Repository navigation
Add --latency-window sliding-window tail latency and flag unresolved percentiles - #386
Conversation
…encies Adds a load1/5/15-style sliding window to the live latency block. The per-tick output now emits three labeled rows per configured percentile: inst — last tick win<N>s — sliding window (default 60s, configurable, 0 disables) overall — full run The window is implemented as a ring of cloned hdr_histograms (one per second); each tick we materialize the windowed percentile by hdr_add-ing every live slot into a reused scratch histogram. Empty ticks consume a slot so the window measures wall-clock seconds rather than seconds-with-traffic. Long --print-percentiles lists wrap to multiple lines per row with deterministic line count, preserving the TTY cursor-up redraw. Adds three RLTests: three-row layout assertion, --latency-window=0 suppression, and ring-populated sanity. Existing --realtime-latencies tests updated for the new label-row layout. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
The macOS openssl-1.0.2 / 1.1 CI jobs don't pick up -std=c++11 and parse 'vector<vector<string>>' as the >> shift operator, breaking those builds. Use a typedef so the closing token sequence never appears. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…20261024 # Conflicts: # bash-completion/memtier_benchmark # memtier_benchmark.cpp
…solved percentiles The window ring was filled from the live per-client second the main loop samples, which a client resets on its own boundary: samples between the last snapshot and the reset were lost (a short --requests run showed n=0 of 1000), and the 'overall' row had the same problem. Fold completed seconds for --realtime-latencies as well as Prometheus, drain them once per tick and share the drain between both, so the win and overall rows count every sample exactly once. Each row now shows its sample count n. A percentile p needs at least ceil(1/(1-p)) samples (1M for p99.9999); with fewer it is just the maximum, so it is marked '*'. When --requests or --rate-limiting bound the sample count, warn before the run about percentiles the run or the window can never resolve. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review. A human maintainer's review is still required before merge. Thanks for this. I went through the whole thing, and I think moving the
The core fix looks solid. I'd mainly like to hear your thoughts on splitting the backportable fix out, and on the output and warning compatibility, before this merges. (I'd post this as a comment, not a formal block.) |
…dow by time In cluster mode --rate-limiting applies to each endpoint connection, so the up-front bound used clients x threads and could warn falsely. Run the check from the cluster topology summary, once, with the same request-generating connection count as the aggregate rate line. Stamp each window slot with its tick time and merge only the last N seconds, so win<N>s stays a wall-clock window when the progress loop drifts. Move the 60 second default into config_init_defaults(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Pushed
Local: |
2ace4c9 called the check from cluster_client, which broke make check: the unit programs link cluster_client.o without memtier_benchmark.o. Publish the first topology's rate-limited connection count from cluster_client instead, and let the main loop warn once it is known, restarting the realtime frame so the TTY redraw does not overwrite the warning. Document that the window/overall rows wait for each client to complete its second, that the check uses the total sample count, and the percent form of the sample bound. Drop a stale comment and a redundant initialization. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A rate-limited connection is granted a burst of request_per_interval on connect, and the window merges the last N ticks of completed client seconds, which can span N + 1 seconds. Include both in the run and window bounds, so a percentile the warning says the window cannot resolve is always marked '*'. Snap 100/(100-p) to the significant digits that survive the binary rounding of p, so p99.999999 needs 1e8 samples rather than slightly more. Say an under-sampled percentile is not resolved instead of claiming it reports the maximum, which HDR rounding does not guarantee. Describe the inst row as each client's current second, widen the count column for 100M+ samples, start the cluster warning on a new line after single-line progress, and skip the unused realtime drain histogram when Prometheus provides one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the re-review. Answers for head
|
Follow-up to #386. percentile_min_samples() snaps 100/(100-p) to the intended value only when it lies within the error from parsing p as a double (half an ulp of 100, doubled for margin, amplified by 100/(100-p)); otherwise it rounds up, using an exact integer power-of-ten unit. p99.99991 now needs 1111112 samples (was 1111111) and p99.9999999999 needs 1e12 (was 999999999999). The realtime rows and the percentile warnings print p%.15g, so 12 nines no longer show as p100; the final table and JSON labels are unchanged. The --requests run warning drops "about", since that bound is exact. A comment notes that the cluster bound comes from the first topology (#825). Add test_percentile_sample_thresholds, which pins the thresholds against exact ceil(100/(100-p)), and assert that a rate-limited window run prints exactly one percentile warning, which catches a cluster run that also applies the pre-run check without the endpoint fan-out. Rename the window-row test, make the Python threshold helper exact, and fix the README example spacing and a split help string. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --cluster-mode --rate-limiting, the up-front percentile warning (#386) took its sample bound from the first committed topology only. Since #799 a run can start on a partial slot map, and when the map heals memtier opens more endpoint connections, each with its own rate limit. On a 3-primary cluster with one primary's slots restored 1 s into a 6 s run at 800 req/s, memtier warned that p99.99 "records at most about 9664" and "will not be resolved", then recorded 10187 samples and resolved it. The cluster client now publishes the largest rate-limited connection fan-out committed so far, written once per topology commit under the topology-summary mutex. The main thread's once-a-second check remembers what it said about each percentile, for the run and the window, and when the fan-out grows prints one header line and then either the warning again with the raised bound or a "may now be resolved" note. A --requests bound does not depend on connections and is not repeated. The progress-line newline is printed only when there is a warning. test_cluster_unowned_slots.py heals the fake cluster after memtier's first warnings and checks the exact update lines, the window '*' marks, and that a --requests warning is not repeated. Fixes #825 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Under
--realtime-latenciesthere is no way to see the tail latency of a recent interval. You get the last second (inst) or the whole run (overall), but not, say, the last 60 seconds' p99.9999. Nothing flags tail percentiles that don't have enough samples to mean anything either. p99.9999 needs 1,000,000 samples, so with fewer it is just the maximum, and a rate-limited run can make that permanent without anyone noticing.The existing
overallrow also loses samples (bug, since 2.4.0).Root cause (overall row)
The main loop builds
overallby adding up snapshots of each client's live, partial second (copy_inst_histogram). Each client resets that histogram on its own second boundary. Any samples recorded between the main loop's last snapshot and the client's reset are never counted. Two examples on master:--requestsrun finishes before any snapshot:overallshows nothing, although the JSON reports 1000 samples.test_progress_intervalpeer test counted 9 of 12 samples. The test comment already noted that a sample "can legitimately disappear".The first version of this PR filled its window ring from the same snapshots, so it had the same loss.
Fix
--latency-window=SECS(default 60,0disables, max 3600) adds awin<N>srow: the percentiles of every sample completed in the last N ticks.--realtime-latencies. The main loop drains it once per tick, and the one drain feeds Prometheus, the window ring and theoverallrow. Every sample is counted exactly once, and no per-client memory is added. Thewinandoverallrows laginstby up to one second.instand StatsD are unchanged.hdr_addand runs one batch percentile query, sowin60sstays accurate if the progress loop drifts (e.g. under sanitizers). Empty ticks still take a slot. The window is on by default (60 s) under--realtime-latencies;--latency-window=0disables it.n=(987, 12.3K, 1.23M; truncated, never rounded up).ceil(1/(1-p))samples is marked*(100 for p99, 1M for p99.9999).--requestsor--rate-limitingmean the run, or the window, can never reach that count. For example,--rate-limiting=100× 160 connections gives at most 960,000 samples per 60 s window, which is not enough for p99.9999. The run-level warning also covers the final results table, so it is printed with or without--realtime-latencies(e.g.-n 10 -c 1 -t 1warns for the default p99/p99.9). In cluster mode the rate limit applies per endpoint connection, so the check runs once, after topology discovery, using the same connection count as theRate limit: … aggregate targetline.--latency-windowwithout--realtime-latenciesgets a warning.Output change: the realtime latency lines move from
cur (avg: avg)pairs to labeled rows withn=.--realtime-latenciesis opt-in, and the default progress line is unchanged (test_default_progress_line_unchanged).Tests
test_latency_window_counts_every_sample_and_marks_unresolved: in a 1000-request run, the last frame'swin60sandoverallrows shown == JSON Totals Count == 1000. p99.9 (needs 1000) is not marked, p99.99 is, and the up-front warning names p99.99 only. On every frame, each value's marker must match its row's n.test_latency_window_warns_when_rate_limit_cannot_fill_it: the window warning fires exactly once with the per-endpoint bound (standalone and cluster), the run warning does not.test_latency_window_expires_old_seconds: a 1 s window drops expired seconds.test_progress_interval_keeps_latency_samples_from_hidden_ticksnow asserts the exactn=12.test_realtime_latencies.py8/8 andtest_progress_interval.py6/6 pass (standalone, authenticated).make format-checkis clean, and the build adds no new warnings.--latency-windowis added tocli_fuzz.py.Not in this PR (follow-ups): window percentiles in JSON, StatsD and Prometheus, and a simultaneous 30 s + 60 s window.
Affected versions
The
overallrow sample loss was introduced in fe53c28 (#379,--realtime-latencies) and is present in every release since: 2.4.0 through 2.5.2. The window and the sufficiency markers are new.🤖 Generated with Claude Code
Note
Medium Risk
Changes main-loop latency aggregation and realtime stderr format (opt-in), but corrects overall percentile data and adds bounded-run warnings; cluster percentile checks depend on late topology discovery.
Overview
--realtime-latenciesnow prints three labeled rows per tick—inst,win<N>s(new--latency-window, default 60s), andoverall—each withn=sample counts instead of side-by-sidecur (avg: avg)pairs. Percentiles with too few samples are marked*, and startup warnings flag unresolvable tails when--requestsor--rate-limitingcap throughput (cluster uses topology-derived connection fan-out).winandoverallare built from drained completed client seconds (same pending path as Prometheus), fixingoverallsample loss from live partial-second snapshots. A wall-clock histogram ring backs the sliding window; Prometheus and realtime share one drain per tick when both are active.Docs, man page, bash completion, and tests cover the new flag, row format, warnings, and exact sample accounting.
Reviewed by Cursor Bugbot for commit 2d66490. Bugbot is set up for automated code reviews on this repo. Configure here.