-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Enqueued Job Trigger for Multiple Queues #320
Fixing Enqueued Job Trigger for Multiple Queues #320
Conversation
Ideally, this could use postgres notifications channel. https://www.postgresql.org/docs/current/sql-notify.html I think there were usages of such approach already in the code. |
@dmitry-vychikov , Postgres LISTEN/NOTIFY function requires a long-living session/connection which comes at a cost. Hangfire.Postgres provides an option for using it, but I prefer not to enable it. I believe there are two quite different use cases:
This PR is improving single-process scenario. |
Do you have any benchmarks or experience to share? How high is that performance cost? Just interested. I'm not totally against this improvement. But to me using postgres channels looks simpler because it can cover both cases. It will be less code in total to maintain which is a good thing in general. Now it is a bit messy because of combination of multiple approaches in different places. |
I can't even turn In terms of performance and costs, I can agree that one long polling connection would be ok. However, according the current code there are one connection per worker. It can be improved also, but as I mentioned above, long-living connections don't fit everyone. BTW, I agree that current code quite branching. I tried not to make it more complicated. |
Co-authored-by: Dmitry Vychikov <31896999+dmitry-vychikov@users.noreply.github.com>
…ng_signals_refact
…fact' into feature/jobs_fetching_signals_refact
Hi @azygis ! Have you had a chance to look at this PR? I noticed that you fixed the test pipeline. What do you think about? Should I invite someone else? |
I did leave a few remarks which don't seem to have been addressed yet. |
@azygis , sorry, I can't find your remarks. All conversations are resolved now. |
Sorry, it was a click by mistake. |
Shoot, sorry, I always forget that GitHub requires submitting the review as opposed to Azure DevOps where comments are just appearing automatically. Published it now. |
The package has been published. |
There was a significant issue with the new enqueued job trigger that should release waiting in jobs fetching loops. It used only one static
AutoResetEvent
instance for all workers and queues. When thisAutoResetEvent
is released, it only releases one random waiting thread. If it was a thread of a worker with a different queue, the job gets stuck until a new event or theQueuePollInterval
passes. This situation frequently occurred in my environment.AutoResetEventRegistry
in place of oneAutoResetEvent
. It internally holds severalAutoResetEvent
instances, one for each queue.PostgreSqlStorage
toPostgreSqlWriteOnlyTransaction
, where new jobs are added and committed. The list_queuesWithAddedJobs
accumulates all queues with added jobs in the transaction, and only those queues fire events after commit. This approach also reduces false positive triggers, as not every transaction contains new jobs.cancellationToken.ThrowIfCancellationRequested()
after waiting in the fetch loop since it is already executed at the beginning of each iteration.Concerns:
Dequeue_UpdateCount
method, which is used in case ofUseNativeDatabaseTransactions = false
, because there was originally no signal waiting. I'm not sure if it should be modified.