Skip to content

Stop --clients-start runs at --test-time instead of the next step - #742

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/728-staircase-timer-deadline
Oct 16, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/728-staircase-timer-deadline

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --clients-start, the process kept running after --test-time until the next --step-duration tick. The results were correct ("Total duration" equals --test-time), but the process sat idle: --test-time 2 --step-duration 20 took 20 s of wall time.

Root cause

client_group::setup_staircase_timer() adds an EV_PERSIST step timer, and handle_staircase_step() checks the deadline only when that timer fires. Once the clients stop at the deadline, that pending timer is the last event left on the thread's base. It keeps event_base_dispatch() running until the first tick at or after test_time.

Fix

  • Deadline timer: setup_staircase_timer() also adds a one-shot timer at benchmark_start_time + test_time, and that timer removes the step timer. The loop now ends when the clients do. The step timer stays EV_PERSIST, so the step schedule does not drift. The repeated delete/free blocks are now one remove_staircase_timer().
  • event_new() failures: a failure of either timer is now logged instead of passing NULL to event_add(). If only the deadline timer fails, the old behaviour remains: the run stops at the first tick past the deadline. That is why handle_end_stalled_clients() still calls remove_staircase_timer(); its comment now says so.
  • Follow-ups from the Fix --clients-start runs ending up to 1 s before --test-time #722 review:
    • The live progress line caps its staircase client count at (test_time - 1) / step_duration steps, as the JSON "Active Clients" does. Before, the final line counted a step that never ran: -t 1 -c 6 --test-time 3 --step-duration 1 showed 4 conns, and now shows 3 conns.
    • The two comment paragraphs above the deadline check in handle_staircase_step() are now one.

Visible change: StatsD and Prometheus

The StatsD connections gauge and the Prometheus memtier_connections gauge are fed from the same capped count. After the deadline they no longer include a step that never ran.

Test evidence

Base: origin/master 8ef3971 (includes #722 0fc29f4, #724 cde91ea and #730).

test_staircase_exits_at_test_time runs four --test-time/--step-duration cases: 2/20, 5/2, 4/2 and 5/3 (-t 2 -c 4 --clients-start 1 --clients-step 1).

  • It measures the worker threads' lifetime from the JSON ALL STATS.CPU.cpu_wall_seconds, so process startup does not count, and requires it to stay below test_time + 0.5 s.
  • Without per-thread CPU accounting (non-Linux), it falls back to process wall time below test_time + 3 s.
  • 2/20 is the strong discriminator. The test now also runs on oss-cluster.

test_staircase_progress_clients_match_json takes -t 1 -c 6 --test-time 3 --step-duration 1. It parses the \r-separated stderr and requires the last progress line's conns to equal the last JSON "Active Clients" entry, which is 3.

test env master 8ef3971 this PR
exits_at_test_time oss fails 3/3 runs. Thread lifetime: 2/20 → 20.00 s, 5/2 → 6.00 s, 5/3 → 6.00 s passes 11/11 runs (2/20 → 2.0 s)
exits_at_test_time oss-cluster fails. Thread lifetime: 2/20 → 20.00 s, 5/2 → 6.00 s, 5/3 → 6.00 s passes
progress_clients_match_json oss fails 3/3 runs (4 conns, JSON 3) passes 11/11 runs

Wall time of the whole process, measured by hand with the fixed build (-t 2 -c 4):

case master this PR
2/20 20.0 s 2.0 s
5/2 6-7 s 5.0 s
5/3 7.0 s 5.0 s
4/2 — 5.0 s

For comparison, a run without staircase at --test-time 2 takes 3.0 s, because the main loop polls once a second. Before and after the fix, "Total duration" equals --test-time and "Unanswered requests" is 0.

Other tests:

Affected versions

2.3.0 through 2.5.2 (the latest release), and master.

Fixes #728

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira force-pushed the fix/728-staircase-timer-deadline branch from 03d1b75 to 46ccb7f Compare October 16, 2026 20:05
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]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/728-staircase-timer-deadline branch from 46ccb7f to 83f99bc Compare October 16, 2026 21:24
@github-actions

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. The root cause analysis matches the code, and the one-shot deadline timer seems like the right fix: the step timer stays EV_PERSIST, so the step schedule doesn't drift, and moving teardown into remove_staircase_timer() removes four copies of the same block. I first wondered whether the unconditional deadline timer in setup_staircase_timer() would fire right away with test_time == 0 and stop the ramp. It can't happen, because staircase mode already requires --test-time (memtier_benchmark.cpp:4803) and rejects --requests. Good to see the new tests fail on master and pass with the fix.

A few small things:

  • The thread_wall < test_time + 0.5 bound in test_staircase_exits_at_test_time seems tight for loaded CI runners (standalone cells now run with PARALLELISM=2). As I read it, the failure modes you're catching end the thread at least a full second late: 5/2, 4/2 and 5/3 all end at 6 s. Did you consider + 1.0 or close to it? That would still catch every case and leave more headroom.
  • Nitpicking: the progress-line cap in run_benchmark() is now a copy of the one in run_stats.cpp (the "Active Clients" loop). Since the point is that the two must agree, would a small shared helper (staircase_clients_at(elapsed_secs) or similar) be easy here? Fine to leave as is if it's awkward.
  • Nitpicking: the PR body says the test bound is test_time + 2 s, but the code and the commit message use + 0.5 (thread wall) and + 3 (fallback). Worth updating the description so it matches.
  • The commit message notes that the StatsD connections and Prometheus memtier_connections gauges change along with the progress line. That's a correction (they now agree with JSON instead of reporting a step that never ran), so I don't see a compat problem. It might still be worth a line in the release notes for anyone alerting on those gauges.

The fix itself looks solid to me. None of the points above should block merging.

@fcostaoliveira

fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks. Answering the 21:26 version of the review point by point:

  • thread_wall < test_time + 0.5: the bound is on the worker threads' own lifetime (JSON cpu_wall_seconds), not on process wall time, so startup and the main loop's 1 s poll are excluded. It held in every CI cell at this head, including the ASan/TSan cells under PARALLELISM=2. The broken cases end at least a full second late (6.00 s for 5/2 and 5/3, 20.00 s for 2/20), so + 1.0 would sit right on the 6.00 s failure value; + 0.5 leaves margin on both sides. If a slow cell ever trips it, raising it to + 0.9 is a one-line change that still catches every case.
  • Shared helper for the cap: fair. It's a one-line formula in two places. I'll fold it into a small helper the next time this code is touched, rather than restart CI for it now.
  • PR body says + 2 s: the description was updated in the last pass. It now says + 0.5 s (thread wall) and + 3 s (fallback), matching the code and commit message.
  • Release note for the gauges: the description has a "Visible change: StatsD and Prometheus" section covering the connections / memtier_connections correction for anyone alerting on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant