Repository navigation
Avoid histogram copies and batch latency percentile queries - #564
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the diff. Output stays the same: the table headers, column order,
There's one existing inconsistency the PR doesn't change: per-second history still uses the batch semantics, where p0 gives the upper equivalent value. The new live/final paths use the scalar ones. You call this out in the header comment, so it's fine for this stage. It may be worth a follow-up so the per-second JSON and the final summary can't disagree on p0. This looks solid to me. I'd only want the return-value question answered before it merges. (would file this as a comment, not a formal block) |
|
Addressed the review nits in cbf1211:
Paired TLS results and full raw evidence are now attached to the PR description: default throughput +0.013%, CPU/op −0.734%; realtime throughput +0.101%, CPU/op +0.256%. Throughput changes fall within the observed spread. These are local sanity measurements, not a portable performance claim. The initial macOS failures exposed missing configured OpenSSL includes in the expanded HDR unit-test target; it now inherits application CPPFLAGS. Four local unit programs, formatting, and TLS V2/JSON/table tests re-pass. CI is rerunning on this head. |
|
The follow-up plan now explicitly tracks p0/empty-history normalization before stages 3/4; the link and local TLS measurements are in the description and preceding reply. I kept the scratch-reuse test with the HDR compatibility tests so it calls the production Agreed on final reporting: the table retains one copied result vector per row. The description explicitly budgets that |
The scratch-reuse test compared a stored double against expected / 1000.0 exactly. x87 builds can keep the right-hand side at extended precision, so the i386 Debian packages' make check failed. Compare rounded microseconds. hdr_histogram_test now takes memtier_benchmark_CPPFLAGS, which include the coverage compile flags, so link CODE_COVERAGE_LIBS as well. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The table test ran pipelined, so Sets, Gets and Totals shared one latency distribution and a dropped or doubled totals merge went unnoticed. Run unpipelined with large SETs and missing-key GETs, query a dense unsorted percentile grid, check Totals against the merged decoded Sets and Gets histograms, cover arbitrary commands, and assert the header labels. Require the default latency_p* StatsD metrics, and cover non-finite percentiles in the batched/scalar compatibility unit test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --enable-code-coverage, make check failed to link socket_options_test, hdr_histogram_test and cluster_transaction_test with undefined __gcov_init, __gcov_merge_add and __gcov_exit. These tests compile with memtier_benchmark_CPPFLAGS, which carries the coverage flags, and two of them link the instrumented memtier_benchmark objects, but none links libgcov. The vendored AX_CODE_COVERAGE (serial 15) puts -lgcov in CODE_COVERAGE_LDFLAGS and never defines CODE_COVERAGE_LIBS. The $(CODE_COVERAGE_LIBS) in memtier_benchmark_LDADD, and the one #564 added to hdr_histogram_test_LDADD, therefore expand to nothing. Only the main binary got the runtime, through memtier_benchmark_LDFLAGS. That put -lgcov before the objects, so it also depended on libtool reordering the link line. Use $(CODE_COVERAGE_LDFLAGS) in both LDADD lists in place of the undefined variable. The tests that reuse memtier_benchmark_LDADD inherit it, memtier_benchmark_LDFLAGS is no longer needed, and -lgcov now follows the objects. Run make check in the coverage CI job so this can't regress. Fixes #595 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --enable-code-coverage, make check failed to link socket_options_test, hdr_histogram_test and cluster_transaction_test with undefined __gcov_init, __gcov_merge_add and __gcov_exit. These tests compile with memtier_benchmark_CPPFLAGS, which carries the coverage flags, and two of them link the instrumented memtier_benchmark objects, but none links libgcov. The vendored AX_CODE_COVERAGE (serial 15) puts -lgcov in CODE_COVERAGE_LDFLAGS and never defines CODE_COVERAGE_LIBS. The $(CODE_COVERAGE_LIBS) in memtier_benchmark_LDADD, and the one #564 added to hdr_histogram_test_LDADD, therefore expand to nothing. Only the main binary got the runtime, through memtier_benchmark_LDFLAGS. That put -lgcov before the objects, so it also depended on libtool reordering the link line. Use $(CODE_COVERAGE_LDFLAGS) in both LDADD lists in place of the undefined variable. The tests that reuse memtier_benchmark_LDADD inherit it, memtier_benchmark_LDFLAGS is no longer needed, and -lgcov now follows the objects. Run make check in the coverage CI job so this can't regress. Fixes #595 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Per-second latency summaries currently deep-copy a dense histogram and copy the percentile list for every client/command, then allocate temporary query results. Live display, StatsD, JSON, and the final table also repeat scalar percentile scans; the table rebuilds its totals histogram for every percentile column.
Pass summary inputs by const pointer/reference and reuse one scratch vector per client. Batch live and final queries in configured order, share instantaneous results between realtime display and StatsD, and merge the final table's total histogram once. JSON output also borrows its input vectors instead of copying them. The scalar-query adapter preserves p0, empty histograms, duplicate percentiles, and unsorted input; existing per-second history retains its previous batch-query semantics.
This is stage 2 of the HDR rolling-window plan, following merged #563. It adds no rolling window or sample-recording work.
Validation:
make checkprograms andmake format-checkpass on Linux ARM64 GCC 13.Component measurements (shared Linux ARM64 Colima VM on Apple M6,
-O3, five samples per case; 10 or 1,000 populated bins): summaries fall from 3.4–5.1 µs to 0.19–0.23 µs. Three/nine-percentile queries are 2.4–6.7× faster; a single-percentile query adds roughly 6–7 ns. These are component timings, not application throughput results or x86 AVX2 measurements.The summary path removes four temporary allocations per invocation after output-vector warmup, retaining
24 + 8*Qbytes per client for scratch on this 64-bit platform (48 bytes at the default three percentiles, excluding allocator overhead). Live queries retain approximately32*Qbytes per enabled query plus vector metadata; the final table temporarily caches8*rows*Qbytes of values. No histogram ring is allocated.Five paired, alternating-order TLS sanity runs per case (pipeline 16, 3 threads × 10 clients, 10 seconds each, fixed Redis per comparison, separate CPU affinity):
Throughput differences are within observed variation. These short shared-VM runs can be server-limited; they do not establish portable gains or statistical equivalence. Full measurements, ranges, memory costs and limitations · Raw samples, summaries and provenance.
Measured commit
6faecefand initial rebased headfeb0448have identical source trees. Follow-upcbf1211fixes macOS unit-test OpenSSL include paths and small final-table/test-review nits; local checks and TLS HDR/table tests re-pass. Full cross-platform CI is running on the draft.Note
Medium Risk
Touches latency reporting across live UI, StatsD, JSON, and final tables; behavior is intentionally preserved but regressions would affect published percentile metrics.
Overview
Introduces
latency_percentilesto query many configured percentiles in one HDR batch while keeping the old scalar behavior for p0, empty histograms, duplicate/unsorted lists, and non-finite inputs.Live path: realtime latency display and StatsD now compute instantaneous percentiles once per tick (shared scratch across ticks) and pass precomputed values into
statsd_publish_tickinstead of re-scanning the aggregated histogram.Reporting path: per-second
summarize_quantilestakes histograms by pointer and reuses onem_quantile_valuesscratch per client; final table output merges the totals histogram once and batches lookups across all percentile columns and command rows; JSON percentile output uses the same helper. Several APIs stop copying large vectors (const references).Build/test updates wire the new header into
hdr_histogram_test(plusrun_stats_types, OpenSSL/coverage flags) and add unit, integration, and StatsD coverage for batched vs scalar parity and table/JSON column order.Reviewed by Cursor Bugbot for commit 3926642. Bugbot is set up for automated code reviews on this repo. Configure here.