Skip to content

Optimize MongoDB queue counter updates with bulk_write#86

Merged
danielplohmann merged 2 commits into
danielplohmann:mainfrom
r0ny123:optimize-mongo-queue-counters-bulk-write-aggregation-v1.4.6-update-11853461620023532903
May 22, 2026
Merged

Optimize MongoDB queue counter updates with bulk_write#86
danielplohmann merged 2 commits into
danielplohmann:mainfrom
r0ny123:optimize-mongo-queue-counters-bulk-write-aggregation-v1.4.6-update-11853461620023532903

Conversation

@r0ny123
Copy link
Copy Markdown
Contributor

@r0ny123 r0ny123 commented Apr 6, 2026

No description provided.

r0ny123 and others added 2 commits March 2, 2026 18:04
This commit optimizes the queue counter update logic in `MongoQueue` by:
1.  Replacing individual `update_one` calls in `refreshCounters` with a single `bulk_write` operation.
2.  Introducing `updateQueueCounters(self, updates)` to aggregate multiple increments/decrements and apply them in a single `bulk_write` call.
3.  Updating all relevant call sites (`next`, `delete_jobs`, `Job.complete`, `Job.error`, `Job.release`, `Job.terminate`) to use the new batched update method.
4.  Reducing redundant database operations by aggregating increments for the same method/state within a single batch.

These changes significantly reduce the number of operations against MongoDB, improving overall performance and reducing latency during high queue activity.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@danielplohmann danielplohmann merged commit 9f986f0 into danielplohmann:main May 22, 2026
1 check passed
@r0ny123 r0ny123 deleted the optimize-mongo-queue-counters-bulk-write-aggregation-v1.4.6-update-11853461620023532903 branch May 22, 2026 12:54
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.

2 participants