简体   繁体   中英

Hangfire: too many connections opened

We are using Hangfire in production and turns out that we literally reach the database connections max limitation.

We have about 45 connections for just hangfire which seems a bit too much for just maintaining some long task running jobs.

I am wondering whether there is anything that can be done to change the number of connections, however, I can't find anything in the configuration providing such configuration.

You could try to reduce the number of workers as it is described here :

app.UseHangfire(config =>
{
    //tell hangfire to only use 2 workers
    config.UseServer(2);
});

Hangfire default takes 20 workers. You can override it on your startup. I used like below:

var options = new BackgroundJobServerOptions
            {
               WorkerCount=1    //Hangfire's default worker count is 20, which opens 20 connections simultaneously.
                                // For this we are overriding the default value.
            };

            app.UseHangfireServer(options);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM