Skip to content

add --disable-disk-cache - #160

Merged
hnyls2002 merged 4 commits into
mainfrom
disk-cache-fix
Feb 7, 2024
Merged

hnyls2002 merged 4 commits into
mainfrom
disk-cache-fix

Conversation

@hnyls2002

Copy link
Copy Markdown
Collaborator

No description provided.

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

Related to #143 and #147.

@hnyls2002
hnyls2002 merged commit b1a3a45 into main Feb 7, 2024
@hnyls2002
hnyls2002 deleted the disk-cache-fix branch February 7, 2024 16:50
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
NorthmanPKU pushed a commit to NorthmanPKU/sglang that referenced this pull request May 16, 2025
…gl-project#160)

* .

* [NKI Transpiler] fix several bugs for input loader and output saver

* undo changes

* undo changes
XiaobingSuper pushed a commit to XiaobingSuper/sglang that referenced this pull request Jan 23, 2026
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
…AN F3-revisit

Initial T14 commit (47c77f3) only validated the instrumentation
on a cold empty tree (p99 = 0.20 ms) and concluded 'real-traffic
numbers will be higher but the threshold is generous'.  That was
lazy — PLAN T14's 50 ms threshold is specifically about behavior
under load, and an empty-tree probe doesn't test it.

Stress probe (dev/aginfer/verify/t14/stress_probe.py):
  32 concurrent /v1/chat/completions with per-chat unique long
  prefixes (256-512 tokens), max_tokens=200, 90 s sustained.  Polls
  /aginfer/state every 150 ms collecting (units, hbm%, dram%,
  p50/p95/p99/max ms, dump_bytes, n_recorded_total).  Exits 1 when
  peak p99 >= --threshold-ms (default 50, matching PLAN T14).

Headline finding: peak p99 = **321.94 ms**, 6.4× over the threshold.
PLAN T14 F3-revisit trigger fires.  Tracked as sgl-project#160.

Ramp:
  t=10s: p99 = 3.7 ms, max = 3.7 ms      (no outlier yet)
  t=20s: p99 = 3.7 ms, max = 395 ms      (first outlier appears)
  t=46s: p99 = 289 ms, max = 395 ms      (~1% outliers in ring)
  t=85s: p99 = 322 ms, max = 395 ms      (steady tail)

Diagnosis:
  - p50 stays 5-10 ms — typical dump-under-load is fine
  - The 395 ms outlier at t=20s is the dominant tail source; with
    1024-entry ring, a single >threshold spike pulls p99 once 1%
    of samples are spikes
  - peak_units = 187 — far below the ~10^4 working-set the paper
    assumes.  Tail is NOT walk-cost-driven; it's contention or GC
    with the scheduler's prefill/decode while HBM is at 100%
  - HiCache write_through reports DRAM 0% throughout the 90 s run;
    write-back pipeline appears not to populate DRAM — likely a
    separate sglang HiCache wiring bug to investigate alongside sgl-project#160

Implications for F3 design:
  - drop-on-full or coalesce would help (cap the spike at the
    source); incremental-state would NOT help (the tail isn't
    walk-cost)
  - this is exactly the kind of signal PLAN said the instrumentation
    was for: the design assumption 'state-dump is cheap' is
    empirically false under HBM-saturated load

README updated:
  - cold-tree p99 = 0.2 ms recharacterised as 'trivial workload,
    instrumentation sanity'
  - stress-test ramp table added as the headline number
  - F3-revisit trigger explicitly documented as fired
  - 'live-traffic numbers will be higher but threshold is generous'
    line replaced with the actual numbers

Stress samples:
  dev/aginfer/verify/t14/results/20260531_t14_stress_samples.tsv
  (470 rows × 10 cols)
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
… §6 B4)

Decouples handler latency from sglang POST latency.  Pre-T36 the
event-worker did 'await client.post(...)' for each migrate dispatch
— T42's stress probe measured time_in_queue_p99 = 355 ms (3.5× over
PLAN's 100 ms F3-revisit threshold) just from the serial-await
overhead.

