Skip to content

feat: --latency-window sliding-window tail latency for --realtime-latencies#386

Open
fcostaoliveira wants to merge 2 commits into
masterfrom
feat/latency-sliding-window
Open

feat: --latency-window sliding-window tail latency for --realtime-latencies#386
fcostaoliveira wants to merge 2 commits into
masterfrom
feat/latency-sliding-window

Conversation

@fcostaoliveira
Copy link
Copy Markdown
Collaborator

@fcostaoliveira fcostaoliveira commented May 18, 2026

Summary

Adds a load1/5/15-style sliding window to the live latency block under --realtime-latencies. The per-tick output now emits three labeled rows per configured percentile:

  • inst — last tick only
  • win<N>s — sliding window (default 60s, configurable via --latency-window=SECS, set to 0 to disable, max 3600)
  • overall — full run

Example with --latency-window=60 --print-percentiles=50,99,99.9:

[RUN #1 50%  2s] throughput 178,155 (avg: 172,043) ops/sec   …   miss 49.88% (avg: 49.87%)
[RUN #1 50%  2s] latency [inst    ]  p50 0.111  p99 0.223  p99.9 0.367
[RUN #1 50%  2s] latency [win60s  ]  p50 0.119  p99 0.239  p99.9 0.479
[RUN #1 50%  2s] latency [overall ]  p50 0.119  p99 0.239  p99.9 0.479 ms

Implementation

  • Ring buffer of cloned hdr_histogram snapshots, one per second (memtier_benchmark.cpp:2125-2143).
  • Per tick: clone inst_hist_agg into the next slot, freeing the displaced snapshot. O(W) per tick (microseconds for W ≤ 3600).
  • To render: hdr_reset a reused scratch histogram, hdr_add every live slot, then hdr_value_at_percentile.
  • Empty ticks still consume a slot, so the window measures wall-clock seconds, not "seconds with traffic".
  • Long --print-percentiles lists wrap to multiple lines per row with deterministic line count, so the TTY cursor-up redraw stays stable.

Memory / CPU

  • Each snapshot is one hdr_histogram (~tens of KB at default precision). Default 60s window ≈ 1-2 MB; capped at 3600s.
  • O(W) hdr_add per tick, once per second. Negligible.
  • No effect when --realtime-latencies is off or --latency-window=0.

Test plan

  • make format-check clean
  • Builds cleanly (release + --enable-sanitizers)
  • ASAN smoke run with deep-tail percentiles: exit 0, no leaks, no errors
  • RLTest test_realtime_latencies.py: 5/5 PASS (incl. 2 new tests: test_latency_window_zero_drops_window_row, test_latency_window_ring_smooths_spikes)
  • Existing --realtime-latencies tests updated for new label-row layout and still pass
  • --help and man page show --latency-window
  • bash-completion lists --latency-window under options_no_comp

🤖 Generated with Claude Code


Note

Medium Risk
Changes --realtime-latencies progress output format and adds a per-second histogram ring buffer, which could affect log parsers and introduce memory/CPU overhead if misconfigured (bounded to 3600s).

Overview
Adds a new --latency-window=SECS option that computes sliding-window tail latency for --realtime-latencies by keeping a ring of per-second HDR histogram snapshots (default 60s, 0 disables, max 3600).

Updates the live progress block to emit labeled latency rows per tick (always inst + overall, plus win<N>s when enabled) and adjusts TTY redraw/wrapping logic accordingly.

Wires the flag through CLI parsing/help/man page and bash completion, extends benchmark_config with latency_window_secs, and updates/adds RLTest coverage to validate the new rows, wrapping behavior, and the --latency-window=0 disable contract.

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

…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) <noreply@anthropic.com>
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 18, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ 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) <noreply@anthropic.com>
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.

1 participant