Support higher performance histogram - #3561
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 5
Open (9)
The PR description fields look incomplete/placeholder (e.g., 'Issue Number: resolve', empty… · New This PR removesPassiveStatus::reset()(which previously CHECK+abort'ed). That changes the public… · Newelapsed_nsis stored inlong, which can be 32-bit on some platforms and may overflow for… · Newtotal_nsuseslongand accumulates per-thread elapsed nanoseconds; on 32-bitlongthis can… · New This adds a performance measurement as a regular unit test, with a fairly large workload… · New Correct spelling in comment: 'Suming' should be 'Summing'. · New Correct wording in comment: 'Inversed' should be 'Inverse' (e.g., 'Inverse operation'). · New The comment refers toPercentile, but this isHistogram. Please update the wording to avoid… · Newlast_countsis hard-coded to 4 buckets, which implicitly assumes the schema{10, 20, 30}… · New
What changed in this PR
This PR introduces a higher-performance Histogram backend (guarded by WITH_BABYLON_COUNTER) using thread-local slots, and adds/updates unit tests to validate correctness under concurrency and thread lifecycle behavior.
Changes:
- Add a babylon-backed histogram storage (
HistogramSlot/HistogramStorage) and routeHistogramrecording/snapshotting through it when enabled. - Optimize bucket lookup by switching
BucketSchema::index_offrom binary search to a linear scan for small bucket counts. - Add new concurrency-focused tests plus a write-performance measurement test; refactor
ReducerSamplerto use tag dispatch.
| File | Description |
|---|---|
| test/bvar_histogram_unittest.cpp | Adds tests for the new backend, contention/snapshot invariants, dead-thread behavior, and a write perf measurement. |
| src/bvar/passive_status.h | Adjusts virtual destructor and removes a reset() implementation that previously aborted. |
| src/bvar/histogram.h | Adds babylon-backed histogram storage types, switches bucket index lookup to linear scan, and updates combiner/storage plumbing. |
| src/bvar/histogram.cpp | Wires operator<< and get_value() to the selected backend. |
| src/bvar/detail/sampler.h | Refactors sampling logic to avoid instantiating both branches (tag dispatch). |
| BUILD.bazel | Adds babylon thread-local dependency when with_babylon_counter is enabled. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 2
Open (4)
This adds a heavy performance-style test (up to ~4M records plus threading) that will run… · New This adds a heavy performance-style test (up to ~4M records plus threading) that will run… · New For integral counters (_counts,_num), usingfetch_add(..., memory_order_relaxed)would more… · New The reported metric is the average of per-thread wall-clock times divided by ops, which is closer… · New
Resolved since last review (9)
This adds a performance measurement as a regular unit test, with a fairly large workload…total_nsuseslongand accumulates per-thread elapsed nanoseconds; on 32-bitlongthis can…elapsed_nsis stored inlong, which can be 32-bit on some platforms and may overflow for… This PR removesPassiveStatus::reset()(which previously CHECK+abort'ed). That changes the public… The PR description fields look incomplete/placeholder (e.g., 'Issue Number: resolve', empty…last_countsis hard-coded to 4 buckets, which implicitly assumes the schema{10, 20, 30}… The comment refers toPercentile, but this isHistogram. Please update the wording to avoid… Correct wording in comment: 'Inversed' should be 'Inverse' (e.g., 'Inverse operation'). Correct spelling in comment: 'Suming' should be 'Summing'.
|
LGTM |


What problem does this PR solve?
Issue Number: resolve
Problem Summary:
bvar::Histogramrecords throughdetail::AgentCombiner, the same thread-localaggregation every other reducer uses. Each
operator<<has to look the agent upin the thread-local
AgentGroupand then take the per-agentbutil::LockthatElementContainerwraps every read and write in. For a histogram that cost ispaid on a path that only ever increments one bucket, a sum and a count.
When bRPC is built with the babylon counter backend (
with_babylon_counter),Adder,IntRecorderandPercentilealready record through babylon'sthread-local storage, but
Histogramwas left on the combiner.What is changed and the side effects?
Changed:
Side effects:
write_perf, 500k records per thread, Linux x86_64, ns per record:Check List: