Skip to content

End a --test-time client at its last reply when the server stalls after the deadline - #876

Merged
fcostaoliveira merged 4 commits into
masterfrom
claude/answered-end-time-870
Oct 25, 2026
Merged

fcostaoliveira merged 4 commits into
masterfrom
claude/answered-end-time-870

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #870.

Problem

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, so Total duration still came out above --test-time and Ops/sec was deflated.

Change

  • Last reply time: each client records when its last reply was read. It reuses the timestamp process_response() already takes, so a reply costs no extra clock read.

  • End time: once the client's own start plus --test-time is past, the client ends at that deadline or at its last reply, whichever is later, and never later than now. Replies drained after the deadline still count; the idle time after them doesn't.

  • Deadline: the client's own start, as in End a --test-time client that never had a reply at its deadline #869. For a client with replies, run_deadline() gives the same time.

  • Unchanged:

  • Scope: this applies to every answered --test-time client past its deadline, not only one stalled on a reconnect. A healthy client ends in the same callback as its last reply, so it barely changes. A rate-limited client that ends on a timer tick after its deadline no longer counts the gap after its last reply, so Total duration and Ops/sec for ordinary rate-limited timed runs can move by up to one rate tick compared with 2.5.x.

Results

Total duration in ms; every run exits 0. The standalone rows use --test-time=4, the others --test-time=3.

Case master a533d92 this PR
Standalone, unlimited attempts (ideal 4000) 5115, 5106 4000, 4000
Standalone, --max-reconnect-attempts=5 5608, 5609 4010, 4010
2 cluster shards, unlimited (ideal 3000) 4020, 4009 3001, 3000
2 cluster shards, finite 4005, 4025 3000, 3000
Last reply past the deadline, then idle (ideal ~3500) 4561–5064 3541–3562
2 cluster shards, late reply on one, held reconnect AUTH on the other (ideal ~3500) ~4005 3500–3520

Tests

  • New tests/test_answered_end_time.py: 6 cases, all failing on master:
    • the stalled client, standalone and on two cluster shards (answered on one, held on the other), with unlimited and finite reconnect attempts;
    • a client whose held request is answered past the deadline and which then idles;
    • a cluster client answered late on one shard while its other shard's reconnect AUTH is held longer, so it ends at that late reply, not at the setup reply or per shard.
  • Mutants: each fails at least one case across the two end-time files (the run_deadline() one only in test_unanswered_end_time.py): always capping at the deadline, run_deadline() instead of the client's own start, no cap, min for max, a per-connection last reply, and setup replies moving the last reply.
  • tests/test_run_count_partial_ranking.py: a run whose worker drops a held request after its deadline now ends at the deadline, not at the drop, so its duration bound is now 1000 to 1200 ms instead of above 1000.
  • Existing tests: test_unanswered_end_time.py is unchanged and its drain case still passes. The related tests pass 64/64, including End a --test-time run at its deadline while reconnecting to a dead server #666's server-gone run, which still exits 1. make check passes 18/18.

Performance

Measured on a quiet Xeon 6972P host (gnr1): local Redis 8.2.2, plain TCP loopback, 8 threads × 25 clients, ratio 1:10, arms interleaved, 8 runs per arm.

pipeline master median Ops/sec this PR delta Mann-Whitney p
1 285,116 285,690 +0.20% 0.33
16 2,024,154 2,033,862 +0.48% 0.33

GET p50 and p99 move by at most one 8 µs histogram bucket, and instructions per op rise by 0.03%. Both are within run-to-run noise.

Not covered here

Affected versions

