Closed maennchen closed 3 months ago
We're ahead of you on this one 🙂
Pro v1.5 adds a custom check_available/1
implementation that is vastly faster (< 8ms for 9.6 million jobs). There's a description of the change and a performance comparison table in the CHANGELOG: https://getoban.pro/docs/pro/1.5.0-rc.0/changelog.html#enhancements
queue can never be nil since the column is required
The use of is not null
was to force index usage in older versions of Oban where the compound index had queue
before state
. It's not necessary now, but there are Oban installations out there that still use the old index because it was an optional migration.
@sorentwo Amazing, will update to the RC immediately then :)
@sorentwo Works perfectly.
Before fix applied:
After fix applied:
Environment
2.18.0
15.1-1.pgdg20.04+1
elixir --version
):1.17.2
on OTP27.0.1
Current Behavior
After creating a very large number of jobs (10M+), I noticed a very noticeable slow down of the system. I found the following query in the slow query logs:
Expected Behavior
The query should not block for a long time when there's lots of jobs.
Exploration
This query is executed by
Oban.Engines.Basic.check_available/1
.The query has multiple issues:
queue
can never benil
since the column is requiredDISTINCT
queries can't be indexed properly in postgresQuery Explain: https://explain.dalibo.com/plan/5ea6gaed026672ed
By checking the existence of the queues present in the
oban_producers
table or just specifying the queues to check if they are available, reduces this down to < 100ms even with millions of jobs.https://explain.dalibo.com/plan/da8e8a68g3gad869
The query is still far from optimal, the index scan on the jobs table is massively over estimating the amount of rows and could still be improved considerable, but is 2 orders of magnitude quicker.