Hangfire:打开的连接太多

Eho*_*ret 8 c# postgresql hangfire .net-core

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

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

我想知道是否可以采取任何措施来更改连接数,但是,我在配置中找不到提供此类配置的任何内容。

Chr*_*tos 7

您可以尝试减少工人数量,如下所述

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


Abd*_*zad 5

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);
Run Code Online (Sandbox Code Playgroud)