Every release: up to 2.5.2, set_end_time() always stamps "now". On master, 0bb7fc5 (#666) caps answered clients only in end_client_after_run(), which this path doesn't reach.

🤖 Generated with Claude Code


Note

Medium Risk
Changes core --test-time duration and Ops/sec accounting for clients with replies under reconnect/stall scenarios; behavior is well-tested but affects reported benchmark metrics.

Overview
Fixes #870: --test-time clients that already received replies no longer stretch Total duration to a post-deadline reconnect completion when the server stalls after --reconnect-on-error.

Each client now tracks m_last_reply_time when replies are read (inc_reqs_answered takes the existing handle_response timestamp). client::set_end_time() sets the interval to max(client start + --test-time, last reply), capped at now—so late drained replies count, but idle wait after the last reply does not. Clients with no replies still end at their deadline (#867 behavior).

README documents the updated duration rules (including --retry-on-error and #879/#880 caveats). Tests: new tests/test_answered_end_time.py (stalled, cluster, late reply, split-shard scenarios) and tighter bounds in test_run_count_partial_ranking.py.

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

…er the deadline

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. #867 capped this only for a client that never had a reply,
since the time past the deadline can cover replies drained after it. So
Total duration came out above --test-time and Ops/sec was deflated. 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 and 105.

Record when each client's last reply was read, from the timestamp
process_response() already takes for handle_response(), 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. The deadline stays the client's own start,
as in #867: for a client with replies run_deadline() is the same time,
and for one without it would inflate Ops/sec for a late start. In cluster
mode the last reply is per client, whichever shard it came on. A client
that never submitted stays out of the average, and --requests runs have
no deadline. 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 (answered on one, held on
the other), with unlimited and finite reconnect attempts. A third case
answers the held request past the deadline and then idles the client
behind a second one, so it ends at that reply, not at the deadline or
at the reconnect.

Fixes #870

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. The fix is small, it reuses the now that process_response() already takes, and the tests are good: six scripted-peer cases that fail on master, plus the mutant list. That is the fails-then-passes bar this repo already accepted in #364. I have a couple of comments below.

  • I think this reaches more than the stalled-reconnect path. m_reqs_answered == 0 is gone from the condition, so every answered --test-time client past its deadline now ends at max(deadline, last reply), not at "now". A healthy client is barely affected, because its last reply and set_end_time() come in the same callback. A rate-limited client that finishes on a timer tick after its deadline, though, now loses that gap from its interval. Your own test comment calls this out for A ("first rate tick past its deadline"). I agree it's more correct, but it slightly moves Total duration / Ops/sec for ordinary timed runs too. Could the PR description and the release note say so, so nobody comparing against 2.5.x is surprised?
  • The test_run_count_partial_ranking change also shows this: a failed run's duration moves from the drop time to the deadline. That makes sense to me. I'd just like a second look from whoever owns the run-count ranking logic, to confirm nothing ranks or filters on that duration.
  • Nitpicking: mark_started() in tests/unit/reconnect_siblings_test.cpp sets m_reqs_answered = 1 but leaves m_last_reply_time at {0,0}. The m_reqs_answered && guard plus the deadline floor keeps this safe, but the fixture now describes a state the real code can't reach. Maybe set both, e.g. through inc_reqs_answered(*start)?
  • Nitpicking: the comment block in set_end_time() and the README bullet are getting long. It's fine since they point to --test-time: a client whose reconnect setup stalls past its deadline sends new requests once it completes (finished() reads a stats clock that only replies move) #879/--test-time: the interrupt (#747), dead-server (#666) and drain-grace end paths cap an answered client at its deadline, dropping replies it drained past it from the interval #880, but it may be worth tightening once those land.

The core change looks solid to me. I'd mainly want the scope of the duration change spelled out before this merges.

(would file this as a comment, not a formal block)

fcostaoliveira and others added 3 commits October 25, 2026 10:27
…t a setup reply

No case pinned two rules of the previous commit: the last reply is the
client's, whichever shard it came on, and a setup reply (AUTH, SELECT,
CLUSTER SLOTS, HELLO, READONLY) is not one. A last reply kept per shard
connection, or one that setup replies also move, passed every case.

The new "split" case gives B two shards, with --key-pattern=S:S over
memtier-1 and memtier-2 so its SETs alternate between them. After B's
20th reply the first shard's connection is closed, and its reconnect's
AUTH is held until A has closed plus 2 s. B's next SET on the second
shard is answered at A's close plus 1 s. B ends from the first shard
once its setup completes, at the late reply on the second: about 3500
ms. A per-connection last reply gives about 3000 ms, and counting the
AUTH reply about 4000.

Reword the README and the set_end_time() comment: replies drained
after the deadline count and the idle time after the last one does not;
with --retry-on-error a resent request answered after the reconnect
moves the end to its reply; and a client whose reconnect setup stalls
past its deadline can still send new requests once it completes, whose
replies extend its end (#879).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…line

test_worker_failure_after_timed_deadline_is_partial checked that the
failed run's Total duration was above 1000 ms. Its peer answers three
requests and drops the fourth 1.3 s in, so the duration used to be the
drop time. The client's last reply came before its 1 s deadline, so it
now ends at the deadline: exactly 1000 ms, and Coverage shard 4/8
failed on 1000 > 1000. Check that it ends at the deadline, not at the
drop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The split case failed when B's first SET after its 20th reply went to
the second shard, which held it. A key generated for the second shard
then queued behind the held SET, and the two filled B's in-flight
budget (--pipeline times its 2 connections). B sent nothing more on the
first shard, so that connection was never closed and its reconnect's
AUTH never held (b_held 0, no "connection dropped"). B still ended at
the late reply, at 3500 ms, but from the second shard, so neither a
per-connection last reply nor a counted setup reply could change the
result. This showed in the UBSan OSS-CLUSTER cell, and in 3 of 10 local
runs with memtier at nice 19 on one CPU with 2 busy loops. B reached
its 20 replies about 2.6 s before its deadline, so this was not about
slow start-up.

Hold nothing on the second shard until the first is closed: B's SETs
there are answered normally until then, and the next one after it is
held and answered late. The peer now sets the order in both cases. The
per-connection mutant still gives 3000 ms, and the one that counts setup
replies 4000.

The README bullet that states the drain rule now notes that a failed
reconnect, Ctrl+C and the drain grace still end the client at its
deadline (#880).

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

Copy link
Copy Markdown
Collaborator Author

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

  • CI: 15,987 tests with 0 failed, and every per-test result matches master. The new file passes 84/84 across 14 cells, including the sanitizer cluster cells. The two earlier CI failures (the partial-ranking duration bound and a split-case ordering flake in the test peer) are fixed in eb0a000 and a2374bd.
  • Performance: on a quiet lab box, +0.20% at pipeline 1 and +0.48% at pipeline 16 (p = 0.33). Instructions per op rise by 0.03%.

Answering the review:

  1. Scope: agreed, and now stated in the description under Scope. It will go in the release notes too.
  2. Run-count ranking: BEST/WORST selection (Prefer complete runs for BEST and WORST results #794) ranks complete runs by throughput and keeps partial runs out on Interrupted, not on duration. The test's other checks (Count 3, Interrupted true, BEST/WORST = run 2) are unchanged and pass. No other open PR asserts Total duration or Ops/sec in a way this changes.
  3. mark_started() fixture: it's safe as is, as you note. I'll set both fields when --test-time: a client whose reconnect setup stalls past its deadline sends new requests once it completes (finished() reads a stats clock that only replies move) #879 touches that fixture.
  4. Comment and README length: I'll tighten them when --test-time: a client whose reconnect setup stalls past its deadline sends new requests once it completes (finished() reads a stats clock that only replies move) #879 and --test-time: the interrupt (#747), dead-server (#666) and drain-grace end paths cap an answered client at its deadline, dropping replies it drained past it from the interval #880 land.

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 whose last reply came before the deadline has its end stamped at a post-deadline reconnect, so Total duration exceeds --test-time

1 participant