bench: xmin-horizon torture test for PG-backed queues#80
Merged
Conversation
Reproducible benchmark contrasting a generic SKIP LOCKED queue and pgque under a held xmin horizon — the most common operational failure mode of SKIP LOCKED queues in production (long RR transactions, pg_dump, idle logical replication slots, hot_standby_feedback=on with a slow replica). Single-laptop reproducer in bench/xmin-horizon/. PG17, Docker Compose, aggressive autovacuum baked in. 4 cells run today (S1+S2 x skiplocked+pgque), 3 minutes each, 800 enqueues/s. Headline (from results/results.md): | Scenario | Workload | Dequeue/s | n_dead_tup | Bystander lat | |---------------|-------------|-----------|------------|---------------| | baseline | SKIP LOCKED | 797 | 6,397 | 1.35 ms | | baseline | pgque | 792 | 0 | 1.50 ms | | RR holds xmin | SKIP LOCKED | 517 | 91,593 | 2.05 ms | | RR holds xmin | pgque | 804 | 0 | 1.45 ms | When xmin is blocked: SKIP LOCKED dead tuples 14x, table size 15x, dequeue throughput drops ~35%, bystander query latency on an unrelated table sharing buffer cache rises ~50%. pgque is unaffected. Spec: blueprints/BENCH_XMIN_HORIZON.md Docs: docs/benchmarks.md updated with summary section + link. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
REV ReviewCI: ✅ all 8 checks green (test 14/15/16/17/18, verify, client-smoke, claude-review) Blockingnone Non-blocking
Potential
REV-style review (security, bugs, tests, guidelines, docs). SOC2 items skipped per project policy. Anti-leak scan clean. |
This was referenced Apr 30, 2026
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
Reproducible benchmark in
bench/xmin-horizon/contrasting a generic SKIP LOCKED queue and pgque under a held xmin horizon — the most common operational failure mode of SKIP LOCKED queues in production. Causes are routine: long REPEATABLE READ transactions,pg_dump, idle logical replication slots,hot_standby_feedback=onwith a slow replica. While xmin is held, VACUUM cannot reclaim dead tuples generated by the queue'sINSERT → UPDATE → DELETElifecycle, the queue table bloats, and read latency climbs.Single-laptop reproducer. PG17 in Docker Compose, aggressive autovacuum baked in (
autovacuum_vacuum_scale_factor = 0.005,autovacuum_naptime = 10s,autovacuum_vacuum_cost_limit = 10000) so the result cannot be dismissed as "you didn't tune."Headline
3-minute cells, 4 producers + 4 consumers + 2 bystander clients on an unrelated 1M-row table, 800 enqueues/s.
When xmin is blocked, the SKIP LOCKED queue's dead tuple count grows by 14×, table size by 15×, dequeue throughput drops by ~35%, and bystander query latency on an unrelated table sharing buffer cache rises by ~50%. pgque is unaffected —
n_dead_tup = 0across allpgque.event_*tables in every cell, throughput and bystander latency unchanged from baseline.What's in
blueprints/BENCH_XMIN_HORIZON.md— benchmark specbench/xmin-horizon/— reproducer (Docker Compose, pgbench scripts, orchestration)bench/xmin-horizon/results/— raw 5s metrics + final-bloat snapshots from today's runbench/xmin-horizon/results/results.md— generated summarydocs/benchmarks.md— top section added with summary table + link to reproducerHow to reproduce
Override
DURATION,PRODUCERS,CONSUMERS,ENQUEUE_RATEto taste.Framing
Comparison is of queue implementations under realistic operational conditions, not a takedown of any specific library.
SKIP LOCKEDis a sound primitive; the failure mode is structural to itsINSERT/UPDATE/DELETElifecycle, not specific to any one implementation.Test plan
docker compose up -dmake run-s1 run-s2results.mdmatches headline abovedocs/benchmarks.mdrenders with new section at the topNotes
n_live_tupis large in S2 (~287K) because rotation can't truncate while xmin is held — this is deferred reclamation, not bloat.n_dead_tupis what VACUUM needs to chase, and it stays at 0.🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com