Skip to content

perf: multi-core scaling baseline + empirical bottleneck (per-page pin on hot pages) - #16

Merged
gburd merged 1 commit into
masterfrom
perf/scaling-baseline
Jun 16, 2026
Merged

perf: multi-core scaling baseline + empirical bottleneck (per-page pin on hot pages)#16
gburd merged 1 commit into
masterfrom
perf/scaling-baseline

Conversation

@gburd

@gburd gburd commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

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). perf self-time: 66.7% in the kernel futex, __db_pthread_mutex_lock 35%, __memp_fget/__memp_fput 26%/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.

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
gburd merged commit 5245fe8 into master Jun 16, 2026
36 of 39 checks passed
@gburd
gburd deleted the perf/scaling-baseline branch June 16, 2026 18:15
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)
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.

1 participant