Repository navigation
perf(node): de-globalize the lane store working set (#1792 item 1) - #1876
Merged
Merged
Conversation
The `PersistentPoolStateStore` held its entire in-memory lane working set behind one `Mutex<LaneBuffer>`, so every `record` on the paid-delivery hot path serialised against every other lane's `record` and against settlement's `load_all`/`get`. At scale this single lock is the serve path's contention point. Replace the mutex-guarded `HashMap` with a sharded `DashMap<LaneKey, LaneSlot>` plus a lock-free `crossbeam_queue::SegQueue<LaneKey>` dirty work-list. A `record` now takes only its own lane's shard lock — no lane serialises on another, and `load_all`/`get` no longer contend with a `record`. `LaneState` is heap-free, so a slot clones out with a memcpy; the `Live`/`Tombstoned` slot enum keeps a `forget`/`record` race decidable under the entry's shard lock, the role the buffer mutex played for the whole map. `flush` drains the work-list into a dedup set, clones each slot out under its shard lock (releasing before the postcard encode), and commits the fsynced batch with no shard lock held — same double-buffered shape as before. A `record` landing after its key is drained re-pushes the key and is captured next flush, so the durable watermark still lags by at most one flush interval (ADR 003 §Off-chain voucher state persistence). On commit failure the drained keys re-push; on success tombstoned slots are reaped with a guarded `remove_if` so a concurrent resurrecting `record` keeps its slot. All `PoolStateStore` trait signatures are unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013MSiZrVoUQzy4J5Ci8RGEu
There was a problem hiding this comment.
Pull request overview
This PR removes a global mutex bottleneck in the node’s persistent lane-state store by replacing the single in-memory HashMap+Mutex working set with a sharded concurrent map and a lock-free dirty work queue, reducing cross-lane contention on the paid delivery path.
Changes:
- Replaces the mutex-guarded lane working set with
DashMap<LaneKey, LaneSlot>and models deletions via tombstoned slots. - Switches dirty tracking from shared
HashSetmarks to a drained/dedupedcrossbeam_queue::SegQueue<LaneKey>work-list. - Adds
crossbeam-queueas a workspace dependency and wires it into the node crate.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/node/src/channel_store.rs | Reworks the lane-state store working set to use DashMap + tombstoned slots and a lock-free dirty queue; updates flush snapshot logic accordingly. |
| crates/node/Cargo.toml | Adds the crossbeam-queue dependency for the dirty work-list. |
| Cargo.toml | Adds crossbeam-queue = "0.3" to workspace dependencies. |
| Cargo.lock | Records the new crossbeam-queue package and associated lockfile updates. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…e empty-slot comment Two review findings on the de-globalized lane store: - `flush` drains the dirty work-list before encoding. If `postcard` encoding of a lane fails, the early return left the already-drained keys out of the queue, so those lanes went permanently "clean" without ever being committed. Re-push every drained key on the encode-error path, the same retry guarantee the commit-failure path already gives. - The "cannot happen" comment on the empty-slot arm was wrong. A drained key can resolve to no slot: a `forget` re-pushes the key after a flush reaps its tombstone via `remove_if`. Skipping is correct (the row is already gone); the comment now describes that path. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013MSiZrVoUQzy4J5Ci8RGEu
Coverage reportTotal: 82.12% (was 82.11%, ▲ +0.01%) — 68327/83207 lines
History
|
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
Item 1 (the headline) of the #1792 serve-path hot-path audit: the lane-state store's in-memory working set no longer sits behind one global mutex.
PersistentPoolStateStoreheld its entire lane working set behind a singleMutex<LaneBuffer>. Everyrecordon the paid-delivery path serialised against every other lane'srecordand against settlement'sload_all/get. That one lock is the serve path's contention point at scale.This PR replaces the mutex-guarded
HashMapwith:DashMap<LaneKey, LaneSlot>working set — arecordtakes only its own lane's shard lock, so no lane serialises on another andload_all/getno longer contend withrecord;crossbeam_queue::SegQueue<LaneKey>dirty work-list —record/forget/set_registered_untilpush a key;flushdrains it.A
LaneSlotisLive(LaneState)orTombstoned.LaneStateis heap-free, so aLiveslot clones out with a memcpy on the read path (boxing it would trade that for a heap indirection on the frequent variant, soLivestays inline under a justifiedlarge_enum_variantallow). The slot enum keeps aforget/recordrace decidable under the entry's shard lock — the role the buffer mutex played for the whole map.Flush semantics (unchanged shape)
flushdrains the work-list into a dedupHashSet, clones each slot out under its shard lock (releasing before the postcard encode), and commits the fsynced batch with no shard lock held — the same double-buffered design as before, so a concurrentrecordnever waits on disk I/O. Arecordthat lands after its key is drained re-pushes the key and is captured by the next flush, so the durable watermark still lags by at most one flush interval (ADR 003 §Off-chain voucher state persistence). On commit failure the drained keys re-push; on success tombstoned slots are reaped with a guardedremove_if, so a concurrent resurrectingrecordkeeps its slot and its fresh dirty mark.All
PoolStateStoretrait signatures are unchanged — this is an internal de-globalization, no call-site churn.Validation
cargo build -p decdn-node✅cargo clippy -p decdn-node --all-targets✅cargo test -p decdn-node --lib(771 tests, incl. all 30channel_storetests — concurrency + leaf-page packing) ✅cargo test -p decdn-node --test client_loopback(111 tests, full paid serve path) ✅cargo fmt --check✅RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items✅crossbeam-queue 0.3isMIT OR Apache-2.0Generated by Claude Code