T36 implementation:

  daemon/outbound.py (NEW, ~190 LoC):
    - OutboundBatch dataclass {batch_id, endpoint, body, enqueue_ts}
    - OutboundQueue: asyncio.Queue[OutboundBatch] + single worker
    - enqueue_migrate(actions): put_nowait + uuid4().  Returns the
      batch_id < 50 µs.  batch_id is also written into the request
      body envelope (DESIGN §6 L507) so APPLY_FAILED can correlate.
    - Worker drops 200 body (sglang's APPLY_FAILED webhook handles
      per-item failures); 4xx/5xx/transport: log + move on, no
      retry (DESIGN §10 idempotency makes re-issue safe).
    - start/stop lifecycle hooks wired by main.py into FastAPI's
      startup/shutdown.

  daemon/kv_scheduler.py:
    - +outbound= constructor param.
    - _dispatch_migrate: if outbound set, enqueue + return; else
      fall back to legacy sync POST path (preserved for unit tests
      not yet migrated).  No await on HTTP in the enqueue branch.

  daemon/main.py + daemon/proxy.py:
    - Wire OutboundQueue: shared instance on app.state.outbound,
      injected into KvScheduler, lifecycle bound to FastAPI hooks.

Verify (verify/t36, 8 stages, all GREEN):

  A0  batch_id UUID4 + unique across calls
  A1  HEADLINE: enqueue returns <1 ms even when downstream POST
      sleeps 200 ms (measured max ~30 µs across 50 calls)
  A2  worker drains FIFO order
  A3  worker survives 5xx storm (no crash, all posts attempted)
  A4  worker survives ConnectError (no crash)
  A5  stop() drains in-flight within bounded time
  A6  KvScheduler._dispatch_migrate enqueues exactly once, no sync POST
  B0  (opt-in) live stress: time_in_queue_p99 < 100 ms target

Stress remeasurement (same 100-webhook recipe as T42):

  metric                    pre-T36    post-T36   delta
  state_fetch_p99_ms        16.38      11.62      -29 %
  queue_depth_p99           18         86         +378 % *
  time_in_queue_p99_ms      355.84     176.05     -50 %

  * queue grew larger post-T36 because the bash driver outpaces the
    now-faster worker; the metric that actually gates F3-revisit
    (time-in-queue) halved.

Headline: T36 halved the time-in-queue p99 at apples-to-apples
event count.  Still over PLAN's 100 ms threshold at 176 ms, so
F3-revisit (sgl-project#160) stays open — but the data now points at
fetch_state HTTP round-trip (~10 ms / event under load) as the
remaining bottleneck.  Synthetic memory_pressure events triggered
only 1 actual migrate of 100, so the POST cost (the term T36
optimised) didn't dominate this trace; real-traffic profile (T42's
stress where every event drove ~17 skips through the sync POST)
would show a larger T36 win.

