Repository navigation
Scheduler: dequeue same-priority queries in arrival order - #7958
Open
mayank-gupta16 wants to merge 1 commit into
Open
mayank-gupta16 wants to merge 1 commit into
mayank-gupta16 wants to merge 1 commit into
Conversation
util.PriorityQueue was a plain container/heap ordered only by priority, with no tie-breaker. Queries sharing a priority came out in roughly reverse arrival order, so with query priority enabled (and with the query-scheduler, which queues everything at the same priority) older queries could starve under steady load. Record an enqueue sequence number with each op and use it to break ties, so ops with equal priority are dequeued FIFO. Fixes cortexproject#7950 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mayank Gupta <mayankg1609@gmail.com>
mayank-gupta16
force-pushed
the
fix/7950-priority-queue-fifo
branch
from
November 27, 2026 10:26
ac169ec to
b0ce0e4
Compare
This branch has not been deployed
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.
What this PR does:
util.PriorityQueueorders its heap only byPriority(), with no tie-breaker, so queries that share a priority level are dequeued in roughly reverse arrival order. With query priority enabled (and with the query-scheduler, which enqueues everything at the same priority, see #7949) older queries can starve under steady load, as described in #7950.This records an enqueue sequence number with each op and uses it to break ties in
Less, so ops with equal priority are dequeued FIFO. Ordering between different priorities is unchanged, and the public API ofPriorityQueueis unchanged.Tests: added three cases to
pkg/util/priority_queue_test.go: six same-priority items come out in arrival order, mixed priorities keep FIFO within each level, and the "serve one, receive one" starvation scenario from the issue. Two of them fail on master (1 6 5 4 3 2ordering) and all pass with the fix.go test ./pkg/util/... ./pkg/scheduler/... ./pkg/frontend/...passes exceptpkg/util/validation(TestValidateNativeHistogrampanics), which fails the same way on master.This change was prepared with AI assistance (Claude Code); I reviewed and tested it before submitting.
Which issue(s) this PR fixes:
Fixes #7950
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flags🤖 Generated with Claude Code