Add queue-state count regression benchmark#1211
Draft
bgentry wants to merge 1 commit intobrandur-queue-state-countfrom
Draft
Add queue-state count regression benchmark#1211bgentry wants to merge 1 commit intobrandur-queue-state-countfrom
bgentry wants to merge 1 commit intobrandur-queue-state-countfrom
Conversation
847afa7 to
f1bd30e
Compare
This adds a benchmark on top of #1203 to make the queue-state count query regression easy to reproduce and discuss. It compares the current `JobCountByQueueAndState` implementation against the legacy query shape on the same migrated `river_job` schema. The benchmark stays lightweight by default, but can be scaled locally with `RIVER_BENCH_QUEUE_STATE_COUNT_NUM_JOBS` to reproduce the planner regression with a couple hundred thousand rows and quantify the gap.
f1bd30e to
cda1dbf
Compare
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.
Stacked on #1203.
This adds a small pgx benchmark around
JobCountByQueueAndStateso we have a cheap default signal in normal runs, but can still scale it up locally withRIVER_BENCH_QUEUE_STATE_COUNT_NUM_JOBSwhen we want enough rows to make the planner choice obvious. The benchmark seeds a migratedriver_jobtable in Go using batchedJobInsertFullManycalls, and keeps the states evenly distributed across queues so every queue exercises every state.On my machine (PostgreSQL 16.13, 200k rows, 100 queues, all 8 states distributed across every queue), the current query in #1203 regressed sharply against the previous query shape when I temporarily restored the old implementation locally and reran the same benchmark harness.
EXPLAIN ANALYZE, 2 queuesEXPLAIN ANALYZE, 10 queuesEXPLAIN (ANALYZE, BUFFERS)shows the reason. The new query filters onqueueand groups by(queue, state), so PostgreSQL no longer has a left-edge match on the existing(state, queue, priority, scheduled_at, id)index and falls back to a parallel sequential scan. The old query shape keeps separatestate = 'available'andstate = 'running'branches, so PostgreSQL can still useriver_job_prioritized_fetching_indexvia index-only scans.The committed benchmark only measures the current query. The old-query numbers above came from temporarily restoring the previous implementation locally, collecting the benchmark and plan data, and then restoring the branch state. This PR is only here to make the regression easy to reproduce and discuss before changing the SQL or adding another index.
Full
EXPLAIN (ANALYZE, BUFFERS)output for 2 queuesCurrent query:
Old query:
Full
EXPLAIN (ANALYZE, BUFFERS)output for 10 queuesCurrent query:
Old query: