HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.34k stars 1.69k forks source link

Increase the recurring job polling interval for hangfire and enabling/disabling the recurring job process #775

Open pratikpushpendra opened 7 years ago

pratikpushpendra commented 7 years ago

I am trying to create a background processor windows service using hangfire. I would like to increase the recurring job polling interval to more than 1 minute(hard-coded by default). The reason for doing the same is that recurring polling can affect the performance of the database.
Is there a possibility to enable/disable the hangfire recurring Job feature. This is required in case there are multiple instances of the service installed. The multiple instances of the service polling the database is also a performance issue

I had tried making changes to the Hangfire.Core to make the polling interval configurable. i have attached the code snips with the issue

background job server options background job server new throttler background job server option based throttler recurring job scheduler

pratikpushpendra commented 7 years ago

@odinserj - Any resolution is highly appreciated. We are facing some critical issues with the service deployment. Thanks in advance.

odinserj commented 7 years ago

How many Hangfire Server instances do you have in total?

pratikpushpendra commented 7 years ago

@odinserj : It will depend on the deployment scenario. A large deployment could mean atleast 4 servers(i.e 4 instances of the Windows Service running the hangfire server)

For Eg. Consider a scenario where i have 4 instances of windows service running hangfire server. Under the current circumstances, all 4 will be polling the database to fetch the recurring jobs. In my case, the database is a highly transactional one. Thus, the perfomance parameters for the database taking a hit due to 4 extra requests every minute. I would prefer to disable the recurring job polling feature for selected instances or atleast increase the polling interval.

I have asked the same on stack overflow - http://stackoverflow.com/questions/41341313/increase-the-recurring-job-polling-interval-for-hangfire-and-enabling-disabling

Adding to the above details- In my case recurring jobs(schedules) is not time critical and less in number as compared to the background jobs(on demand). Thus what we need to selectively stop polling on some instances or alternatively increase the polling interval for all service instance. In our case based on the performance parameters, we would want to set it to an interval of 5 minutes.

Hope this further explains the situation.

odinserj commented 7 years ago

You can use the BackgroundProcessingServer class instead of the BackgroundJobServer (the latter is a facade for the former), and exclude both DelayedJobScheduler and RecurringJobScheduler processes from your application instances. Will it be enough for your case?

var processes = new List<IBackgroundProcess>();

for (var i = 0; i < Environment.ProcessorCount * 5; i++)
{
    processes.Add(new Worker("default"));
};

// processes.Add(new DelayedJobScheduler());
// processes.Add(new RecurringJobScheduler());

using (var server = new BackgroundProcessingServer(processes))
{
    Console.WriteLine("Custom BackgroundServer started. Press ENTER to exit...");
    Console.ReadLine();
}