[wip/DO NOT MERGE ] db/state: lock-free DomainMetrics + kv_get (atomics)#21722
Draft
sudeepdino008 wants to merge 1 commit into
Draft
[wip/DO NOT MERGE ] db/state: lock-free DomainMetrics + kv_get (atomics)#21722sudeepdino008 wants to merge 1 commit into
sudeepdino008 wants to merge 1 commit into
Conversation
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.
What was tracked
KV_READ_METRICS=trueemits the[Execution] domain readslog line. Setup: mainnet,--prune.mode=minimal, at chaintip,TIP_TRIE_WARMUPERS=256,--exec.state-cache=false, mutex profile viaPERF_PROFILES=true.Finding: the durations were measuring the instrumentation's own lock contention
The tip warmup pool (
TIP_TRIE_WARMUPERS, defaultNumCPU*8) is 128 goroutines that all read the commitment domain concurrently during commitment calc. They serialize on the metric-recording locks (changeset.DomainMetricsmutex + the per-(domain,level)kv_getprometheusSummarymutex). The critical section is tiny, but at N-way fan-in the contended-mutex handoff (~1µs, futex park/unpark) dominates, and since the metric is wall-clock that wait is folded into the reporteddbdur/fdurthemselves.Signature:
fdurscales linearly with warmuper count — ≈ 0.9µs × N (16→26µs, 64→62µs, 128→115µs, 256→223µs) — i.e. N goroutines serializing on one lock, not storage cost. Throughput (~85–89 mgas/s) is identical across all configs.This branch makes both recording paths lock-free (atomics + fixed
[DomainLen]array; lock-freekv_getaccumulator).Aggregate (chaintip, W=256)
warmupKeymutex sharesummary.ObserveDuration)EVM-exec vs commitment-calc split (per-domain)
The contention was entirely in the commitment regime (the only place warmupers run). Removing the metric locks collapses it to parity with the execution domains:
(dbdur / fdur, medians.) EVM-exec domains were never contended (no warmupers there); their
dbduris flat,fduronly wobbles with per-block cache warmth.Relationship to #21663
#21663 removes the
DomainMetricscollection lock (channel/actor) and adds source labels + RPC coverage — the superset there. It does not touch the per-levelkv_getSummarylock ingetLatestFromFile; this branch makes that lock-free too (atomics). TheDomainMetricspart overlaps — #21663 is the one to merge.Next contention source:
BranchCache(mh0lt's perf stack)The perf stack (#21380 / #21386) introduces
commitment.BranchCache, whose LRU tail wrapshashicorp/golang-lru/v2— a single exclusive mutex (evenGetlocks, to bump recency). Profiling #21663 at chaintip, the 256 warmupers serialize there:BranchCache.Get+Put≈ 72% of mutex delay (320s total); bypassing that lock just relocates them back onto thekv_getSummary. So the warmup read path has three serialized locks —DomainMetrics,kv_getSummary,BranchCache— and the pool only runs free with all three lock-free/sharded.BranchCacheis not in main (so this branch can't address it) — flagging it for the stack: none of the stacked PRs (#21380/#21386 introduce it; #21414/#21416/#20893 don't touch it, including the parallel-commitment PR) shard the LRU tail.