.Net Core Hangfire - 增加工人数量

Nit*_*tin 3 parallel-processing worker hangfire .net-core

我有一个带有 Hangfire 实现的 .Net Core 应用程序。

每分钟有一个重复的工作如下:-

RecurringJob.AddOrUpdate<IS2SScheduledJobs>(x => x.ProcessInput(), Cron.MinuteInterval(1));

var hangfireOptions = new BackgroundJobServerOptions
            {
                WorkerCount = 20,
            };
            _server = new BackgroundJobServer(hangfireOptions);
Run Code Online (Sandbox Code Playgroud)

ProcessInput()内部检查一些Id的BlockingCollection()来处理,它不断地处理。

有时,前 10 个 ProcessInput() 作业会继续由 10 个工作人员处理,而其他新的 ProcessInput() 作业则会排队。

为此,我想增加工作线程数量,比如 50 个左右,这样就会有 50 个 ProcessInput() 作业被并行处理。

请建议。谢谢。

小智 13

在.NET Core版本中,您可以在添加Hangfire Server时设置worker计数:

services.AddHangfireServer(options => options.WorkerCount = 50);
Run Code Online (Sandbox Code Playgroud)