-
Notifications
You must be signed in to change notification settings - Fork 55
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
Repair may stuck when many failed jobs #122
Comments
Interesting. I'll have to double check, but it looks like a good optimization. |
Full
And for completeness, this is what the table looks like currently:
|
Visualisations for the original plan and the updated one. |
It would be interesting to see what the result is of using SELECT j.id
FROM minion_jobs AS j
LEFT JOIN minion_jobs children
ON children.state != 'finished' AND array_length(children.parents,1)>0 AND j.id = ANY(children.parents)
WHERE j.state = 'finished' AND j.finished <= NOW() - INTERVAL '2 day' AND children.id IS NULL
UNION ALL
SELECT j.id FROM minion_jobs AS j
WHERE j.state = 'inactive' AND j.expires <= NOW(); This might also benefit from indexes on |
Results for the
|
It didn't do significant difference in my case, but I am glad that you are looking at it as well. |
Steps to reproduce the behavior
Minion::Backend::Pg::repair doesn't scale well
Expected behavior
Should scale well with number of rows to delete and number of inactive / failed tasks
Actual behavior
Performance decreases exponentially - Backend must do X times array lookups over Y rows, where
X - number of finished jobs to be deleted
Y - number of inactive / failed jobs
Analysis:
The query used for removing old jobs is similar to
Explain analyze in live environment shows
but the cost grows further with number of rows to remove and rows in failed + inactive jobs. It may stuck for hours with large enough number of old and failed jobs.
Proposed solution:
Rewrite query to use left join, so it should scale well with increased number of rows to process
Explain analyze in live environment shows:
The text was updated successfully, but these errors were encountered: