Hangfire:连接过多

时间:2019-05-07 09:23:36

标签: c# postgresql .net-core hangfire

我们在生产中使用了Hangfire,结果证明我们确实达到了数据库连接的最大限制。

我们只有大约45个连接用于hangfire,对于仅维护一些长时间运行的任务来说似乎有点过多。

我想知道是否可以做些什么来改变连接数,但是,在提供这种配置的配置中我找不到任何东西。

2 个答案:

答案 0 :(得分:2)

here所述,您可以尝试减少工人数量:

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

答案 1 :(得分:2)

Hangfire默认需要20名工人。您可以在启动时覆盖它。我使用如下:

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);