Repository navigation
Fix --clients-start runs ending up to 1 s before --test-time - #722
Conversation
39636c3 to
927e09e
Compare
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through it and the fix looks right to me. Using A few small things:
Nitpicking: the comment above the deadline check in None of this blocks the merge as far as I can tell. The core change looks solid. (would file this as a comment, not a formal block) |
927e09e to
0b4f272
Compare
|
Thanks for the review. Point by point:
|
|
Follow-up to (b) in the reply above: the pre-existing behaviour where the staircase timer stays armed past |
In staircase mode the run's deadline was checked as now.tv_sec - benchmark_start_time.tv_sec >= test_time, which drops the microseconds. A run that started at x.6 s therefore ended at x+test_time whole seconds, about 0.4 s early: "Total duration" for --test-time 3 was anywhere between 2.0 and 3.0 s, and the last staircase step got a shorter window than the others. client::finished() now compares the full elapsed timeval, as run_is_over() already does. client_group::handle_staircase_step() used the same whole-second check to stop at the deadline. It now decides by the step count instead: step k is due at k * step_duration and is taken only if that is before test_time. A clock check does not work there either way: the timer runs on libevent's monotonic clock and can fire a hair before the deadline by gettimeofday(), so an exact check connected one more client per thread at the deadline, which the run then stopped at once. The clock is still checked as well, with full timevals: after a stall of the event loop (SIGSTOP, VM pause) libevent reschedules the timer from "now", so the count lags behind and a step could otherwise fire after the deadline. The JSON "Active Clients" entry is computed from the bucket's second. Now that the last requests can complete just after the deadline, in a bucket at t = test_time, cap it at the last step due before test_time, so that bucket does not count a step that was never taken. The live display's client count now rounds down from the microsecond difference. The special case PR #667 added in handle_cluster_slots_retry_event() is kept, only its comment about whole seconds is dropped. Fixes #713 Co-Authored-By: Claude Opus 5.5 <[email protected]>
0b4f272 to
daf351f
Compare
|
Re the 17:48 review:
|
|
Thanks. Point by point:
|
In staircase mode the step timer is EV_PERSIST, and the deadline was only checked when it fired. Once the clients stopped at --test-time, that pending timer was the only event left and kept event_base_dispatch() running until its next tick: --test-time 2 --step-duration 20 took 20 s of wall time, --test-time 5 --step-duration 3 took 6-7 s. The results were not affected, the process just idled. setup_staircase_timer() now also adds a one-shot timer at benchmark_start_time + test_time that removes the step timer, so the thread's loop ends when its clients do. The step timer stays persistent, so the step schedule does not drift. If either event_new() fails, log it instead of passing NULL to event_add(); without the deadline timer the old behaviour (stop at the first tick past the deadline) remains, which is also why handle_end_stalled_clients() still removes the step timer. The live progress line now caps its staircase client count at the last step due before --test-time, as the JSON "Active Clients" does since #722. On the final line it used to count a step that never ran (4 conns instead of 3 for -c 6 --test-time 3 --step-duration 1). The StatsD "connections" and Prometheus memtier_connections gauges are fed from the same count, so they change the same way. Tests, both failing on master: - test_staircase_exits_at_test_time runs --test-time/--step-duration 2/20, 5/2, 4/2 and 5/3 and requires the worker threads' lifetime (JSON CPU cpu_wall_seconds, which excludes process startup) to stay below test_time + 0.5 s; without per-thread CPU accounting it falls back to process wall time < test_time + 3 s. It now also runs on oss-cluster. - test_staircase_progress_clients_match_json checks that the last progress line's conns equals the last JSON Active Clients entry. Fixes #728 Co-Authored-By: Claude Opus 5.5 <[email protected]>
) With --clients-start, setup_staircase_timer() added an EV_PERSIST step timer and the deadline was only checked when that timer fired. Once the clients stopped at --test-time, the pending step timer was the only event left and kept event_base_dispatch() running until the next step tick: --test-time 2 --step-duration 20 took 20 s. setup_staircase_timer() now also adds a one-shot timer at benchmark_start_time + test_time that removes the step timer, so the step schedule does not drift and the loop ends at the deadline. The four copies of the step-timer teardown are folded into remove_staircase_timer(), and both event_new() results are checked. The live progress line caps the staircase client count at the last step due before --test-time, as the JSON "Active Clients" does since #722. The StatsD connections and Prometheus memtier_connections gauges come from the same count, so after the deadline they no longer report a step that never ran. Tests: test_staircase_exits_at_test_time (2/20, 5/2, 4/2, 5/3; worker thread lifetime from the JSON, also on oss-cluster) and test_staircase_progress_clients_match_json; both fail on master. Fixes #728 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
In staircase mode (
--clients-start), a--test-timerun ends when the wall clock's seconds counter reachesstart_sec + test_time, not whentest_timeseconds have passed. "Total duration" for--test-time 3was anywhere between about 2.0 and 3.0 s, the Finish time always landed on a whole second, and the last staircase step got a shorter window than the others.Root cause
client::finished()andclient_group::handle_staircase_step()computed the elapsed time asnow.tv_sec - benchmark_start_time.tv_sec, droppingtv_usec. A run that started at 41.598 s hadelapsed >= 3at 44.000 s.Fix
client::finished()compares the full elapsedtimeval(timersub), asshard_connection::run_is_over()already does.client_group::handle_staircase_step()now decides by step count, not by the clock: step k (due at k * step_duration) is taken only ifk * step_duration < test_time. An exact clock check does not work there: the EV_PERSIST timer runs on libevent's monotonic clock and can fire a hair before the deadline bygettimeofday()(e.g. elapsed 2.9993 s for--test-time 3), which connected one more client per thread right before the run stopped (and, in cluster mode, sent a needless CLUSTER SLOTS from a client that can never start). The full-timeval clock check is kept as a second stop condition: after an event-loop stall (SIGSTOP, VM pause) libevent reschedules the EV_PERSIST timer from "now", so the count lags the clock and a step could otherwise fire after the deadline. The clock half cannot fire early, so it does not bring back the extra step. Checked with--test-time 5 --step-duration 2and SIGSTOP at 1 s for 3.5 s: no step after the deadline, 7.5 s wall (same as before the count rule; the count rule alone ran 9.5 s with 4 extra activations).ts_diff).run_stats.cpp) is capped at the last step due before--test-time,(test_time - 1) / step_duration. The trailing Time-Serie bucket att = test_timetherefore no longer reports a step that never ran. For example,-c 5 --clients-start 1 --clients-step 1 --step-duration 1 --test-time 3used to report 4 per thread in bucket "3" and now reports 3. This corrects a value in the JSON output.handle_cluster_slots_retry_event()is kept. Under--clients-startit is now equivalent torun_is_over(), but it is not clearly redundant in the other modes, so only its comment about whole seconds is removed.Behaviour note: since staircase runs now last the full
--test-time, the last requests can complete a few hundred µs after the deadline, so the Time-Serie may contain a small trailing bucket att = test_time. Non-staircase runs already have this. No existing staircase test encoded the old behaviour; all existing tests intests/test_client_staircase.pypass unchanged.Test evidence
Two new tests in
tests/test_client_staircase.py:test_staircase_runs_full_test_timelaunches memtier half way through a second and checksTotal durationis within [2900, 3300] ms for--test-time 3 --clients-start 1 --clients-step 1 --step-duration 1.xx000). This branch: 6/6 PASS.test_staircase_no_step_at_deadlineruns-t 8 -c 5 --clients-start 1 --clients-step 1 --step-duration 1 --test-time 3three times and asserts the server'stotal_connections_receiveddelta is exactly 24 (start + 2 steps per thread).tests/test_client_staircase.py(standalone): 13/13 pass.tests/test_cluster_slots_bad_reply.py(oss-cluster, 3 shards, includes #667's late staircase tests): 16/16 pass.Fixes #713
Affected versions
2.3.0 through 2.5.2 (latest) and master.
🤖 Generated with Claude Code
Note
Medium Risk
Changes core benchmark stop and ramp-up timing in staircase mode; behavior shifts from early termination to full test duration, with new edge-case guards for timer vs wall clock.
Overview
Fixes staircase mode (
--clients-start) runs ending up to 1 second early when--test-timewas compared using whole seconds only (tv_secdifference), ignoring microseconds.Deadline handling:
client::finished()now usestimersubfor the global staircase deadline, matching full wall-clock elapsed time. The staircase timer callback tracksm_staircase_stepsand stops ramp-up when eithersteps * step_duration >= test_time(avoids an extra client when libevent fires slightly before the wall-clock deadline) or the full timeval elapsed time reachestest_time(covers event-loop stalls where the step count lags).Reporting: Live progress client count uses
ts_difffor elapsed seconds. JSON Active Clients caps steps after the deadline so trailing time buckets do not show a step that never ran.Adds regression tests for full
--test-timeduration and for no connections added at the deadline step.Reviewed by Cursor Bugbot for commit daf351f. Bugbot is set up for automated code reviews on this repo. Configure here.