I have few thousand recurring jobs that run around midnight every day but when running a recurring job sometimes it starts hundreds of new threads even though I have set to Worker Count 10. Has anyone encountered this issue before?
Here is my hangfire configuration (in aspnet core app):
In Service Configuration:
services.AddHangfire(c => c
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSerializerSettings(new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })
.UseSqlServerStorage(configuration.GetConnectionString("HangfireDbConnection"), new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
UsePageLocksOnDequeue = true,
DisableGlobalLocks = true
}));
In App Configure:
var backgroundJobOptions = new BackgroundJobServerOptions
{
Queues = new[] { "admin" },
WorkerCount = 10,
ServerName = "cloud"
};
app.UseHangfireServer(backgroundJobOptions);