Skip to content

perf(node,client-pull): upstream pull leg — undeadlined lane-wide sends, process-wide funding single-flight, reputation lock on ranking #1794

Closed

Description

@alpergundogdu

Group G of the serve-path hot-path audit (siblings: #1788–#1793). The buyer leg is what a cache miss waits on before and during pull-through, so everything here is miss TTFB and miss-throughput — and it scales with miss rate, which is highest exactly when the network is growing (cold caches, new regions).

1. The issuance lock is held across the upstream network send with no deadline

crates/client-pull/src/ledger.rs:363,495-534 (issue() holds the per-lane tokio::Mutex through exchange(...).await; same in reanchor() :583 and :695). Holding it across the send is intentional — vouchers must reach the node in strict cumulative order (:349-355,472-478) — but the send has no timeout.

Fix: put a deadline on the send that fails the lane (triggering normal per-blob failover) rather than waiting forever; ordering can also be kept by a per-lane sequenced sender task so issuers enqueue without blocking each other.

Improves: a stalled upstream becomes a bounded failover event instead of a wedge.

Leaving as-is limits: one stalled upstream write blocks voucher issuance for every concurrent pull on that (signer, provider) lane indefinitely — the paced pulls stop (credit window exhausts), the downstream serves feeding off those fills stall, and failover never triggers because nothing errors. A single bad peer can freeze all misses being filled from it; blast radius grows with how much the node concentrates pulls on its best-ranked peers, i.e. with doing selection well.

2. Channel open/top-up single-flight is process-wide, not per-pool

crates/node/src/buyer_channel.rs:347,351 — open_in_flight / topup_in_flight are two global Mutex<Option<Shared…>> slots; every miss that needs funding funnels through them regardless of target pool. A poisoned slot is node-wide fatal for paying anyone (node_origin/mod.rs:127-131,214-218).

Fix: key the single-flight by pool (map of in-flight opens); scope poisoning to the affected pool.

Improves: unrelated pools fund concurrently; a funding failure is contained.

Leaving as-is limits: miss TTFB serializes on on-chain funding latency across unrelated pools — one slow Arbitrum interaction queues every other miss needing funds. As the node serves more distinct buyers/pools (the scale-up case), the two global slots become the throughput bound on cold-lane misses, and one panic in the funding path takes down payments node-wide.

3. Reputation is one process-wide RwLock, written inline during candidate ranking

crates/reputation/src/local.rs:196-200 (RwLock<HashMap<NodeId, Entry>>); evict() does a full-map retain under the write lock (:294-308); reads per candidate per miss (node_origin/mod.rs:2931-2933,1429); and the region-latency-mismatch write happens inline inside probe_and_rank while a client's miss waits (node_origin/mod.rs:1423).

Fix: shard the map (or per-peer atomic EWMA cells) and queue the inline write to a background folder.

Improves: ranking reads become lock-free; maintenance eviction stops blocking selection.

Leaving as-is limits: every concurrent miss's score() calls can block behind an O(peers) scan under the write lock, and the scan cost grows with network size — peer-set growth directly inflates miss TTFB. The inline write adds reputation bookkeeping to the client-visible ranking path.

4. BuyerLedgers.get_or_seed scans all live lanes under its lock on every miss

crates/node/src/buyer_ledgers.rs:62-71 — an O(lanes) retain with Arc::strong_count checks under the map mutex, per lookup.

Fix: move GC to a periodic task; lookups become one map probe.

Improves: O(1) lane fetch on the pull path.

Leaving as-is limits: per-miss cost grows with the number of live buyer lanes — more upstream relationships (a healthy, well-connected node) makes every miss slower.

5. The probe collection window has a fixed 500 ms ceiling

ADR 005 §Rate discovery: collect probe responses until 500 ms, then select (window.rs:151 → selection). Verify current behavior first — if selection already early-exits, close this item.

Fix: early-exit once K candidates beat a score threshold, keeping the ceiling as the fallback for sparse answers.

Improves: discovery latency tracks the fastest good candidates instead of the ceiling.

Leaving as-is limits: cold-miss TTFB carries up to 500 ms of fixed discovery latency even when the best candidate answered in 20 ms — in a regional deployment with nearby peers, the ceiling, not the network, sets miss TTFB.

Related: #1787–#1793.

Activity

  1. moved this from Backlog to Ready in deCDNon Aug 24, 2026
  2. added
    rust
    prio:medium
    on Aug 26, 2026
  3. moved this from Ready to In progress in deCDNon Aug 31, 2026
  4. moved this from In progress to Done in deCDNon Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:mediumrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions