Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize PG reservation query for PG >=9.5
What does this optimization do? It handles an issue where two DJ servers "workers" would try to pull the top `delayed_jobs` record at the same time. One would succeed and the second would block. "SKIP LOCKED", introduced in PostgreSQL 9.5, allows the second query to skip records that are already locked by another transaction. This results in significant improvement in performance when there are multiple worker servers all trying to get the next available job row at the same time. What about older PostgreSQL versions? ActiveRecord requires PG>=9.3, so we cannot rely on the built-in checks. But we can use the same mechanisms that AR provides to check the current version and enable an optimization in that case. Meaning newer versions of AR (at least 5.0+) will inspect the current PG version and make the optimization if they can. We're not going to worry about older ARs as everything that old is EOL'd anyhow. And if they're running a Rails that old, the PG is likely older too.
- Loading branch information