Repository navigation
Spread database queue workers across candidate jobs - #398
Open
EfeDurmaz16 wants to merge 1 commit into
Open
EfeDurmaz16 wants to merge 1 commit into
EfeDurmaz16 wants to merge 1 commit into
Conversation
Workers racing for a database queue all read the same five oldest jobs and tried them in the same order, so most claims lost to another worker. A worker still tries the oldest job first, which keeps a lone worker in dispatch order, and then starts at a random one of the others. The claim itself is unchanged.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or 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
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.
Database queue workers currently fetch the same five candidates and try to claim them in the same order. On PostgreSQL, workers end up waiting on the same row locks just to lose the claim.
This keeps the oldest candidate first but rotates the remaining candidates by a random offset. A single worker still processes jobs in dispatch order, and no database specific SQL is needed.
Measured with 5,000 no-op jobs on PostgreSQL 18, using separate
queue:workprocesses over three interleaved runs:No measurable difference on SQLite. MySQL wasn't benchmarked.
Added a test with three competing workers to verify that each job runs exactly once and the queue ends up empty. All 343 locally run queue integration tests passed.
I also tested
SKIP LOCKEDon PostgreSQL and saw 3.1x throughput at 8 workers and 6.1x at 16. I ran intodatabase is lockederrors with 16 SQLite workers on the existing code as well. Happy to send separate PRs forSKIP LOCKEDand a configurable WAL mode.