Skip to content

feat(miss-tracking): hit/miss ratio columns and miss-rate warnings for arbitrary/monitor commands - #398

Merged
fcostaoliveira merged 5 commits into
redis:masterfrom
filipecosta90:feat/miss-tracking
May 29, 2026
Merged

fcostaoliveira merged 5 commits into
redis:masterfrom
filipecosta90:feat/miss-tracking

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Hit/Miss columns in text stats table — Hits/sec and Misses/sec columns now appear for --command and --monitor-input modes. Previously suppressed for arbitrary commands.
  • Fix MONITOR_RANDOM stats-only slots — spec / miss_tracking_enabled now populated at creation time (direct command_meta::lookup()) so runtime update_arbitrary_op_misses() fires correctly for __monitor_line@__ mode.
  • Fix JSON Totals Hits/sec — in arbitrary-command runs the JSON Totals row now sums m_arbitrary_misses instead of the always-zero GET-cmd counters, making JSON and text-table Totals consistent.
  • Fix aggregate_average() for --run-count > 1 — accumulate and average m_arbitrary_misses across runs so AVERAGE reports show correct Hits/sec / Misses/sec.
  • --miss-rate-threshold=PERCENTAGE (default 1%) — warns to stderr after each run when any command type's miss rate exceeds the threshold. Zero is a valid value; NaN and empty strings are rejected.
  • Startup warning for --monitor-input without --command — warns that the monitor file will be ignored.
  • Command meta: startup log gated behind --debug.
  • reply_shape_name() helper added to command_meta.h.

Test plan

  • --command "GET __key__" → Hits/sec and Misses/sec appear in text table
  • --command "__monitor_line@__" → Hits/sec non-zero for GET-shaped commands
  • JSON Totals.Hits/sec matches text table Totals row
  • --run-count 3 → AVERAGE Hits/sec is plausible
  • --miss-rate-threshold=0 → warnings fire for any miss
  • --monitor-input file without --command → startup warning emitted
  • --debug --command "GET __key__" → Command meta: GET appears
  • --miss-rate-threshold=nan / --miss-rate-threshold= are rejected

🤖 Generated with Claude Code


Note

Low Risk
Changes are limited to benchmark stats aggregation, CLI options, and stderr warnings; no auth, persistence, or server protocol changes.

Overview
This PR improves hit/miss reporting for --command and --monitor-input workloads and adds configurable miss-rate warnings.

Reporting: Text tables now show Hits/sec and Misses/sec for arbitrary commands (not only classic SET/GET). JSON Totals hit/miss rates are derived from m_arbitrary_misses so they match the text table. With --run-count > 1, aggregate_average() sums arbitrary hit/miss counts and uses a summed duration so AVERAGE rows show correct rates (and per-key miss JSON stays populated).

Monitor mode: Stats-only slots created for __monitor_line@__ / MONITOR_RANDOM get command_meta::lookup() and miss_tracking_enabled from reply shape so monitor-driven GETs actually accrue hits/misses.

CLI: New --miss-rate-threshold=PERCENTAGE (default 1%, 0 warns on any miss; invalid/empty/NaN/out-of-range rejected). Stderr warnings when a command type (or GET totals) exceeds the threshold. Warning if --monitor-input is set without --command. --debug logs resolved reply_shape / miss tracking per command type; reply_shape_name() added in command_meta.h.

Tests: New tests/test_miss_rate_tracking.py covers columns, JSON totals, monitor random, multi-run average, threshold warnings, and CLI validation.

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

…s for arbitrary/monitor commands

- Extend print_hits_sec_column / print_missess_sec_column to emit per-command
  Hits/sec and Misses/sec rows in the text stats table when running with --command
  or --monitor-input (previously those columns were silently suppressed).
- Fix MONITOR_RANDOM stats-only slots: populate spec and miss_tracking_enabled at
  creation time (resolve_command_meta returns early for empty argv), so runtime
  hit/miss accounting fires correctly for __monitor_line@__ mode.
- Fix JSON Totals Hits/sec: in arbitrary-command runs the Totals row now sums
  m_arbitrary_misses instead of the always-zero GET-cmd counters.
- Fix aggregate_average() to accumulate and average m_arbitrary_misses so
  --run-count > 1 AVERAGE reports show correct Hits/sec.
- Fix --miss-rate-threshold=0 sentinel collision: initialise to -1.0 and check
  < 0 in config_init_defaults; add endptr == optarg and std::isfinite validation.
- Add --miss-rate-threshold=PERCENTAGE CLI option (default 1%): emits a per-run
  warning to stderr when any command type exceeds the threshold.
- Add startup warning when --monitor-input is given without --command.
- Gate Command meta startup log behind --debug to reduce normal-run noise.
- Add reply_shape_name() inline helper in command_meta.h.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Comment thread run_stats.cpp Resolved
… non-zero

aggregate_average() accumulated m_arbitrary_misses counts but never set
m_start_time / m_end_time on the AVERAGE run_stats object. ts_diff then
returned 0, the test_duration_usec > 0 guard failed in print_hits_sec_column
and print_json, and Hits/sec / Misses/sec displayed as 0.0 in every AVERAGE
report for arbitrary-command mode.

Fix: accumulate the per-run duration inside the loop and stamp a synthetic
m_end_time equal to the average run duration so rate calculations are correct.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
fcostaoliveira added a commit that referenced this pull request May 28, 2026
Reverts commits 6ef3821 and 0010c1f that were pushed directly to master
instead of going through the pull-request workflow.  The same changes land
via PR #398 (filipecosta90:feat/miss-tracking).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…s-rate threshold

Adds tests/test_miss_rate_tracking.py covering:
- Hits/sec and Misses/sec columns present in text output for --command GET
- JSON Gets.Hits/sec is non-zero with preloaded keys
- JSON Totals.Hits/sec is non-zero and consistent with per-type rows
- __monitor_line@__ (MONITOR_RANDOM) Hits/sec is non-negative in JSON
- --run-count > 1 AVERAGE report carries non-zero Hits/sec
- --miss-rate-threshold warning fires when miss rate exceeds threshold
- --miss-rate-threshold=0 fires for any miss
- --miss-rate-threshold suppressed when all keys exist (100% hit rate)
- --monitor-input without --command emits a startup warning
- --miss-rate-threshold rejects empty string, NaN, and out-of-range values

All 12 tests pass locally against OSS standalone.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 0c4af20. Configure here.

Comment thread run_stats.cpp Resolved
fcostaoliveira and others added 2 commits May 28, 2026 16:54
Code review (7 reviewers) surfaced two dead tests and several correctness items:

Tests (were passing vacuously):
- test_run_count_average_hits_sec_nonzero queried the wrong JSON key
  ("AVERAGE RESULTS" vs the real "AGGREGATED AVERAGE RESULTS (N runs)"), so it
  always hit the graceful-skip and never exercised the aggregate_average fix.
  Now locates the section dynamically and asserts Hits/sec and Misses/sec > 0.
- test_monitor_random_hits_sec_nonzero asserted only >= 0 (always true) despite
  its name; now asserts > 0 for both Gets and Totals so a dead MONITOR_RANDOM
  path would fail the test.
- test_hits_misses_columns_in_text_output now parses the Gets row numerically
  and asserts text-vs-JSON Hits/sec / Misses/sec parity.

run_stats.cpp:
- print_hits_sec_column / print_missess_sec_column per-line loops now iterate
  m_ar_commands.size() (same bound as the other columns) and guard
  m_arbitrary_misses access, so the table can't misalign if the vectors diverge.
- aggregate_average now accumulates and averages per-key buckets too, so the
  AGGREGATED AVERAGE report's "Per-Key Misses" JSON section is populated like
  the BEST/WORST runs.
- print_json Totals skips the MONITOR_RANDOM placeholder slot to mirror the
  text/aggregated Totals path exactly.

memtier_benchmark.cpp:
- --miss-rate-threshold help text now documents that 0 warns on any miss.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… counts

Cursor Bugbot (Medium) flagged that dividing the unsigned m_arbitrary_misses
counts by the run count uses integer division, truncating toward zero. For
short or low-request runs this skews AVERAGE Hits/sec / Misses/sec and can zero
out a small miss count, silently suppressing the miss-rate warning.

Fix: keep the SUMMED counts and set the synthetic duration to the SUMMED run
duration instead of the per-run average. The rate the print paths compute,
count / ts_diff(start, end), is then the exact time-weighted average
Σhits / Σduration — mathematically equal to dividing both by N but with no
truncation. Per-key buckets are likewise left summed (the JSON "Per-Key Misses"
section reports cumulative Total Hits/Misses across runs).

(Bugbot also re-raised the High "AVERAGE shows zero Hits/sec" item; that is a
false positive — the synthetic-duration block is present and the run-count
integration test asserts AVERAGE Hits/sec > 0.)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Addressed the latest Cursor Bugbot review (commit d111e0f):

  • Medium — "Integer division truncates averaged hit/miss counts": fixed. aggregate_average() no longer divides the unsigned counts by N. Instead it keeps the summed counts and sets the synthetic duration to the summed run duration, so the rate Σhits / Σduration is the exact time-weighted average with no truncation. This also removes the edge case where a small miss count could truncate to 0 and suppress the miss-rate warning.
  • High — "AVERAGE report shows zero Hits/sec and Misses/sec": false positive. The synthetic-duration block that sets m_start_time/m_end_time is present in aggregate_average() (it just sits below the line the bot flagged). The integration test test_run_count_average_hits_sec_nonzero runs with --run-count=2 and asserts the AGGREGATED AVERAGE RESULTS section reports Hits/sec > 0 and Misses/sec > 0, which passes.

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.

2 participants