Skip to content

Support higher performance histogram - #3561

Merged
chenBright merged 2 commits into
apache:masterfrom
chenBright:histogram_seqlock
Sep 23, 2026
Merged

chenBright merged 2 commits into
apache:masterfrom
chenBright:histogram_seqlock

Conversation

@chenBright

@chenBright chenBright commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

bvar::Histogram records through detail::AgentCombiner, the same thread-local
aggregation every other reducer uses. Each operator<< has to look the agent up
in the thread-local AgentGroup and then take the per-agent butil::Lock that
ElementContainer wraps every read and write in. For a histogram that cost is
paid 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, IntRecorder and Percentile already record through babylon's
thread-local storage, but Histogram was left on the combiner.

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

write_perf, 500k records per thread, Linux x86_64, ns per record:

threads babylon AgentCombiner
1 6.91 23.40
2 6.98 23.37
4 6.97 24.32
8 7.62 24.32
  • Breaking backward compatibility:

Check List:

@chenBright
chenBright requested a lite review from Copilot September 22, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Medium severity · 4 Low severity

Open (9)
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 route Histogram recording/snapshotting through it when enabled.
  • Optimize bucket lookup by switching BucketSchema::index_of from binary search to a linear scan for small bucket counts.
  • Add new concurrency-focused tests plus a write-performance measurement test; refactor ReducerSampler to 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.

Comment thread BUILD.bazel
Comment thread src/bvar/passive_status.h
Comment thread test/bvar_histogram_unittest.cpp Outdated
Comment thread test/bvar_histogram_unittest.cpp Outdated
Comment thread test/bvar_histogram_unittest.cpp
Comment thread src/bvar/detail/sampler.h Outdated
Comment thread src/bvar/detail/sampler.h
Comment thread src/bvar/histogram.h Outdated
Comment thread test/bvar_histogram_unittest.cpp Outdated
@chenBright
chenBright requested a lite review from Copilot September 22, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Medium severity · 2 Low severity

Open (4)
Resolved since last review (9)

Comment thread test/bvar_histogram_unittest.cpp
Comment thread test/bvar_histogram_unittest.cpp
Comment thread src/bvar/histogram.h
Comment thread test/bvar_histogram_unittest.cpp
@wwbmmm

wwbmmm commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

LGTM

@chenBright
chenBright merged commit bc010e7 into apache:master Sep 23, 2026
44 of 46 checks passed
@chenBright
chenBright deleted the histogram_seqlock branch September 23, 2026 02:54
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.

3 participants