Next-step data for F3 (sgl-project#160): incremental state / state caching on
the daemon side (DESIGN §10 F3 branch) is now the clear
next-fastest optimisation.

Logs:
  verify/t36/results/20260601_t36_initial_pass.log     (8/8)
  verify/t36/results/20260601_t36_stress_100webhooks.log (5 cadence
    summaries + shutdown)
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
…eal win

User-flagged audit: my first stress test (run #1) ran on an empty
cache, so 99/100 events emitted 0 actions and the path T36
optimised was never exercised — the 50% drop was an artifact, not
a T36 effect.

Added run #2: pre-populated 79 units + 32 concurrent chats keeping
sglang busy.  Now every event drives a real migrate (20/20
enqueued; outbound worker drains in parallel).  T36's design is
realised: event worker does NOT serialize on POST.

But time_in_queue_p99 = 1655ms because state_fetch_p99 = 711ms
under sglang's chat-busy HTTP path.  The bottleneck shifted from
POST (T36 fixed) to fetch_state (F3-revisit / sgl-project#160 territory).

Back-of-envelope estimate for the un-measurable pre-T36 number
under run #2's conditions: 17 × ~1s/event = ~17 seconds.  vs 1655ms
post-T36 = roughly an order-of-magnitude win.

README updated to present all three runs honestly, explain why
run #1's number was misleading, and point to F3-revisit as the
clear next bottleneck (now well-characterized).

New log: results/20260601_t36_stress_with_populated_cache.log
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
…s against real sglang+daemon stack

The ONLY verify that launches a full sglang + daemon process pair
and pushes traffic through.  Per-task verifies (T7/T8/T36/T42/T164/…)
mock sglang; this one tests the actual wire path Run K uses.

Six flavors (60s shared sglang+daemon stack except F):
  A  proxy hot-path under load        — 24 concurrent chats × 60s
  B  state-dump under sustained traffic — /aginfer/state @ 2 Hz under chat load
  C  event-router fan-in throughput   — 200 webhook events
  D  migrate under traffic            — outbound + chat concurrently
  E  threshold PUT atomicity          — PUT/GET concurrent with traffic
  F  dead-sglang resilience           — separate daemon vs dead sglang port

Run4 (2026-06-01): all 6 PASS.  Headline:
  A: 10488 req, 100% success, p99=272 ms (Qwen3-0.6B)
  B: 159 samples, p99_max=33.9 ms — UNDER sgl-project#160's 50 ms F3-revisit ceiling
  C: 200/200 events accepted
  D: 200/200 migrate batches OK
  E: 268/268 PUTs OK, 0 torn reads of daemon's GET /aginfer/thresholds
  F: daemon stays alive, /health responsive, no false-positive fatal

State worth recording (caught during wire-up):
  * SGLANG_ENABLE_UNIFIED_RADIX_TREE=1 required; default HiRadixCache
    returns {"unsupported_tree_cache":...} for /aginfer/state
  * --aginfer-notify-url required for sglang's update_aginfer_thresholds
    to do anything (otherwise returns ok=False reason="no webhook firer")
  * Daemon MUST launch before sglang — sglang's T22 sgl-project#165 bootstrap
    GETs daemon/aginfer/thresholds at launch and halts on failure
    (deployment-ordering bug per daemon/aginfer_webhook.py)

F's positive-case integration is structurally hard from the event
path (state-fetch fails before outbound queue populates); T164
stages B0/C0 own the positive integration of escalate-to-fatal.
F here covers the complementary negative (low-traffic dead-sglang
must NOT escalate) — DESIGN §10 contract that sgl-project#164's both-axis
trigger was designed to prevent false-positives on.

Side-finding worth a follow-on: B's p99_max=34 ms beats sgl-project#160's
50 ms F3-revisit threshold under realistic load.  Earlier sgl-project#160
trigger may have been a different config; worth re-examining
whether sgl-project#160 is still load-bearing.
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
…evisit trigger no longer fires

sgl-project#160 was opened 2026-05-31 when the T14 stress probe measured peak
p99 = 321.94 ms (6.4× over the PLAN F3-revisit threshold).

Re-ran the SAME fixture today (32 concurrent unique-prefix chats ×
90 s × max-tokens=200 × Qwen3-0.6B × HiCache write_through ×
--max-total-tokens 65536) via the new run_stress_real.py driver:

  metric                 | 2026-05-31 | 2026-06-01  | Δ
  -----------------------+------------+-------------+----------
  peak units             |  187       |   171       | comparable
  peak HBM used          | ~99 %      | 99.9 %      | comparable
  peak p99 (ms)          | 321.94     |   3.52      | 91× lower
  peak max (ms)          | 395        | 415.46      | comparable

The single ~400 ms GC/scheduler-contention OUTLIER still fires
(once per 90 s run), but no longer dominates the distribution.
1024-entry × 150 ms-poll ring holds ~2.5 min of recent history;
1 outlier in ~600 samples can't pull p99 above ~3-4 ms.

No single code change targeted state-dump cost specifically.
The improvement is incidental — likely cumulative effect of the
verify-batch landed between 2026-05-31 and today: T17 schema
simplifications, T36 outbound fire-and-forget removing daemon-
side blocking, T42 daemon observability reducing cross-process
contention.

T14 README updated with a "Re-verification (2026-06-01, sgl-project#160
closure)" section.  Single outlier documented for posterity — if
it ever clusters again under different workloads (larger models,
hicache storage backend), the trigger will fire and sgl-project#160 should
re-open.

Raw artifacts:
  results/20260601_t160_revisit_run.log
  results/20260601_094923_t160_revisit_stress_samples.tsv

Adds:
  verify/t14/run_stress_real.py — launches sglang with the original
  fixture, runs stress_probe.py, tears down.  Reusable for future
  sgl-project#160 re-checks.
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
…s trigger STILL FIRES

The 2026-06-01 closure (commit 7450723) was wrong.

What the audit caught (subagent + user feedback):
  1. The new run_stress_real.py launcher DROPPED two flags from
     the original 2026-05-31 fixture: --mem-fraction-static 0.15
     and --attention-backend flashinfer.  ADDED an extra
     --max-running-requests 32.  Result: state-dump payload was
     ~50 kB (vs original 573 kB).  Smaller dump → faster latency
     for a trivial reason; the comparison was meaningless.
  2. N=1 violates the standing feedback-latency-multi-run.md rule
     ("single-shot perf numbers are unconvincing; do N≥3").
  3. Comparing today's N=1 against historical N=1 confounds
     machine-load variance with code-state changes.

Honest re-run today with:
  * EXACT original launch flags (mem-fraction-static 0.15,
    attention-backend flashinfer, write_through, max-total-tokens
    65536) — verified line-by-line against README "REPRODUCING"
  * N=3 independent trials, each with a fresh sglang launch

Results:

  trial | peak_p99(ms) | peak_max(ms) | outliers>50ms | dump_bytes
  ------+--------------+--------------+---------------+-----------
   1    |    343.79    |    426.83    |      216      |   567 792
   2    |    343.31    |    420.54    |      216      |   558 629
   3    |    344.60    |    371.88    |      194      |   586 420
  mean  |   343.90     |              |      209      |   ~571 kB
  stdev |     0.65     |              |               |

  3/3 trials fire the PLAN T14 F3-revisit trigger (p99 > 50 ms).
  Cross-trial std = 0.65 ms — the finding is extremely stable.

sgl-project#160 STAYS OPEN.  The original 321.94 ms reproduces robustly.
The temporary "closure" was a fixture-mismatch artifact.

T14 README's previous "Re-verification" block fully rewritten:
admits the fixture error, shows the new N=3 measurement, and
notes the corrected diagnosis (peak_units only ~170 → outliers
are GC/scheduler-contention stalls, not tree-walk cost).

Driver fix: run_stress_real.py now uses the exact original
launch flags + supports --trials N (default 3) + parses outlier
counts from each TSV + aggregates mean/std at the end.

Memory written: feedback-reverify-exact-fixture-multi-trial.md
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 2, 2026
…43ms→12.4ms (27× lower)

The actual F3-revisit fix.  After the audit caught my previous
"closure" as a fixture-mismatch artifact and the user pushed to
彻底解决 (fully resolve), I did the actual implementation work.

Root cause (now diagnosed):
  The state_dump_metrics records wall-clock duration of
  `_dump_aginfer_state_impl` INSIDE the scheduler process,
  INCLUDING GIL preemption.  When the scheduler is mid-prefill /
  decode, Python state-dump code waits for the GIL; the metric
  records that wait as "dump cost".  Daemon HTTP requests
  landing during a busy iter similarly queue at ZMQ for ~400ms.

  Two latencies were conflated:
    1. Scheduler-internal compute (state_dump_metrics.p99_ms)
    2. Daemon's HTTP blocking wait

Fix (the F3 "coalesce + background refresh" option):
  http_server.py:/aginfer/state now serves from a module-level
  cache that a background asyncio task refreshes every 50 ms
  (AGINFER_STATE_REFRESH_MS).  User requests return cached bytes
  in microseconds + HTTP RTT.  Bg refresh task absorbs the
  scheduler-side variance in its own loop.

  Cold-start: first /aginfer/state request triggers a sync fetch
  AND kicks off the refresh task.  Failed refreshes keep the
  stale cache (logged); never fail-loud to the daemon.

  Bounded staleness: daemon sees state ≤ (refresh interval +
  worst-case refresh wall-clock) ≈ 50ms + 340ms ≈ 400ms.
  Acceptable for paper §3 policy decisions (HBM-pressure trends,
  not ms-fresh snapshots).

Re-verification (N=3, exact-original fixture):

  trial | sched p99 | http p99 (NEW) | http max | sched outliers
  ------+-----------+----------------+----------+----------------
    1   |  344.72   |    11.07       |  89.69   |     212
    2   |  323.98   |    13.70       |  86.09   |     224
    3   |  339.90   |    12.37       |  89.14   |     207
  mean  |  336.20   |    12.38       |          |
  stdev |   10.85   |     1.32       |          |

  Daemon-facing p99: 343.90 → 12.38 ms.  27× lower; 4× under the
  50 ms PLAN T14 threshold.  All 3/3 trials pass.

  Scheduler-internal p99 stays ~336ms (the bg refresh task still
  hits the slow path on each tick).  Daemon doesn't observe it —
  hidden behind the cache.  Reducing it is the architectural
  follow-on sgl-project#179 (dedicated thread / lock-free walk / slim dump
  variant).

PLAN T14 updated to split the trigger:
  * "daemon-facing HTTP latency" — fixed by this change (12.4ms)
  * "scheduler-internal compute" — separate concern (sgl-project#179)

New artifacts:
  python/sglang/srt/entrypoints/http_server.py — cache + bg refresh
  dev/aginfer/verify/t14/http_latency_probe.py — client-side probe
  dev/aginfer/verify/t14/run_stress_real.py — now runs both metrics
WhiteCmile added a commit to WhiteCmile/sglang that referenced this pull request Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant