Hangfire continues to execute SQL queries, even if they are inactive

I am developing an ASP.net MVC 5 website and I use Hangfire to schedule some tasks, in this case once every 3 min. I know that it takes only a few seconds to complete such a task (and the related database query).

The problem I am facing is that it seems like Hangfire has my SQL Server running “something” (I don’t know what) and I see in the SQL Server Activity Monitor that my processor always stays at 20 +%, as well as database I / O operations (average value 1.2 MB / s). I know this is Hangfire because when I do not initialize it, Activity Monitor (and the task manager) does not show unnecessary overhead. I even left to delete all scheduled tasks and everything that Hangfire can run, and still the problem persists.

I can’t go to production like this because I am afraid that it might cause performance problems. Any help would be appreciated, thanks in advance

+6
source share
1 answer

Does the dashboard show nothing? No CRON / Duplicate Jobs? Use control panel authorization? Maybe a request to a registered / registered user? The amount of data seems dubious, but who knows. I use Hangfire myself. Be sure to check tomorrow's traffic!

Edit: Sorry guys there should have been a comment. Ink iPhone .: - /

Added: I researched this a bit on my own server using MVC app + hangfire. In fact, my CPU usage is also 20-25%. So, I searched for a suitable monitor application, installed a great tool called "SQLRanger" and found that the topmost query is:

update top (1) HangFire.JobQueue set FetchedAt = GETUTCDATE() output INSERTED.Id, INSERTED.JobId, INSERTED.Queue where FetchedAt is null and Queue in (@queues1) 

So this is basically a flag check for pending jobs. So far, I have not encountered performance issues or lags.

Addendum: the problem was explicitly caused - and fixed - by adjusting the polling interval, see the corresponding section http://docs.hangfire.io/en/latest/configuration/using-sql-server.html

The default interval is 15 seconds, which provides operational processing of tasks, as well as a constant load on the server. In non-critical applications, a higher interval (1 min, 5 min, etc.) should be in order. Know what you need and react to it: do you need immediate job processing or low server load? If the first, let a short interval and think about the need to increase the number of servers; if the latter increase the interval to the highest acceptable minimum.

I need the first one and will monitor the server whether it can carry the load.

+4
source

Source: https://habr.com/ru/post/987524/


All Articles