Repository navigation
Conversation
select_snapshots builds an inverted index and enumerates candidate pairs to find the cheapest two-row quote. With heavily shared prefixes (agent-style traffic that reuses one long context across many requests) every posting list carries almost every candidate, so the pair loop approaches O(n^2 * pages): a single quote on a package with ~2000 free snapshots measured 9.4 s in release mode, and the quoting loop re-runs it after every eviction, wedging the scheduler (health stays 200, GPUs idle, no log output). See NVIDIA#319 for full evidence including symbolized stacks of the livelock. Truncate the candidate list entering the pair phase to a constant 128 ids. Candidates arrive in id order and ties already prefer lower ids, so the cap keeps the documented preference while bounding the worst case; quoting stays a heuristic and apply_snapshot_quote re-verifies deterministically. On the reproduced input the quote now takes ~40 ms, and 15 minutes of the wedge-triggering load (12 workers, /v1/responses, max reasoning effort, ~350 KB shared-prefix contexts, mid-stream cancels) run with no stall while decode throughput is unchanged (C16 -1.2%, C32 -0.7% vs the same load before the window).
original-el8
left a comment
There was a problem hiding this comment.
The scheduler stall in #319 needs a bounded-cost fix, but this truncation changes snapshot selection and can reject a feasible allocation. I reproduced the regression using the exact posting_starts/select_snapshots functions from this PR and from main 5fd4070, compiled with rustc. With 130 candidates, ids 0..127 costing two pages and ids 128/129 costing zero, two available pages and keep_pages=2, main selects [128] for count=1 and [128,129] for count=2; this head returns None for both. This is a functional regression, separate from the reported performance improvement. The complete runtime workload was not rerun during this review.
| const MAX_PAIR_CANDIDATES: usize = 128; | ||
| let truncated = candidates.len() > MAX_PAIR_CANDIDATES; | ||
| let candidates = if truncated { | ||
| candidates.into_iter().take(MAX_PAIR_CANDIDATES).collect::<Vec<_>>() |
There was a problem hiding this comment.
[P1] Preserve feasible snapshots beyond the first 128 IDs
Taking the first 128 IDs drops candidates before evaluating their costs and even before the count==1 fast path. IDs are only a tie-break after cost; lower IDs are not generally better choices. Reproduction: backing=[true,true], protected_refs=[0,0], ranges[0..128]=0..2, ranges[128]=ranges[129]=0..0, candidates=0..130 and keep_pages=2. Main returns Some([128]) for one row and Some([128,129]) for two rows; this PR returns None for both although those zero-cost aliases fit. Callers can consequently evict useful checkpoints or reject/delay admissible work. Bound the expensive pair search without imposing this ID-prefix allocation restriction, preserve the unaffected single-row path, and add coverage where the only feasible or cheapest candidates lie past index 127. Deterministically rechecking a returned quote cannot recover candidates that were discarded.
Review feedback: taking the first 128 ids drops candidates before considering cost, so the only feasible (zero-cost) snapshots can be discarded and the selector rejects an allocation main would make. - Leave the single-row path on the full candidate list (it is already linear; the blowup is only the pair phase). - For pairs, keep the cheapest MAX_PAIR_CANDIDATES by (cost, id) instead of the first ids; zero-cost candidates therefore always survive the bound. Inputs with at most that many candidates run the exact original enumeration unchanged. - Compare ties explicitly on the (union, id pair) key: the candidate list may now be cost-sorted, so scan order no longer encodes the lexicographic id preference. - Add the review's minimal case (feasible zero-cost candidates at ids 128/129 under 130 candidates) as a regression test, alongside the shared-prefix blowup test with a bounded-time assertion. Verified: scheduler suite 310/310; shared-prefix quote still ~40 ms (was 9.4 s unbounded); review case selects [128] and [128,129].
|
Thanks for the precise review and the minimal reproduction — agreed, the id-prefix truncation was wrong. Pushed a revision to this branch:
We will also run the #296/#329 branches through the shared-prefix/cancellation workload from #319 and report back. |
Live re-testing of the previous revision exposed a second unbounded path: with the bound placed in the two-row branch only, requests whose quote rows exceed two (speculative-decode workloads quote more rows) still reached the count>2 greedy witness with the full candidate list, and the engine wedged again under the same shared-prefix load (symbolized stack: select_snapshots -> simulate_snapshot_quote, hot in BTreeSet probes per page; GH NVIDIA#319 evidence recorded). Move the bound before every multi-row path (both the conservative witness and the two-row enumeration); the single-row path keeps the full candidate list as requested in review. Added a count=7 shared-prefix regression test alongside the pair-path one: both now quote in ~40 ms where the unbounded originals take seconds, and the review's zero-cost-at-id-128/129 case still selects correctly. Validation on 4x RTX PRO 6000 (TP4, draft 7, CSF package): scheduler suite 311/311; 15 min of the NVIDIA#319 wedge load with zero stalls on this revision (the previous revision wedged at ~165 s); decode bench C1 285.5 / C8 1035.8 / C16 1468.7 / C32 1881.2 tok/s vs 290/1076/1465/ 1896 on the working 972e28e baseline (within run-to-run noise).
|
Follow-up with live results, including a correction to the previous revision: The cost-sorted bound placed only in the two-row branch was insufficient. Live re-testing wedged the engine again at ~165 s under the #319 load — requests that quote more than two rows still reached the Validation matrix (4× RTX PRO 6000, TP4, draft 7, CSF package, 15 min of the #319 workload each):
New head decode bench: C1 285.5 / C8 1035.8 / C16 1468.7 / C32 1881.2 tok/s vs 290/1076/1465/1896 on the working baseline (run-to-run noise). Offline: pair-path and count=7 shared-prefix quotes both ~40 ms (was 9.4 s / multi-second); scheduler suite 311/311; your zero-cost-at-128/129 case passes. On #296/#329: per the earlier suggestion we ran #296 ( |
|
Your profiling found that the cost is in pair enumeration inside each selection, and #346 removes exactly that. We merged #346 instead because it keeps the selection exact. A 128-candidate cap misses some feasible cases: with 128 disjoint 4-page aliases plus one 8-page alias spanning two of them, budget 8 and count 3, the cap returns no selection, and the quote then evicts checkpoints it didn't need to. #346 brings the worst nested-alias selection from ~10 s to under 1 ms, with results identical to main across 18M randomized inputs. Closing in favour of #346. Thanks again for the diagnosis. |
|
Follow-up as promised: #329 ( Result: no stalls (905 s, canary green throughout), decode bench C1 281.4 / C8 1049.6 / C16 1465.0 / C32 1915.7 tok/s, prefill 32k 13,200 tok/s — at or slightly above the working baseline. Complete validation matrix on this host (4× RTX PRO 6000, TP4, draft 7, CSF package, 15 min of the #319 load each):
So both #296 and #329 independently avoid the livelock by eliminating the repetition amplifier, while a single unbounded quote can still cost ~9 s on those branches; the bound in this PR caps the per-quote cost itself. The approaches look complementary — happy to rebase or rework the bound however maintainers prefer if #296/#329 land first. (For the record: our production instance has been serving on this PR's build since validation — 9+ hours overnight, zero incidents.) |
|
Thank you — closing in favour of #346 makes complete sense. Prefix sums over contiguous alias ranges keeping the selection exact (and at 0.84 ms on our reported shape) is strictly better than our heuristic cap, and the additional feasibility counter-example is a fair kill for the 128-candidate bound. Glad the diagnosis was useful. For the record, we are migrating our production instance to a main build containing #346 (currently serving on our interim bounded build, which has been stable through the same workload), and will report if anything resurfaces under the shared-prefix agent traffic. |
Fixes the scheduler livelock analyzed in #319.
Root cause (confirmed with symbolized gdb stacks + an offline reproduction):
select_snapshotsenumerates candidate pairs through an inverted page index. Under heavily shared prefixes every posting list carries almost every candidate, so the pair loop approaches O(n² · pages): on a package with ~2000 free snapshot slots a single quote measured 9.4 s in release mode (offline unit test on the exact function,select_snapshots_shared_prefix_blowupin this PR).simulate_snapshot_quotere-runs the selection after every eviction, so planning never returns — the worker thread spins insidequote_snapshots_preserving, ranks idle, GPUs idle,/healthkeeps answering 200 and nothing is logged.Fix: truncate the candidate list entering the pair phase to a constant 128 ids. Candidates arrive in id order and the tie-break already prefers lower ids, so the documented preference is kept; quoting stays a heuristic and
apply_snapshot_quotere-verifies the quote deterministically. The reproduced input now quotes in ~40 ms (222×).Validation:
/v1/responses,reasoning_effort: 100, ~350 KB shared-prefix contexts, 2–8 s mid-stream aborts) — zero stalls; the unpatched build wedges in 8 s–8 min on the same load