I am building a web application and I want to use Hangfire to process long running calculations outside of the request context.
So, the basic scenario is this:
- user enters input;
- input is stored in a DB, under an id;
- job is enqueued with parameter this id;
- when the job is started, it will:
** retrieve input;
** start calculations;
** store results in DB;
** mark done;
- meanwhile, the UI polls for results;
** when done, show results.
Since there are few concurrent users expected, we do not want to invest in running separate servers with a worker services. So, Hangfire is running in process with the web server. It is OK if users need to wait longer, whenever the queue is full.
The calculations are CPU bound. To avoid the web server to become unresponsive, I could limit the number of background worker to below the number of cores in the server. Would that work?
However, it may be more appropriate to use: Thread.Priority Property, to lower the priority:
System.Threading.Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
- Are any issues to be expected?
- Does Hangfire have any mechanism to specify the
ThreadPriorityof the jobs it starts?