Skip to content

Spread database queue workers across candidate jobs - #398

Open
EfeDurmaz16 wants to merge 1 commit into
laravel:0.xfrom
EfeDurmaz16:spread-queue-claims
Open

EfeDurmaz16 wants to merge 1 commit into
laravel:0.xfrom
EfeDurmaz16:spread-queue-claims

Conversation

@EfeDurmaz16

Copy link
Copy Markdown

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:work processes over three interleaved runs:

Workers Jobs/s (before → after) Lost claims (before → after)
1 390 → 395 0 → 0
4 416 → 806 8,455 → 4,207
8 490 → 686 21,667 → 14,319
16 388 → 582 46,124 → 34,676

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 LOCKED on PostgreSQL and saw 3.1x throughput at 8 workers and 6.1x at 16. I ran into database is locked errors with 16 SQLite workers on the existing code as well. Happy to send separate PRs for SKIP LOCKED and a configurable WAL mode.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T22:01:09.357583Z 58769d2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant