Skip to content
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

Add SKIP LOCKED clause to DJ Pickup Query #1

Merged
merged 1 commit into from
May 3, 2021

Conversation

coreyja
Copy link
Member

@coreyja coreyja commented May 3, 2021

This changes the optimized Postgres strategy to use the SKIP LOCKED
locking clause.

This is 'new' in Postgres 9.5, but thats pretty old for us. What it does
is change the locking behavior in this sub-query to do the pickup.
Before it would wait behind other locks, meaning that the more workers
were competing for jobs, the more locks were occuring.

This way new queries will just skip locked rows, and pick up the 'next'
available job!

Blog Post about SKIP LOCKED in queues: https://vladmihalcea.com/database-job-queue-skip-locked/
PR where QueueClassic adopted this: QueueClassic/queue_classic#303
Postgres Docs: https://www.postgresql.org/docs/12/sql-select.html#SQL-FOR-UPDATE-SHARE

This changes the optimized Postgres strategy to use the `SKIP LOCKED`
locking clause.

This is 'new' in Postgres 9.5, but thats pretty old for us. What it does
is change the locking behavior in this sub-query to do the pickup.
Before it would wait behind other locks, meaning that the more workers
were competing for jobs, the more locks were occuring.

This way new queries will just skip locked rows, and pick up the 'next'
available job!
@coreyja coreyja merged commit 5206912 into master May 3, 2021
@coreyja coreyja deleted the ca/master/skip-locked branch May 3, 2021 21:05
@ukd1
Copy link

ukd1 commented May 14, 2021

🚀

@ukd1
Copy link

ukd1 commented May 14, 2021

Would be interesting to add y'all to https://github.com/bensheldon/queue-shootout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants