Skip to content

merkle: let the thread joining the update run queued shard tasks - #987

Open
citizen-stig wants to merge 1 commit into
thrumdev:masterfrom
citizen-stig:nikolai/merkle-caller-runs-tasks
Open

citizen-stig wants to merge 1 commit into
thrumdev:masterfrom
citizen-stig:nikolai/merkle-caller-runs-tasks

Conversation

@citizen-stig

@citizen-stig citizen-stig commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

Updater::update puts the merkle update tasks (one per page-cache shard) in a shared queue. The commit_concurrency pool workers and the thread that calls UpdateHandle::join all take tasks from it until it is empty.

Why

After #978 there are 64 shard tasks. The thread calling Session::finish used to block in join while the pool worked through them. Now it runs tasks too, so finish gets one more worker without adding a thread.

Benchmarks

finish_bench mean finish over 8 interleaved runs. Master 6ee36d3 is run at commit_concurrency N and N+1, this PR at N:

CPUs master @n master @n+1 this PR @n vs master @n vs master @n+1
12 pinned (6 cores), N=6 95.14 ± 0.81 ms 88.28 ± 0.57 ms 88.24 ± 0.59 ms −7.3% equal
all 16 (8 cores), N=8 76.24 ± 0.51 ms 72.56 ± 0.69 ms 70.64 ± 0.48 ms −7.3% −2.6%
all 16 (8 cores), N=12 64.23 ± 0.35 ms 62.32 ± 0.37 ms 60.88 ± 0.54 ms −5.2% −2.3%

into_overlay is unchanged in every configuration (53–55 ms).

Is this just commit_concurrency + 1?

Since #978, master sends 64 shard tasks to a commit_concurrency-thread pool, and the pool's queue already balances them across its threads. This PR adds one more consumer: the thread calling join, which would otherwise sleep in recv. Raising commit_concurrency by one also gives N+1 consumers, but it adds an OS thread.

  • With spare cores (N=6 on 6 pinned cores with SMT), the two are the same: 88.24 vs 88.28 ms.
  • Once the pool fills the machine's cores (N=8 on 8 cores) or goes past them (N=12), this PR beats N+1 by 1.4–1.9 ms, about 3 standard deviations.

So the change is worth keeping where a node already sets commit_concurrency to the core count or higher. With spare cores, raising commit_concurrency by one gets the same result. Also, finish keeps scaling past 6 workers on this machine: master goes from 95 ms at 6 to 62 ms at 13.

finish_bench: an isolated Session::finish benchmark with the user-namespace access profile of a Sovereign SDK node (benchtop/src/bin/finish_bench.rs @ 3469d5c, not part of this PR; a bench-only env var sets commit_concurrency). 50k–145k ReadThenWrite accesses per slot (68% updates with the prior value, 32% inserts), 36-byte values, BinaryHasher<Sha256>, rollback on, tree growing from 5.35M leaves, 10 warm-up + 20 measured slots from a restored seed DB. AMD Ryzen 7 7700 (8 cores, 16 threads). "12 pinned" is taskset -c 2-7,10-15; "all 16" is taskset -c 0-15. All 9 configurations ran in one batch, with order rotated each round. Every run ends at the same root.

🤖 Generated with Claude Code

The commit_concurrency workers and the thread waiting in UpdateHandle::join take shard
tasks from a shared queue, so the caller works instead of idling once its own part of
Session::finish is done. No threads are added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants