Skip to content

End a --test-time client that never had a reply at its deadline - #869

Merged
fcostaoliveira merged 2 commits into
masterfrom
claude/end-time-deadline-867
Oct 25, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
claude/end-time-deadline-867

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #867.

Problem

In a --test-time run with --reconnect-on-error, a client that sent workload but never got a reply had its end time stamped at "now" by client::set_end_time(). That happens when its post-deadline reconnect completes ("Done, no requests to send"), or when its thread ends. Since #821 such a client takes part in the run's duration average, so Total duration came out above --test-time and Ops/sec was deflated.

The issue suggested widening the gate in end_client_after_run(), but that path isn't the one stamping this client. Widening it would also break #666's rule: when the server is gone after the deadline, a client with no reply is left unended on purpose so the run fails.

Change

client::set_end_time() caps the client's end at its own start plus --test-time when all of these hold:

  • it is a --test-time run;
  • the client has no reply but has submitted workload;
  • its clock has started, and now is past that deadline.

The deadline check is the same overflow-safe one that set_end_time_interrupted() uses for Ctrl+C after the deadline (#747), so both paths now agree. The cases this leaves alone:

  • Clients with replies: still end at "now", since that time can cover replies drained after the deadline.
  • Never-submitted clients: stay out of the average (Exclude setup-only clients from final workload duration #821).
  • --requests runs: have no deadline, so nothing changes.
  • Staircase clients: timed from the benchmark's start, so they end at the run's deadline.

The README's reconnect note now says this extra time is not in the reported duration.

Results

Scripted peer, 2 clients (A served normally, B's first SET held past the deadline), --rate-limiting=100, --test-time=4 (the cluster row: --test-time=3, ideal 3000 ms). Ideal: about 4000 ms, 100 ops/sec. Two runs each, except where noted.

Scenario master f22d336 this PR
unlimited --max-reconnect-attempts 5001 / 80.0, 5010 / 80.2 4000 / 100.0, 4000 / 100.0
--max-reconnect-attempts=5 5504 / 72.7, 5503 / 72.7 4011 / 100.2, 4000 / 100.0
staircase 5500 ms 4000 ms
cluster, B held on 2 shards, --test-time=3 (unlimited / finite attempts) 4001 / 4502 ms 3000 ms
Ctrl+C after the deadline (#747) about 4000 ms about 4000 ms
--requests 3503 ms 3503 ms

Tests

  • New tests/test_unanswered_end_time.py: 4 cases, standalone and cluster, with unlimited and finite attempts. The peer releases B's held SET only after A has closed its connection, plus 2 s, so there is no SIGINT and nothing races memtier.
    • Total duration must be within 300 ms of --test-time and Ops/sec within 8% of Count over that time.
    • On master all 4 fail, at 4000–4522 ms; with the fix all 4 pass, at 3000–3005 ms.
  • Related tests, all passing: test_reconnect_start_time 4/4, test_duration_participation 5/5, test_client_staircase 15/15, test_late_interrupt_duration 3/3, test_reconnections 32/32, test_connection_setup_rejected 14/14, test_cluster_slots_bad_reply 20/20, test_test_time_stalled_server 5/5.
  • make check: 18/18, and clang-format 18 is clean.

Not covered

A client that did get replies, all before the deadline, can still have its end stamped late by a post-deadline reconnect: for example, B answered on one shard and held on another. Fixing that needs a per-client last-reply time and changes timing for answered clients, so it's tracked separately as #870.

Affected versions

The uncapped end time has been in every release: up to 2.5.2, set_end_time() always stamps "now". On master since 0bb7fc5 (#666, unreleased), only clients with replies are capped, in end_client_after_run().

🤖 Generated with Claude Code


Note

Medium Risk
Changes core --test-time duration accounting for reconnect edge cases; behavior is narrow (no replies + submitted workload) but affects reported throughput and run timing metrics.

Overview
Fixes #867: in --test-time runs with --reconnect-on-error, a client that submitted workload but never received a reply no longer has its stats end time stamped at a post-deadline reconnect or thread shutdown. client::set_end_time() now caps that client at its own start time plus --test-time (overflow-safe, same pattern as interrupt handling), instead of using the benchmark-wide deadline—so late-starting clients are not shortened and Total duration / Ops/sec stay aligned with --test-time. Clients with replies still end at “now” so time spent draining replies after the deadline remains counted (#870).

The README reconnect section documents that this extra reconnect wait is excluded from an unanswered client’s duration share.

New integration tests (tests/test_unanswered_end_time.py) drive a scripted peer for standalone and cluster mode, unlimited/finite reconnect attempts, late start, post-deadline drain for answered clients, and early give-up before the deadline.

Reviewed by Cursor Bugbot for commit a53d066. Bugbot is set up for automated code reviews on this repo. Configure here.

With --reconnect-on-error, a client that had sent workload but never got a
reply had its end time stamped at "now" by client::set_end_time(): when its
reconnect after the deadline completed, or when its thread ended. Such a
client takes part in the run's duration average (#821), so Total duration
came out above --test-time and Ops/sec was deflated. With two clients, one
served normally and one whose SET was held 2 s past a 4 s deadline, the run
reported about 5000 ms and 80 ops/sec (5500 ms and 73 with
--max-reconnect-attempts=5) instead of 4000 ms and 100.

Cap such a client's end at its own start plus --test-time, as Ctrl+C after
the deadline already does (#747): it has no op past the deadline to
account for. A client with replies still ends at "now", since that time can
cover replies it drained after the deadline. A client that never submitted
stays out of the average, and --requests runs have no deadline, so neither
changes. Staircase clients are timed from the benchmark's start, so they
end at the run's deadline. end_client_after_run() keeps leaving such a
client unended when its server is gone after the deadline: that run still
fails, as #666 documents.

test_unanswered_end_time.py runs that scenario against a scripted peer,
standalone and in cluster mode, with unlimited and finite reconnect
attempts. The peer closes B only after A has ended and closed its
connection, so B's drop is always past the deadline.

Fixes #867

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

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

Thanks for this. I went through the client.cpp change and the new test. The fix looks right to me, and I only have one small point.

  • Just a quick check: the "end at start + --test-time" rule now lives in three places: set_end_time_interrupted(), abandon_unanswered_requests() and this new branch in set_end_time(). The first and the new one share the overflow-safe ts_diff(...) > test_time * 1000000 guard. abandon_unanswered_requests() adds test_time to tv_sec directly, which I think is safe there only because of its earlier duration check. If it's easy, it would be nice for these to share a small helper, something like "deadline for this client if now is past it". That way the next fix to this rule (e.g. --test-time: a client whose last reply came before the deadline has its end stamped at a post-deadline reconnect, so Total duration exceeds --test-time #870's per-client last-reply time) only has to change one place. What do you think? It's not a blocker.

The tests are what I'd hope for. The four held cases fail on master and pass with the fix. late, drain and early cover the conditions the cap deliberately doesn't apply to: B's own start rather than run_deadline(), clients that got replies, and clients that gave up before their deadline. Without those, a wider version of the fix would also have passed the tests. The early case is a good catch: it guards against stamping an end time that is still in the future. I also checked that the old set_end_time_at(NULL) → set_end_time_at(&now) change does the same thing, since run_stats::set_end_time() just calls gettimeofday() for NULL.

The core fix looks good to me. The helper is optional.

test_unanswered_end_time.py only checked an unanswered client that starts
with the benchmark and is dropped after its deadline. Three cases, using
the same scripted peer, now cover the other conditions of the cap:

- B's first connection is closed on AUTH, so its clock starts about 1 s
  late. Its end must be its own start plus --test-time: a deadline taken
  from the benchmark's start reports about 2500 ms instead of 3000.
- B is answered, but one SET is held until 2 s past A's end. A client with
  replies ends when that reply is drained, so Total duration stays about
  1000 ms above --test-time; capping it would report 3000 ms.
- B's SET is dropped and its reconnect is closed on AUTH, so B gives up
  about 1 s in and the run fails. Total duration must not exceed memtier's
  reported wall time; always capping would stamp B's end in the future and
  report about 2000 ms for a 1 s run.

The client.cpp comment now says why the client's own start is used rather
than run_deadline(), and deadline is declared where it is used. The README
sentence is scoped to the client's share of the duration, and says that a
client with replies still includes its time past the deadline (#870).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Review summary for a53d066. All 7 lenses approve (semantics, output, tests, lifecycle, interactions, maintainability, build).

  • Fix: the end of a client that sent workload but never got a reply is capped at its own start plus --test-time. Measured: 5001 → 4000 ms with unlimited reconnect attempts, and 5504 → 4011 ms with 5.
  • Unchanged: wall time, exit codes and End a --test-time run at its deadline while reconnecting to a dead server #666's server-gone rc 1 are the same as on master.
  • Tests: test_unanswered_end_time.py has 7 cases. The late, drain and early cases each catch one wrong variant of the fix:
    • timing from the benchmark start instead of the client's own start;
    • capping clients that had replies;
    • capping before the deadline.
  • CI: the file passes 98/98 across 14 cells, including ASan, TSan and UBSan, and all 875 existing tests match master.

On the shared deadline helper: the overflow-safe "own start + test time, only once past" arithmetic is the only part this cap shares with set_end_time_interrupted(). The gating rules really differ, and run_deadline() uses a different start for clients that never started, so it can't simply be merged in. I'd rather not refactor the interrupt path inside this fix, and the code comment points at the twin. The answered-client gap is #870.

@fcostaoliveira
fcostaoliveira merged commit a533d92 into master Oct 25, 2026
151 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 25, 2026
…er the deadline (#876)

With --reconnect-on-error, a --test-time client that got replies, all
before its deadline, and then stalled had its end time stamped at "now"
by client::set_end_time() when its reconnect after the deadline
completed. #869 capped this only for a client that never had a reply.
With one client served normally and one answered 20 times and then held
past a 4 s deadline, the run reported about 5100 ms and 82 ops/sec
(5600 ms and 75 with --max-reconnect-attempts=5) instead of 4000 ms.

Record when each client's last reply was read, from the timestamp
process_response() already takes, so a reply costs no extra clock read.
Once a client's own start plus --test-time is past, end it at that
deadline or at its last reply, whichever is later, and no later than
now. Replies drained after the deadline still count, but the idle time
after them does not. In cluster mode the last reply is per client,
whichever shard it came on, and setup replies do not count. This applies
to every answered client past its deadline, so a rate-limited client
that ends on a timer tick after it no longer counts that gap.
end_client_after_run() is unchanged, so a run whose server is gone
after the deadline still fails (#666).

test_answered_end_time.py runs the stalled client against a scripted
peer, standalone and with two cluster shards, with unlimited and finite
reconnect attempts; a client answered past the deadline that then idles;
and a cluster client answered late on one shard while the other shard's
reconnect setup is held. test_run_count_partial_ranking.py now expects
a run whose worker drops after its deadline to end at the deadline.

Not covered: a stalled reconnect setup can still let new requests go
out past the deadline (#879), and the interrupt, dead-server and
drain-grace end paths still cap at the deadline (#880).

Fixes #870

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--test-time: a client that sent workload but never got a reply has its end time past the deadline, so Total duration exceeds --test-time

1 participant