HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.38k stars 1.7k forks source link

Each worker hangs on to a database connection from the pool #395

Open emilevr opened 9 years ago

emilevr commented 9 years ago

Hi.

I've been using Hangfire 1.4.3 (plus Pro 1.3.0). The server is being created via app.UseHangfireServer(options), with a custom queue name.

I can see in TCPView that each worker grabs and holds on to a SQL Database connection, even when there are no jobs queued. This is a big problem when a large number of workers are configured as it is very easy to run out of database connections, especially if there are other connections to the same database.

In fact, configuring 100+ workers will use up all the connections in the pool and even the dashboard will fail with: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

The only way to work around this is to configure a much larger connection pool in the connection string, but that should not be required if the workers can open/close connections only when they need them.

Does the current design require that workers have an open connection? Should workers not only need a connection when they have to write job completion data to the DB? If so, then those connections would not need to be in use for long...

Thanks.

Mohankmr commented 6 years ago

I too have the same issue as mention by Quicksilvr, We have the jobs running in the development environment, Our application consumed almost 90% of the CPU and the application became very slow. How many db connection are used by a hangfire server? Is it possible to limit the connection to the hangfire? It would be better if I get the solution as soon as possible as we are planning to move our application to the UAT environment.

sergey-bulavskiy commented 5 years ago

Any updates regarding this issue ?