Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix performance issues with delayed_jobs by extending index
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.
- Loading branch information