Bound workflow claims within a dequeue transaction#1300
Open
jlalmes wants to merge 2 commits into
Open
Conversation
Contributor
|
Thanks @jlalmes , we'll be looking into this. I think the batch makes sense. I'd be worried about moving to bounded dequeue + batch budget. It'd probably require a new, carefully tuned index on |
Contributor
Author
|
Thanks @maxdml, is there a similar implementation in the Python library already? |
Contributor
|
No, we also dequeue each workflow sequentially in the other languages. |
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.
Summary
maxDequeuesPerPolloption and DB-backed getter/setter.SELECT ... FOR UPDATEplus per-row updates with a bounded atomic claim query using a locked candidate CTE andUPDATE ... RETURNING.Problem
A queue dequeue transaction can currently select every eligible workflow when no effective concurrency bound is present. With a large backlog, that transaction can lock and update a very large candidate set before it commits. If it remains open, it holds row locks in
workflow_statusand blocks other DBOS state changes that need to update those workflows, such as cancellation or completion.Solution
Each
findAndMarkStartableWorkflowscall now claims at most 100 workflows by default, or the queue-specificmaxDequeuesPerPollvalue. The cap is applied after available concurrency and remaining rate-limit capacity are calculated, so rate-limited queues do not lock more rows than they are allowed to start.The claim is a single bounded SQL statement: select locked candidates with
LIMIT, then update and return the claimed workflow IDs atomically. Existing partition polling and scheduler behavior are unchanged; each existing partition dequeue transaction is independently bounded.This is not a concurrency limit. It limits the number of workflows claimed in one dequeue transaction, keeping transactions short while preserving existing queue concurrency semantics.
Tests
npm run buildnpx jest ./tests/wfqueue.test.ts --runInBand --testNamePattern="bounded-queue-dequeue-claims" --silentnpx jest ./tests/adminserver.test.ts ./tests/client.test.ts --runInBand --silent