HangfireIO / HangfireIO/Hangfire
Support for `async` background job methods
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
Heavy I/O bound background jobs consume worker thread inefficiently – instead of doing the real work they wait for the completion of I/O operation(s). Currently if an application has a lot of such background jobs, it is better to increase the worker pool size to process jobs more efficiently. However increased worker pool causes performance problems for CPU-bound jobs.
Instead of waiting for the I/O completion, it would be useful to yield the worker thread to process another background job instead, for example, using the default mechanism with `async` and `await` keywords:
``` csharp
public async Task IOBoundMethod()
{
var documents = await _documentsService.FetchAll();
documents.Process();
}
```
But we should ensure that the completion is being called inside the _Hangfire's worker thread_, and not in _CLR's thread pool thread_ (to not to compete with request processing pipeline, use additional storage connections and so on). Another consideration should be dedicated to job filters – `CaptureCultureAttribute` changes the thread context, and it should be changed again on each continuation. There are also problems with reliability (outstanding jobs should be requeued), shutdown events (outstanding operations should be canceled), and perhaps with something else.
Contributor guide
Assessment
This issue has not been assessed yet.