c# - hangfire 配置中的 SchedulePollingInterval、HeartbeatInterval 和 ServerCheckInterval 有什么区别?

标签 c# hangfire

在 Azure Application Insight > 应用程序 map > 调查性能中,我不确定为什么每隔 5 分钟,我的服务就会有一个或多个来自hangfire 的数据库调用。也不确定为什么有时每 5 分钟只有 1 个 db 调用,但其他时候却有 9 个 db 调用。

这些是日志数据中的一些时间戳。

10/25/2022, 10:57:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:52:10 PM

10/25/2022, 10:47:10 PM

我知道它来自hangfire,因为当我注释掉hangfire代码时,我没有看到我的服务调用数据库。我不确定 SchedulePollingIntervalHeartbeatIntervalServerCheckInterval 之间有什么区别。但我已将它们全部设置为 TimeSpan.FromHours(1)。我需要的是每小时检查队列中是否有任何作业。我无法从hangfire 文档中找到太多信息。 https://api.hangfire.io/html/P_Hangfire_BackgroundJobServerOptions_HeartbeatInterval.htm

这是我在program.cs中的设置。我正在使用 .NET 6

builder.Services.AddHangfireServer(
    options => {
        options.WorkerCount = 1;
        options.SchedulePollingInterval = TimeSpan.FromMinutes(10);
        options.HeartbeatInterval = TimeSpan.FromMinutes(10);
        options.ServerCheckInterval = TimeSpan.FromMinutes(10);
    }
);

app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    StatsPollingInterval = 600000   
});

为了简洁起见,删除了一些代码。

最佳答案

I am not sure what is the difference between SchedulePollingInterval, HeartbeatInterval, and ServerCheckInterval.

  • SchedulePollingInterval:hangfire 用于检查是否有一些计划作业要执行的时间间隔(似乎与您的情况无关)
  • HeartbeatInterval:每个后台作业服务器向hangfire系统发出信号的时间间隔
  • ServerCheckInterval:我不确定。我猜它是用来删除旧的(超时)服务器实例

如果您使用 Sql Server 作为存储,我认为您最感兴趣的设置是 SqlServerStorageOptions.QueuePollInterval。将其设置为一小时应该可以解决您的问题。

关于c# - hangfire 配置中的 SchedulePollingInterval、HeartbeatInterval 和 ServerCheckInterval 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74194545/

相关文章:

c# - 升级到 netcoreapp2.1 后发布到 Azure 时出错

c# - Hangfire:从关键部分内排队后台作业

servicestack - 将 Hangfire 与 ServiceStack 结合使用

asp.net - 无法将 Hangfire 与 ASP.NET Webforms 网站一起使用

asp.net-web-api2 - Autofac 作业激活器与 Hangfire 抛出异常 DependencyResolutionException

visual-studio - 如何在发布期间从预编译中排除 cshtml

c# - 缺少 AxHost.GetPictureFromIPicture() 方法,正在从 MS Access 数据库中检索图片(附件)

c# - 使用语句和关闭方法

c# - 使用 WEB API HttpClient 使用外部 API 然后以 Angular 显示反序列化结果是否可以接受?

c# - 使用 Reflection.Emit 动态创建一个类。我被困