Repository navigation
Report connection errors and Ctrl+C of clients that never connected - #707
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the merge path and the tests, and I only have a couple of small questions. The fix looks right to me. All client groups merge into the same
The core change looks solid to me. The two points above are questions, not blockers. |
16b6ada to
0905dcf
Compare
|
Thanks for the review. Answers to each point, as of 0905dcf:
|
0905dcf to
f96e9cf
Compare
When no connection ever succeeds, no client sets a start time, and client_group::merge_run_stats() skipped every such client so that its zeroed start time would not be averaged into the merged timestamps. The connection errors and the interrupted flag those clients recorded were dropped with them: the final report and JSON said "Connection Errors: 0" although the live line counted every failed connect, and a Ctrl+C left "Interrupted": "false". The Ctrl+C message averaged the client durations, which are 0 for clients that never started, and printed "after 0.0 secs". Merge every client. run_stats::merge() now takes only the connection error count, the interrupted flag and the unanswered requests of a run that never started, adding the errors to the current second that summarize() already includes; its timestamps and per-second buckets (keyed from the epoch, since the start time is zero) are still left out, and it does not advance the averaging counter. The Ctrl+C message uses the wall time since the run started. Fixes #702 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the connection errors of never-started clients in the current second, print() now calls summarize() for a run whose merged duration is 0. totals_cmd::summarize() divided by that duration, so the Sets, Gets and Waits Ops/sec and KB/sec printed -nan and were null in the JSON (also in BEST/WORST with --run-count), where master printed 0. Return 0 rates for a zero duration, like the hits/misses and connection error rates. Drop the unanswered-requests merge of never-started clients: they sent no requests. Say in merge() why the errors go to m_cur_stats and not to m_totals. Tests: assert 0 rates and no null outside "configuration" in the JSON of the dead-server runs; compare the connection error count with >=, since an error with errno 0 is counted but not logged; keep the refused port bound for the whole run instead of closing it first; and add a mixed run where client 0 is always refused and client 1 connects through a one-connection proxy, which checks the error count and that the merged run time is not halved by client 0's zero timestamps. Fixes #702 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Over TLS a refused connect logs "TLS connection error: (null)" rather than "Connection error: ", so the mixed test counted 0 logged errors and failed in the TLS CI cells. Count the "attempting reconnection" and "Maximum reconnection attempts" lines instead: attempt_reconnect() logs exactly one of them for each error it counts, on every transport. Run the dead-server tests with the TLS args too. Bound the count from above (clients x (1 + attempts), or the logged count plus one per client for the Ctrl+C run) and check that every Time-Serie second is within the run, so merging the epoch-keyed buckets of a never-started client again is caught. Give the mixed run an 8 s --test-time, so client 0's last dial at 6 s happens before the deadline also when reconnects stop at the deadline (#666), and expect the run to last at least 5 s: it ends when that dial fails, and averaging in client 0's zero timestamps halves it to 3 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f96e9cf to
f267365
Compare
|
Re the automated review posted at 13:14:
|
With more than one thread, run_benchmark() calls merge_run_stats() once per thread, all into the same run_stats. merge_run_stats() started its averaging weight at 1 on every call, and run_stats::merge() computes the running mean as (avg * (w - 1) + new) / w, so the first client of each thread replaced the average built so far. The merged Start time, Finish time and Total duration, and every Ops/sec and KB/sec derived from them, came only from the last thread's clients. Let the caller own the counter: run_benchmark() passes the same one to every thread's merge_run_stats(), so the weight keeps growing across threads. Clients that never started still do not advance it (#707). The test runs four rate-limited single-client threads and disconnects one client once, so it ends about 1 s after the others. The merged duration must be the mean of the four (about 3.25 s), not the last thread's 3 s or 4 s. Fixes #709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The merged run's Start time and Finish time are a running mean over every client that started, but client_group::merge_run_stats() reset its averaging counter for each thread. With more than one thread the last thread's clients outweighed all the others, so the merged Start and Finish time, Total duration and every rate (Ops/sec, KB/sec, hits/misses/aborts per second) came mostly from the last thread. A delayed client in another thread was ignored. The caller now owns a single counter that spans all threads; clients that never started still do not advance it (#707's rule). timeval_factorial_average() also overflowed int64 when the weight times the epoch-microsecond timestamp got large (about 5100 clients), which gave negative Start/Finish times in the JSON. It now computes a + floor((b - a) / w), which cannot overflow and equals the old result whenever the old one did not overflow. The .hgrm log written with --hdr-file-prefix uses the same merged times, so its StartTime header and interval timestamps change the same way for multi-thread runs. Tests: a unit test for the merge arithmetic (fails on master with negative times) and an RLTest that delays one client in the first thread and checks the merged duration includes it (master fails 10/10). Fixes #709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decision: a client that never connected still counts in the final report for what it did record (connection errors, Ctrl+C), so the final
Connection Errorsmatches the liveN conn errorsline. Its timestamps stay out of the merged run times, as #350 intended. No defaults or output fields change. A run where no client connected reports 0 rates, as on master, not NaN.Problem
When the server is never reachable, the final report and the JSON show
Connection Errors: 0, although the live line counts every failed connect. If the run is stopped with Ctrl+C in that state, memtier printsInterrupted by user (Ctrl+C) after 0.0 secsand the JSON has"Interrupted": "false"(see #702 and its comment). When some clients connect and a lower-index one never does, that client's errors are also missing from the total.Root cause
A client's start time is set when its first connection is established (
handle_event()->process_first_request()->client::set_start_time()).client_group::merge_run_stats()skips every client with!has_started(), so that the client's zeroed start time is not averaged into the merged timestamps (#350). That skip also dropped the client's connection errors and itsm_interruptedflag. The Ctrl+C message averagesclient_group::get_duration_usec(), which skips the same clients, so it is 0.Fix
client_group::merge_run_stats()merges every client. The averaging counter advances only for clients that started.run_stats::merge()handles a run that never started separately. It adds only that run's connection error count, intom_cur_stats, and takes its interrupted flag, then returns.print()andaggregate_average()rebuild the totals from the per-second stats plusm_cur_statswithsummarize(), which is why the errors go intom_cur_statsand notm_totals. The run's timestamps and per-second buckets are not merged: with a zero start time those buckets are keyed from the epoch.totals_cmd::summarize()(also used for arbitrary commands) returns 0 rates when the duration is 0. When no client starts,print()now reachessummarize()with a zero duration, and without this guard the Sets/Gets/Waits Ops/sec and KB/sec would be-nanin the text andnullin the JSON, including BEST/WORST with--run-count. The guard matches the existing ones for hits, misses and connection-error rates.benchmark_start_time.Behaviour notes
--clients-start, the staircase ramp. On a healthy run it matches master (3.5 s for a SIGINT at 3.5 s).Total duration(and Start/Finish time) stays 0 for a run where no client ever connected. There is no start time to report.Totals/Connection Errorsincludes the errors of never-started clients, but they do not appear in any per-secondTime-Serieentry, because there is no start time to place them. The per-second entries have no connection-error field anyway.Overlap with other PRs
shard_connection.cppand addsclient::set_end_time_at(). This PR touches none of that. Its tests are inserted in the middle oftests/test_reconnections.py, not at the end where End a --test-time run at its deadline while reconnecting to a dead server #666 adds its tests.fprintfto name the signal. This PR is rebased onto it and keeps both: Handle SIGTERM like Ctrl+C so --json-out-file stays valid #706'sinterrupt_source()label and this PR's wall time sincebenchmark_start_time.Tests
Three tests in
tests/test_reconnections.py, standalone, plain TCP and TLS. All count connection errors from theattempting reconnection/Maximum reconnection attemptslines:attempt_reconnect()logs exactly one of them for each error it counts, on every transport. TheConnection error:line isTLS connection error:over TLS and is missing when errno is 0.test_connection_errors_reported_when_server_never_reachable: refused port,-c 2,--max-reconnect-attempts=2.Connection Errors≤ 2 × (1 + 2).0.0.configuration, and every Time-Serie second is ≤ 31.test_ctrl_c_reported_when_server_never_reachable: SIGINT after 3 s.Interruptedis"true".test_connection_errors_reported_when_only_a_later_client_connects(mixed case).--test-time=8, so client 0's last dial at 6 s happens before the deadline, also with End a --test-time run at its deadline while reconnecting to a dead server #666's reconnect deadline.Measured locally on RLTest's own standalone env (port 14110), plain and
--tls. Columns are the three tests in the order above:0 >= 5)after 0.0,0 >= 6)0 >= 3)None == 0.0rates, nulls)m_totals0 >= 3)3002 >= 5000, duration halved)10 <= 6)12 <= 8)6 <= 3, epoch-keyed Time-Serie)Each mutant was run on TCP and TLS, with the same result on both. The previous mixed-test schedule (
--test-time=5) fails on the #666 merge with2 >= 3. The 0905dcf tests fail over TLS with0 >= 3at line 718, as in CI. The rest oftests/test_reconnections.pypasses, excepttest_reconnect_on_connection_kill, which fails the same way on master underexisting-env(ExistsRedisEnvhas nodbDirPath).Affected versions
2.3.0 through 2.5.2 (latest) and master.
has_started()skip inmerge_run_stats()andget_duration_usec()came from 0228bac "Add client staircase ramp-up for incremental connection growth" (Add client staircase ramp-up for incremental connection growth #350).Connection Errorscounter came from 7ae9f65 (Connection Error Tracking & Auto-Reconnect #320), and the Ctrl+C message and interrupted flag from aa9edb8 (Signal Handling with Graceful Shutdown with metrics #325).git tag --contains).Fixes #702
🤖 Generated with Claude Code
Note
Medium Risk
Changes how run stats are merged and summarized on failure/interrupt paths; behavior is narrow but affects final JSON/text reporting when connections never succeed.
Overview
Fixes #702: final reports and JSON no longer drop connection errors and interrupted state from clients that never established a connection, while still excluding their zero timestamps from merged run duration.
client_group::merge_run_stats()now merges every client; only clients thathas_started()advance the factorial-averaging iteration counter.run_stats::merge()treats never-started peers separately: it folds their connection errors intom_cur_stats, propagatesm_interrupted, and skips timestamp/per-second bucket merge (avoids epoch-keyed time series and corrupted durations).On Ctrl+C, the “after N secs” line uses wall time since
benchmark_start_timeinstead of averaged client durations (which stay 0 until connect).totals_cmd::summarize()reports 0 ops/KB rates when duration is 0 so text/JSON avoid NaN/null when no client ever connected.Adds three reconnection integration tests (unreachable server, SIGINT before connect, mixed staircase + refused client).
Reviewed by Cursor Bugbot for commit f267365. Bugbot is set up for automated code reviews on this repo. Configure here.