-
Notifications
You must be signed in to change notification settings - Fork 363
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
Fix performance issues with delayed_jobs by extending index #3324
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FloThinksPi
force-pushed
the
fix-expensive-delayed_jobs-selects
branch
from
June 28, 2023 06:33
e4c29fc
to
840a6e1
Compare
philippthun
approved these changes
Jun 28, 2023
We found out that when having a lot of delayed_jobs rows in the table, postgresql query planner did a sequential scan of the table. This was due to the query of cc_workers to fetch new jobs being: ``` SELECT * FROM "delayed_jobs" WHERE (((("run_at" <= '2023-06-27 07:18:28.061781+0000') AND ("locked_at" IS NULL)) (.....) ORDER BY "priority" ASC, "run_at" ASC LIMIT 1 FOR Update; ``` As an order by is used on `priority` the index over the columns `queue, locked_at, locked_by, failed_at, run_at` is not used. This is more severe as the query above gets more and more expensive by increasing row count and is queried a lot. Every worker every few seconds does this select. This quickly can become a load issue for the database. This change adds the `priority` column to the already existing index `delayed_jobs_reserve`. Improves query times as well as database load significantly in our tests.
FloThinksPi
force-pushed
the
fix-expensive-delayed_jobs-selects
branch
from
June 28, 2023 09:49
840a6e1
to
03dc9de
Compare
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 11, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
5 tasks
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 18, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 18, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 18, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 19, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 20, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 20, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 21, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable.
philippthun
added a commit
that referenced
this pull request
Jul 26, 2023
With PR #3324 [1] the 'delayed_jobs_reserve' index was changed by adding the field 'priority' which is used in the ORDER BY clause. This change re-adds the previous index, that only contains fields used in the WHERE clause of the query. Although PostgreSQL could always use the new index, there seem to be situations where the query planner decides for a sequential table scan (theory: if the number of entries is rather low). [1] #3324 Co-authored-by: Dimitar Velinov <[email protected]>
5 tasks
kathap
added a commit
to sap-contributions/cloud_controller_ng
that referenced
this pull request
Jul 27, 2023
Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng cloudfoundry#3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable. change the start_frequent_jobs method to always use all configured parameters except frequency_in_seconds, change expiration_in_seconds from positional to keyword parameter
johha
pushed a commit
that referenced
this pull request
Jul 27, 2023
With PR #3324 [1] the 'delayed_jobs_reserve' index was changed by adding the field 'priority' which is used in the ORDER BY clause. This change re-adds the previous index, that only contains fields used in the WHERE clause of the query. Although PostgreSQL could always use the new index, there seem to be situations where the query planner decides for a sequential table scan (theory: if the number of entries is rather low). [1] #3324 Co-authored-by: Dimitar Velinov <[email protected]>
johha
pushed a commit
that referenced
this pull request
Jul 31, 2023
* More aggressive cleanup of failed delayed jobs Currently, failed delayed_jobs are deleted after 14d (configurable) to keep some info about failed jobs that helps debugging: https://github.com/cloudfoundry/cloud_controller_ng/blob/main/app/jobs/runtime/failed_jobs_cleanup.rb This can still lead to very large number of delayed_jobs records that slow down DB queries working on delayed_jobs (also addressed by an index, ccng #3324). Idea was to have an additional absolute limit of failed jobs so that they get deleted even before the 14d failed_jobs.cutoff_age_in_days. The limit should be configurable. change the start_frequent_jobs method to always use all configured parameters except frequency_in_seconds, change expiration_in_seconds from positional to keyword parameter * remove optional paramter from configs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We found out that when having a lot of delayed_jobs rows in the table, postgresql query planner did a sequential scan of the table. This was due to the query of cc_workers to fetch new jobs being:
As an order by is used on
priority
the index over the columnsqueue, locked_at, locked_by, failed_at, run_at
is not used.This is more severe as the query above gets more and more expensive by increasing row count and is queried a lot. Every worker every few seconds does this select. This quickly can become a load issue for the database.
This change adds the
priority
column to the already existing indexdelayed_jobs_reserve
. Improves query times as well as database load significantly in our tests.I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
main
branchI have run all the unit tests using
bundle exec rake
I have run CF Acceptance Tests