-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Slow queries with many finished entries and concurrency control #514
Comments
til
added a commit
to til/good_job
that referenced
this issue
Feb 7, 2022
This allows it to make use of the index index_good_jobs_on_concurrency_key_when_unfinished. Refs bensheldon#514
@til thank you! Thank looks like the correct analysis to me. I think the reason why I initially didn't use unfinished is that there is not an atomic operation of "mark-as-finished and unlock". But thinking about it now, I think it likely does not matter...and the performance benefit you've highlighted is significant. |
bensheldon
pushed a commit
that referenced
this issue
Feb 7, 2022
This allows it to make use of the index index_good_jobs_on_concurrency_key_when_unfinished. Refs #514
Works well now, thanks for the quick release! |
connorchris831
pushed a commit
to connorchris831/good_job
that referenced
this issue
Dec 19, 2022
This allows it to make use of the index index_good_jobs_on_concurrency_key_when_unfinished. Refs bensheldon/good_job#514
OneDev0411
added a commit
to OneDev0411/ruby-good-job
that referenced
this issue
Mar 17, 2023
This allows it to make use of the index index_good_jobs_on_concurrency_key_when_unfinished. Refs bensheldon/good_job#514
legendarydeveloper919
added a commit
to legendarydeveloper919/good_job
that referenced
this issue
Mar 15, 2024
This allows it to make use of the index index_good_jobs_on_concurrency_key_when_unfinished. Refs bensheldon/good_job#514
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On a system with a lot of entries in the
good_jobs
table for finished jobs (around 700k) and only a few thousand of them being unfinished, I'm seeing that a specific query is being executed many times and takes many seconds to finish.Below is the plan of that query, reproduced with dummy values for its bind variables. It took around 14s:
The table has an index on the
concurrency_key
but limited to the conditionWHERE finished_at IS NULL
. Is this the code that triggers this query: https://github.com/bensheldon/good_job/blob/main/lib/good_job/active_job_extensions/concurrency.rb#L64-L68? If yes, is there a reason why this query is not limited to theunfinished
scope? Modified to includefinished_at IS NULL
, it would use the index and run a lot faster:The text was updated successfully, but these errors were encountered: