perf: multi-core scaling baseline + empirical bottleneck (per-page pin on hot pages) - #16
Merged
Conversation
lab/bench/scale_bench.c: T-thread sweep over a shared env (read-random, read-hot, write-random) that resets and reads BDB's mpool/lock/mutex wait counters per run to localize contention. docs/design/scaling-findings.md: measured on meh (24t, single socket). Read throughput peaks at ~8 threads then DECLINES; perf shows 66.7% in kernel futex + __db_pthread_mutex_lock + __memp_fget/fput + atomic inc/dec. Root cause: the per-page buffer-header mutex and reference-count on hot root/internal B-tree pages (touched by every op) -- not the lock partitions or mpool hash (≈0 wait). Data-driven priority: #2 latch-free buffer-header access (+#7 cache-line) for reads, #3 group commit for writes; #1 hash-shard/NUMA and #4 partitions rank lower on single-socket boxes.
gburd
added a commit
that referenced
this pull request
Jul 31, 2026
perf: multi-core scaling baseline + empirical bottleneck (per-page pin on hot pages)
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.
Empirical answer to what makes BDB slow down as cores increase, measured on
meh(24t, single socket) with a new harness (lab/bench/scale_bench.c).Finding: read-random throughput peaks at ~8 threads then declines (24t < 8t).
perfself-time: 66.7% in the kernel futex,__db_pthread_mutex_lock35%,__memp_fget/__memp_fput26%/22%,__atomic_inc/dec~43% combined. BDB's own wait counters (lockpart%,mpoolhash%, region waits) are ~0.Root cause: every B-tree search pins the root + internal pages via
__memp_fget, which takes that page's buffer-header mutex (pthread → futex) and bumps its atomic refcount. The root is fetched by every op on every thread → one mutex + one cache line serialize the whole workload.Contrasts: hot-key reads add lock-partition latch contention (page read locks;
lockpart%→37.5%); random writes are fsync-bound (~733 ops/s/thread) with heavy lock-region mutex contention.Data-driven priority: #2 latch-free buffer-header access (+#7 cache-line) is the top read-scaling fix; #3 group commit for writes. The mpool hash mutex and lock partitions are not contended here, and both test hosts are single-socket — so #1's hash-shard/NUMA work ranks lower until we have a multi-socket box. Full write-up in
docs/design/scaling-findings.md.