Repository navigation
Add client staircase ramp-up for incremental connection growth - #350
Conversation
Adds --clients-start, --clients-step, and --step-duration CLI options to gradually increase client connections during a benchmark run while keeping thread count fixed. This enables observing server behavior under increasing load with a staircase pattern. Key changes: - New CLI options with validation (requires --test-time, all three must be specified together, clients_start < clients) - Visual staircase pattern printed to stderr at startup - Timer-based client creation within each thread's libevent loop (thread-safe, same pattern as rate-limiting timers) - Global deadline in finished() for staircase mode so all clients stop at test_time regardless of when they were created - JSON output includes staircase config fields and per-second "Active Clients" section with clients-per-thread and total counts - Progress display shows current client count instead of max - Made next_client_idx atomic for thread-safe concurrent client creation Co-Authored-By: Claude Opus 4.6 <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
std::atomic<int> has a deleted copy constructor which breaks benchmark_config copy semantics on debian:bullseye and macOS. Revert next_client_idx back to plain int. Also apply clang-format to satisfy the C++ Format Check. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1. In handle_staircase_step(), move push_back after prepare() so that a failed prepare() doesn't leave a broken client in the vector. Delete the client on failure to prevent leaks. 2. Use gettimeofday wall-clock time (from benchmark_start_time) for the progress display client count and progress percentage instead of averaged per-client duration, which underestimates elapsed time when late-joining clients pull the average down. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Two data races existed in staircase mode: 1. next_client_idx race: Multiple event loop threads creating clients concurrently via handle_staircase_step() would race on config->next_client_idx++ in setup_client(). 2. m_clients vector race: The main thread iterates m_clients (via get_total_ops() for progress display) while event loop threads do push_back() in handle_staircase_step(), causing use-after-free when the vector reallocates. Fix: Create ALL clients upfront in cg_thread::prepare() (which runs sequentially in the main thread), and have the staircase timer only prepare() (connect) pre-existing clients. Use std::atomic<unsigned int> m_staircase_active_clients to track how many clients are connected. All getter functions only iterate active clients. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1. Per-second stats misalignment: In staircase mode, clients added at later steps had their own m_start_time set to when they first sent a request. Their per-second bucket m_second=0 mapped to a different absolute time than the initial clients' m_second=0, causing data from different time periods to be merged together. Fix: all clients in staircase mode use benchmark_start_time as their start time, ensuring per-second entries are aligned to the same time origin. 2. Active count overcounting: handle_staircase_step() unconditionally stored 'target' into m_staircase_active_clients even when prepare() failed mid-loop. This caused getter functions to iterate over never-connected clients. Fix: track actual connected count and only store that. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ection verification tests Fix handle_staircase_step() to check connected >= max instead of target >= max for timer removal. This ensures the timer keeps firing if prepare() fails on the last step, allowing retries. Add three new tests: - test_staircase_actual_connections_via_client_list: polls CLIENT LIST during live benchmark to verify actual connection count matches expected - test_staircase_timeserie_aligned_with_active_clients: verifies Time-Serie and Active Clients JSON sections cover the same seconds - test_staircase_per_step_ops_consistency: verifies ops are consistent within each step (not mixing data from different time periods) Co-Authored-By: Claude Opus 4.6 <[email protected]>
The last second of a test run may have partial data because the benchmark finishes mid-second. Exclude it from the consistency check to avoid false failures on CI. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1. finalize_all_clients() and set_all_clients_interrupted() now iterate ALL clients (m_clients.size()) instead of only active ones. During handle_staircase_step(), a client may be prepare()-d but not yet counted in the atomic — the interrupt from the monitoring thread could miss it. Iterating all clients is safe: set_end_time() is a no-op via m_end_set guard, and non-active clients are excluded from merge/getter functions which still use active_client_count(). 2. Fix test_staircase_actual_connections_via_client_list sleep timing: sleep(check_time - 2) always subtracted the initial 2s offset instead of the previous check time, causing the third check to arrive at ~14s instead of ~10s. Track last_check_time and sleep the delta. Co-Authored-By: Claude Opus 4.6 <[email protected]>
When test_time is shorter than the time to reach max clients, the EV_PERSIST staircase timer never gets removed (only removed when connected >= max). After test_time, all clients' finished() returns true but the persistent timer keeps event_base_dispatch alive, firing every step_duration and preparing clients that immediately finish — extending the run far beyond test_time. Fix: check elapsed time against test_time at the start of handle_staircase_step() and remove the timer if the deadline has passed. Co-Authored-By: Claude Opus 4.6 <[email protected]>
merge_run_stats, aggregate_inst_histogram, write_client_stats, and get_duration_usec now iterate ALL clients instead of only active_client_count(). This prevents silently dropping stats from a client that was prepare()-d in handle_staircase_step() but not yet counted in the atomic when the benchmark ended. Each function skips clients where has_started() is false (i.e., set_start_time was never called). This avoids corrupting the factorial-averaged timestamps by merging a client with zeroed m_start_time. Clients that never started have no ops, no per-second data, and no histograms, so skipping them is always correct. Progress display functions (get_total_bytes/ops/latency) continue using active_client_count() since they run concurrently with the event loop thread and cannot safely access clients beyond the atomic count. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add documentation for 12 flags missing from memtier_benchmark.1: - Staircase ramp-up: --clients-start, --clients-step, --step-duration - StatsD metrics: --statsd-host, --statsd-port, --statsd-prefix, --statsd-run-label, --graphite-port - Monitor replay: --monitor-input, --monitor-pattern - Output control: --command-stats-breakdown, --print-all-runs Also update bash-completion with all missing flags including TLS, reconnection, jitter, and URI options. Update AGENTS.md to note that new CLI flags must be verified in both --help output and memtier_benchmark.1 after adding. Co-Authored-By: Claude Opus 4.6 <[email protected]>
These flags are being added in a separate PR (fix/missing-manpage-flags). Keep only --clients-start, --clients-step, --step-duration additions that belong to the staircase ramp-up feature. Co-Authored-By: Claude Opus 4.6 <[email protected]>
# Conflicts: # bash-completion/memtier_benchmark
The main thread's progress display calls has_started() and get_duration_usec() which read m_start_time, while worker threads concurrently write it via set_start_time(). This unsynchronized access triggers TSAN errors (exit code 66) that cause test_default_set_get_rate_limited and test_rate_limited_completion_no_hang to fail. Fix by adding a copyable_atomic_bool m_started flag with acquire/release semantics: - set_start_time() writes m_start_time then does a release store - has_started() does an acquire load of the flag (no timeval read) - get_duration_usec() checks the atomic before reading m_start_time The acquire/release pair establishes happens-before, ensuring m_start_time is fully visible when the flag reads true. The wrapper struct allows run_stats to remain copyable (needed for std::vector storage), with copies using relaxed ordering since they only occur after thread join. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| unsigned int steps_done = elapsed_secs / cfg->step_duration; | ||
| display_clients = cfg->clients_start + steps_done * cfg->clients_step; | ||
| if (display_clients > cfg->clients) display_clients = cfg->clients; | ||
| } |
There was a problem hiding this comment.
Model-based display diverges from actual active clients
Low Severity
The display_clients in the progress loop and the active count in JSON Active Clients section are computed from a wall-clock model (clients_start + steps_done * clients_step) instead of reading the actual active_client_count() from each thread's client_group. If a staircase step's prepare() partially fails in handle_staircase_step, the model still reports the full expected count while the real m_staircase_active_clients atomic reflects fewer connected clients. This makes both the live progress display and the persisted JSON report inaccurate regarding actual active connections during failure scenarios.
Additional Locations (1)
…t-interval RED-197205 reported that running with --reconnect-interval=1 produced a final summary where Totals.Ops/sec, KB/sec, Hits/sec and Misses/sec all rendered as 0.00 even though Count and Latency were correct. Root cause (on v2.2.1): client_group::merge_run_stats() iterated *all* clients including those that were prepare()-d but never reached set_start_time(). Their zeroed m_start_time was factorial-averaged into the aggregate, dragging it toward the epoch. With m_end_time correct but m_start_time near zero, test_duration_usec became huge and every `ops / test_duration_usec * 1000000` division collapsed to ~0. Fix landed in 0228bac (PR redis#350): a run_stats::m_started atomic flag plus has_started() guards in merge_run_stats() and aggregate_inst_histogram() that skip never-started clients. RED-197205 was a side-effect fix, not the headline of that PR, so this test pins down the invariant explicitly. Verified end-to-end against the test's exact workload: v2.2.1 + 4t/4c --test-time=5 --ratio=1:1 --reconnect-interval=1 -> Ops/sec=0.00, KB/sec=0.00, Misses/sec=0.00 (bug fires) master + same args -> Ops/sec=52320, KB/sec=3035, Misses/sec=26114 (fixed) The bug only fires reliably with --test-time (not -n); with -n every client runs to completion and reaches set_start_time, so the zero-state merge path is never hit. _build_benchmark gains an optional test_time parameter so the helper can express that distinction. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…t-interval * test(red-197205): regression test for zero-rate stats with --reconnect-interval RED-197205 reported that running with --reconnect-interval=1 produced a final summary where Totals.Ops/sec, KB/sec, Hits/sec and Misses/sec all rendered as 0.00 even though Count and Latency were correct. Root cause (on v2.2.1): client_group::merge_run_stats() iterated *all* clients including those that were prepare()-d but never reached set_start_time(). Their zeroed m_start_time was factorial-averaged into the aggregate, dragging it toward the epoch. With m_end_time correct but m_start_time near zero, test_duration_usec became huge and every `ops / test_duration_usec * 1000000` division collapsed to ~0. Fix landed in 0228bac (PR #350): a run_stats::m_started atomic flag plus has_started() guards in merge_run_stats() and aggregate_inst_histogram() that skip never-started clients. RED-197205 was a side-effect fix, not the headline of that PR, so this test pins down the invariant explicitly. Verified end-to-end against the test's exact workload: v2.2.1 + 4t/4c --test-time=5 --ratio=1:1 --reconnect-interval=1 -> Ops/sec=0.00, KB/sec=0.00, Misses/sec=0.00 (bug fires) master + same args -> Ops/sec=52320, KB/sec=3035, Misses/sec=26114 (fixed) The bug only fires reliably with --test-time (not -n); with -n every client runs to completion and reaches set_start_time, so the zero-state merge path is never hit. _build_benchmark gains an optional test_time parameter so the helper can express that distinction. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(test): widen Time-Serie tolerance to account for accumulated-latency quantization CI on PR #384 surfaced this: with --reconnect-interval=1 and --test-time=5, the trailing per-second bucket can hold very few ops (Count as low as 1). 'Accumulated Latency' is emitted with %lld (1 ms precision), so the reported value can differ from the true sum by up to 1 ms — which means the derived avg = accumulated/count can differ from the double-precision 'Average Latency' by up to (1 / count) ms. The previous tolerance was max(0.01 ms, 2% relative). For Count=1 with a sub-ms avg that's 0.01 ms; observed gap was 0.058 ms (0.391 vs 0.333), well within the quantization bound but outside the static tolerance. Add a third term `1.0 / count` so the quantization error is modeled explicitly. For large-count buckets (the typical case in every existing test) the existing tolerance still dominates, so no behavior change for them. Verified by replaying the exact failing workload locally: -t 4 -c 4 --test-time=5 --ratio=1:1 --reconnect-interval=1 old tolerance: 3 violations across Sets/Gets/Totals bucket 5 new tolerance: 0 violations Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(red-197205): skip reconnect-interval test in cluster mode memtier rejects --reconnect-interval together with --cluster-mode ("error: cluster mode dose not support reconnect-interval option"), so the test exited non-zero on every cluster CI job. The RED-197205 regression is not cluster-specific — guard the test with env.isCluster() so it only runs in single-endpoint configurations. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * ci: retrigger CI run after timeout fluke --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
The per-run run_stats are built with merge(), which never set m_started. Since 0228bac (#350), get_duration_usec() returns 0 until m_started is set, so every run's duration was 0, the ops/sec divisor fell back to 1 and the (int) cast overflowed to the same value for every run. Run #1 then won both the best and the worst comparison. Set m_started in merge() when a started run is merged in, and compare runs by a double ops/sec instead of an int-cast value. Fixes #565 Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
--clients-start,--clients-step, and--step-durationCLI options to gradually increase client connections per thread during a benchmark, enabling staircase-style load ramp-up--test-timeis too short to reach max clients"Active Clients"section for downstream correlationExample
Test plan
tests/test_client_staircase.pyvalidating JSON config fields, Active Clients section structure, staircase pattern correctness, total/per-thread client math, max cap enforcement, ops produced every step, and non-staircase regression🤖 Generated with Claude Code
Note
Medium Risk
Adds a new time-based client ramp-up mode that changes connection lifecycle, event-loop behavior, and stats aggregation across threads; issues could affect benchmark termination timing and reported metrics accuracy.
Overview
Adds a client staircase ramp-up mode via new CLI flags
--clients-start,--clients-step, and--step-duration, plus bash completion and man/usage updates.Implements per-thread, timer-driven activation of pre-created clients (connect in steps) and switches staircase runs to a shared
benchmark_start_timeso all clients stop on the same--test-timedeadline and per-second stats align.Updates stats aggregation/output to account for partially activated clients (tracks
has_started(), merges/exports only started clients, reports per-second "Active Clients" in JSON), adjusts progress/StatsD connection gauges to reflect current active connections, and adds a comprehensivetests/test_client_staircase.pysuite covering validation and output behavior.Written by Cursor Bugbot for commit 0d0e60d. This will update automatically on new commits. Configure here.