kvserver/mmaprototype: add BenchmarkRebalanceStores#165284
Merged
trunk-io[bot] merged 6 commits intocockroachdb:masterfrom Mar 16, 2026
Merged
kvserver/mmaprototype: add BenchmarkRebalanceStores#165284trunk-io[bot] merged 6 commits intocockroachdb:masterfrom
trunk-io[bot] merged 6 commits intocockroachdb:masterfrom
Conversation
Contributor
|
😎 Merged successfully - details. |
Member
f7acd25 to
6e2a60c
Compare
tbg
commented
Mar 10, 2026
tbg
commented
Mar 10, 2026
tbg
commented
Mar 10, 2026
tbg
commented
Mar 10, 2026
tbg
commented
Mar 10, 2026
tbg
commented
Mar 10, 2026
82751c0 to
d04dfb1
Compare
tbg
commented
Mar 10, 2026
pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores.go
Outdated
Show resolved
Hide resolved
e0be4b8 to
a95dd61
Compare
angeladietz
approved these changes
Mar 11, 2026
Contributor
angeladietz
left a comment
There was a problem hiding this comment.
some nits but lgtm overall, nothing blocking!
I'm also curious how you attributed the number of allocs to each line (commit 2). was it just with pprof (& your agent)?
pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores_bench_test.go
Show resolved
Hide resolved
pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores.go
Outdated
Show resolved
Hide resolved
pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores_bench_test.go
Show resolved
Hide resolved
c61112c to
6f8b7ec
Compare
tbg
commented
Mar 16, 2026
Member
Author
tbg
left a comment
There was a problem hiding this comment.
Yes I told the agent to run the benchmark with memprofile and to top50 the output by allocation count, then iterated.
@tbg partially reviewed 10 files and all commit messages, made 3 comments, resolved 5 discussions, and dismissed @angeladietz from a discussion.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on angeladietz).
pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores_bench_test.go
Show resolved
Hide resolved
pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores.go
Outdated
Show resolved
Hide resolved
6f8b7ec to
11ee657
Compare
Add a microbenchmark for the MMA rebalance loop (rebalanceStores).
The benchmark uses the existing undoPendingChange production code to
reverse mutations after each iteration, plus targeted resets of leaked
fields (lastFailedChange, overload times, meansMemo cache).
Setup: 4 stores, 1000 ranges (100 hot, 900 cold), store 1 overloaded.
BenchmarkRebalanceStores 100 323k ns/op 102kB/op 2013 allocs/op
Epic: none
Release note: None
Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Add TODO(tbg) comments at each allocation site found via BenchmarkRebalanceStores memory profiling (4 stores, 1000 ranges, 100 hot). The allocs/op counts are from a 1000-iteration run. Epic: none Release note: None Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
The `formatCandidatesLog` closure and `redact.StringBuilder` were
allocated on every call to `sortTargetCandidateSetAndPick`, even when
verbose logging at level 2 was disabled. Additionally, the standalone
VEventf for discarded candidates boxed multiple arguments into
interfaces unconditionally.
Extract `formatCandidatesLog` to a package-level function and guard all
call sites (plus the standalone VEventf) with `log.ExpensiveLogEnabled`.
BenchmarkRebalanceStores 1999 -> 1689 allocs/op (-310)
Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
…bled
The top-K debug logging block in `processSheddingStore` builds a
`redact.StringBuilder` and formats `LoadVector` values for every range in
the top-K set on every call, even when verbose logging at level 2 is
disabled. Wrap the entire block with `log.ExpensiveLogEnabled`.
BenchmarkRebalanceStores 1689 -> 778 allocs/op (-911)
Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
…Enabled
The VEventf call logging lease-transfer candidates boxes `candsPL`
(a `storeSet`) to `interface{}`, triggering formatting even when verbose
logging at level 2 is disabled. Guard with `log.ExpensiveLogEnabled`.
BenchmarkRebalanceStores 778 -> 678 allocs/op (-100)
Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
11ee657 to
11e77a4
Compare
Reduce per-iteration allocations by pooling hot slices and maps via generic `slicePool[T]` and `mapPool[K, V]` wrappers around `sync.Pool`. These handle the `New` func, type assertion on `get`, and `clear`+reset on `put`. Five pools are introduced: - `storeAndLeasePreferencePool`, `storeIDPool`, `candidateInfoPool` for slices - `nodeLoadMapPool`, `storeIDStructMapPool` for maps The `rebalanceEnv.scratch` struct (which had aliasing hazards) is removed in favor of these pools. `candidatesToMoveLease` now accepts a reusable buffer. 678 → 160 allocs/op. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
50bbd59 to
f9fc017
Compare
Member
Author
|
/trunk merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce per-iteration allocations in the MMA rebalance loop from ~2000 to ~160
allocs/op, primarily by guarding expensive logging and pooling hot slices/maps.
Commit arc
Add BenchmarkRebalanceStores — microbenchmark for the rebalance loop
(4 stores, 1000 ranges, 100 hot). Uses
undoPendingChangeto restore statebetween iterations. Baseline: 2013 allocs/op.
Annotate top allocation sites — TODO comments at each site found via
memory profiling, guiding the subsequent commits.
Guard logging in sortTargetCandidateSetAndPick — extract
formatCandidatesLogto a package-level function with an internalExpensiveLogEnabledcheck, removing redundant guards at all 6 call sites.2013 → 1689 allocs/op.
Guard top-K debug logging — wrap the
redact.StringBuilder+LoadVectorformatting block withExpensiveLogEnabled.1689 → 778 allocs/op.
Guard lease-transfer candidate logging — prevent boxing
candsPLintointerface{}when verbose logging is off. 778 → 678 allocs/op.Pool slice and map allocations in rebalance loop — introduce generic
slicePool[T]andmapPool[K, V]wrappers aroundsync.Pool, replacingmanual pool boilerplate and the
rebalanceEnv.scratchstruct (which hadaliasing hazards). Five pools cover slices (
storeAndLeasePreference,StoreID,candidateInfo) and maps (NodeID→*NodeLoad,StoreID→struct{}).candidatesToMoveLeaseaccepts a reusable buffer.678 → 160 allocs/op.
Epic: CRDB-55052