Repository navigation
perf(node,client-pull): unwedge and speed up the buyer/upstream pull leg (#1794) - #1881
Merged
Merged
Conversation
…leg (#1794) Group G of the serve-path hot-path audit. Five buyer-leg fixes, each the minimal safe form: 1. Bound the voucher send. `PoolLedger::issue`/`reanchor`/`meter` hold the per-lane issuance lock across the upstream send (needed for strict cumulative order), but the send had no deadline — a stalled upstream wedged voucher issuance for every concurrent pull on the lane forever, and no error ever fired so failover never triggered. Each send now runs under `VOUCHER_SEND_DEADLINE` (20s); a timeout errors like any ambiguous send (voucher stays armed, `settlement` settles high), releasing the lock and letting the pull leg fail over. 2. Recover the funding single-flight slots on poison instead of treating a panic as node-fatal. The node owns a single pool (`get_by_owner`), so the "per-pool keying" of the issue does not apply — but a poisoned open/topup slot previously wedged ALL funding node-wide. `join_or_spawn_{open,topup}` now recover the inner value (matching `SlotGuard`'s own Drop) and drop the dead `Result`. 3. Shard the reputation map into 16 independently-locked shards. A `score()` read on the ranking path and the periodic `evict()` sweep no longer serialize on one global `RwLock`; eviction walks shards one at a time. 4. Make `BuyerLedgers::get_or_seed` O(1) on the hot reuse path. The O(lanes) prune now runs only when a genuinely new lane is inserted, preserving the exact cardinality bound without scanning on every miss — and never dropping a still-held ledger whose in-memory watermark leads the persisted row. 5. Early-exit probe collection. `probe_and_rank` collects answers via `FuturesUnordered` and stops once `PROBE_EARLY_EXIT_CANDIDATES` (= `MAX_PROVIDER_ATTEMPTS`) blob-holding providers answer, instead of `join_all` pacing the round to the slowest/dead probe. `PROBE_TIMEOUT` stays the ceiling for sparse rounds. ADR 001 updated. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR addresses serve-path “buyer/upstream pull leg” latency and throughput by bounding previously unbounded waits and removing lock/contention hot spots in the cache-miss path (client-pull issuance, node funding, node selection probing, buyer ledger lookup, and reputation scoring).
Changes:
- Add a per-send voucher deadline in
decdn-client-pullto prevent lane-wide issuance wedges on stalled upstreams. - Reduce contention/latency on the node miss path via early-exit probe collection and an O(1) buyer-ledger reuse fast path.
- Shard local reputation storage to avoid global lock contention during ranking and periodic eviction, and update ADR 001 to reflect early-exit probe collection.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/client-pull/src/ledger.rs | Add VOUCHER_SEND_DEADLINE and enforce it around voucher sends; add timeout-focused test. |
| crates/node/src/buyer_channel.rs | Recover poisoned funding slots instead of treating them as node-fatal; simplify join-or-spawn APIs. |
| crates/reputation/src/local.rs | Replace single peer-map lock with SHARD_COUNT shards; update record/score/snapshot/evict accordingly. |
| crates/node/src/buyer_ledgers.rs | Make get_or_seed O(1) on reuse; run lane-pruning only on new-lane insertion. |
| crates/node/src/selection.rs | Introduce PROBE_EARLY_EXIT_CANDIDATES to govern early-exit probe collection behavior. |
| crates/node/src/node_origin/mod.rs | Collect probe responses via FuturesUnordered and early-exit once enough blob-holding candidates arrive. |
| adr/001-network.md | Document early-exit probe-response collection while keeping the 500ms ceiling as fallback. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Copilot review on #1881: use `.first()` instead of `as_bytes()[0]` in `shard_for` so the workspace `clippy::indexing_slicing` anti-panic lint has nothing to flag. Behaviour is identical (the key is always 32 bytes). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 82.29% (was 82.27%, ▲ +0.02%) — 69312/84224 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.
Closes #1794 (Group G of the serve-path hot-path audit). Five buyer-leg fixes, at the "all five, minimal depth" scope.
The buyer leg is what a cache miss waits on, so these are miss TTFB / miss-throughput fixes that scale with miss rate (highest while the network grows).
1. Bounded voucher send — the wedge (client-pull)
PoolLedger::issue/reanchor/meterhold the per-lane issuance lock across the upstream send (required for strict cumulative voucher order), but the send had no deadline. One stalled upstream froze voucher issuance for every concurrent pull on that(signer, provider)lane forever — and since nothing errored, per-blob failover never fired. Each send now runs underVOUCHER_SEND_DEADLINE(20s). A timeout is treated exactly like any ambiguous send (voucher stays armed,settlementsettles high,committedunmoved), which releases the lock and turns the wedge into an ordinary failover.2. Poison recovery on the funding slots (node)
The issue's "key single-flight by pool" premise is stale: the node owns exactly one pool (
store.get_by_owner), so there are no unrelated pools to serialize. The applicable half — a poisoned slot being node-wide fatal for paying anyone — is fixed:join_or_spawn_{open,topup}now recover the inner value on poison (matchingSlotGuard's ownDrop) instead of returning a fatal error, and shed the now-deadResult.3. Sharded reputation map (reputation)
LocalReputationsplits its peer map into 16 independently-locked shards (by firstNodeIdbyte). Ascore()read on the ranking path and the periodicevict()sweep no longer contend on one globalRwLock; eviction walks shards one at a time instead of holding the write lock across an O(peers) scan.4. O(1)
get_or_seedhot path (node)BuyerLedgers::get_or_seednow probes the map once on the common reuse path; the O(lanes) cardinality prune runs only when a genuinely new lane is inserted. Same bound as before, no per-miss scan — and it deliberately never drops a still-held ledger, whose in-memory watermark can lead the persisted row.5. Probe early-exit (node)
probe_and_rankcollects probe answers viaFuturesUnorderedand stops oncePROBE_EARLY_EXIT_CANDIDATES(=MAX_PROVIDER_ATTEMPTS= 3) blob-holding providers answer, rather thanjoin_allpacing the whole round to the slowest/dead probe. Item 5 asked to verify the ceiling wasn't already early-exiting — it wasn't.PROBE_TIMEOUT(500ms) stays the ceiling for sparse rounds. ADR 001 § Probe response collection updated.Verification
cargo clippy --workspace --all-targets,cargo fmt --check,cargo doc(pre-commit) — all clean.cargo nextest run:decdn-client-pullledger (incl. new deadline test),decdn-reputation(27),decdn-nodenode_origin_pull(176, incl.silent_upstreams_do_not_starve_the_candidate_loopand the wedged/failover suite) +client_loopback— all pass.🤖 Generated with Claude Code