Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 697
Natalie Perret Avatar asked May 07 '19 09:05

Natalie Perret


2 Answers

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);
});
like image 56
Christos Avatar answered Oct 20 '22 17:10

Christos


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);
like image 43
Abdus Salam Azad Avatar answered Oct 20 '22 17:10

Abdus Salam Azad