Repository navigation
fix(monitor-cluster): end-to-end backpressure for staged monitor replay - #399
Merged
fcostaoliveira merged 5 commits intoMay 29, 2026
Merged
Conversation
…eplay In cluster mode, --monitor-input + `--command __monitor_line@__` routes each selected command to the slot-owning shard by pushing it into that shard's staged queue (m_staged_monitor_commands) and waking it via schedule_fill(). Staging never grows the routing connection's own m_pipeline, so fill_pipeline's `m_pipeline->size() < pipeline` gate cannot throttle the producer: the routing side keeps selecting and fanning out commands while each target drains at most ~pipeline-per-RTT. The staged queues grow without bound, so reported latency (measured from selection) climbs monotonically as queue residence dominates the tail (p99 3s -> 6s -> 40s+ over a real network) while p50 stays at true server latency, and throughput overshoots the rate target. Couple production to drain by capping the global end-to-end in-flight count -- staged + sent-awaiting-response == (m_reqs_generated - m_reqs_processed) -- at pipeline * connection_count in cluster_client::hold_pipeline. A connection that still has its own staged or pooled commands to drain is never held, so forward progress is never blocked; only pure producers pause until responses bring the backlog back under budget. Scoped to --monitor-input runs so the SET/GET and arbitrary-command cluster paths are unaffected. Verified against a local 3-node cluster (1 thread, 4 clients, pipeline=1, 4000 reqs/client): p99 dropped from 86.5ms to 0.66ms and average latency from 25.4ms to 0.23ms for an identical workload, with no monotonic climb. Adds tests/test_monitor_cluster_backpressure.py asserting p99 stays bounded when replaying a multi-slot monitor capture against an OSS cluster. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review flagged that with --monitor-input + --retry-on-error a redirected/replayed request can be counted in m_reqs_processed more than once without a matching m_reqs_generated bump, so the unsigned (m_reqs_generated - m_reqs_processed) could underflow to a huge value and wedge the producer permanently. Clamp to 0 when processed >= generated. Defensive: the gate already only pauses pure-producer connections, but this removes any chance of a wrapped in-flight count stalling the run. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
paulorsousa
approved these changes
May 29, 2026
3 tasks
fcostaoliveira
added a commit
that referenced
this pull request
Jun 2, 2026
… sites (#437) PR #399 introduced a >= clamp at hold_pipeline; the three sibling sites (connect_shard_connection, handle_cluster_slots, handle_moved) subtract empty_staged.size() with no such guard. Today the invariant -- entries in empty_staged are pre-decrement -- holds, but a refactor could break it silently. Matching the pattern makes the invariant explicit and future-proofs against subtle underflow to 2^64. Refs: 2.4 review #12 (Review 1 + Review 16). Co-authored-by: Claude Sonnet 4.6 <[email protected]>
This was referenced Oct 24, 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.
Problem
Replaying a MONITOR capture against an OSS cluster (
--monitor-input+--command __monitor_line@__+--cluster-mode) shows latency that grows monotonically over the run — p99 climbs 3s → 6s → 40s+ — while p50 stays at true server latency (~1–2ms) and throughput overshoots the rate target by ~2×. The pathology is identical across RS6/RS7/RS722P, which is the tell that it's client-side, not server.Root cause — no end-to-end backpressure
The design is route-then-stage:
m_staged_monitor_commands[target]and wakes it viaschedule_fill().m_pipeline.push_req()— the only place that growsm_pipeline, bumpsm_pending_resp, and decrements the rate counter — fires only when a command is actually sent (at drain time, on the target). Sofill_pipeline'sm_pipeline->size() < pipelinegate never throttles the producer.pipeline-per-RTT. The staged queues grow without bound (up to the 1M cap).enqueue_time), so reported latency = queue-residence + RTT → the monotonic p99 climb.Fix
Couple production to drain by capping the global end-to-end in-flight count — staged + sent-awaiting-response, which equals
m_reqs_generated - m_reqs_processed— atpipeline * connection_countincluster_client::hold_pipeline. A connection that still has its own staged or pooled commands to drain is never held, so draining (and forward progress) is never blocked; only pure producers pause until responses bring the backlog back under budget. Scoped to--monitor-inputruns, so the SET/GET and arbitrary-command cluster paths are unaffected.Validation
Against a local 3-node OSS cluster (1 thread, 4 clients, pipeline=1, 4000 reqs/client, identical workload):
No monotonic climb with the fix. (Absolute numbers are loopback; over a real network the no-fix tail reaches the tens of seconds described above.)
Test plan
tests/test_monitor_cluster_backpressure.py— replays a multi-slot monitor capture against an OSS cluster and asserts p99 stays bounded (<50ms ceiling, >25× margin) and the run completes with non-zero ops. Runs in the OSS-CLUSTER CI jobs.test_monitor_input.pypasses.🤖 Generated with Claude Code
Note
Medium Risk
Touches cluster pipeline scheduling for monitor-input only, but incorrect backpressure could stall producers or skew throughput/latency under cluster replay.
Overview
Adds end-to-end backpressure for
--monitor-inputcluster replay when commands are route-then-staged across shards. Incluster_client::hold_pipeline, pure producer connections (no local staged or pooled work) pause when global in-flight work—m_reqs_generated - m_reqs_processed—reachespipeline × connection_count, so staging cannot outrun drain and p99 latency is not dominated by queue residence. The check is scoped to monitor-input runs; connections still draining their own queues are never held. Unsigned underflow on the in-flight subtraction is clamped when--retry-on-errorcan process without a matching generate bump.Adds
tests/test_monitor_cluster_backpressure.py: OSS cluster replay with cross-shard keys asserts p99 < 50ms and a smaller sanity run completes with non-zero ops.Reviewed by Cursor Bugbot for commit 26c3b21. Bugbot is set up for automated code reviews on this repo. Configure here.