Skip to content

Scheduler load metrics: a server-owned load ledger in /metrics and GET /v1/load - #1655

Merged
ashhart merged 11 commits into
ashhart:mainfrom
laudney:load-metrics-1558
Oct 31, 2026
Merged

ashhart merged 11 commits into
ashhart:mainfrom
laudney:load-metrics-1558

Conversation

@laudney

@laudney laudney commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

What this changes

/metrics and a new GET /v1/load publish the scheduler load a traffic shaper needs, from one ledger the server owns: the server's identity and process instance, whether --idle-unload has parked the engine, model requests in progress by route group, queued prompt tokens, requests requeued for memory and background passes that yielded, per-mode scheduler tokens counted as the work happens with the engine time of their prompt calls, and on CUDA the KV mode, free lanes and GLM-5.3-Flash's page pool in tokens. A group an engine cannot count is left out, never shown as zero, and while the engine is parked no engine value is shown. The lane host and the Flash Next host no longer publish preemptions_total 0 as a constant. No scheduling, admission or arithmetic changes. Closes #1558.

The questions in #1558 are still open. This is one series of eight commits in the delivery order the issue gives; I can split it into a stack, move the JSON under a stable /stats, or add vLLM-name mirrors, whichever you prefer.

Commit What it adds
refactor(lanes): move warm passes and requeue out of the lane host Frees lines in lane_host.zig (595 to 556) for the call sites; no behaviour change
feat(metrics): add the server-owned scheduler load ledger core/load_ledger.zig: groups, producer handles that drop writes once detached, one snapshot read
feat(metrics): publish server identity, parked state and activity server_info{model,backend,version,instance}, process_start_time_seconds, engine_parked, lanes, http_requests_active{route}
feat(lanes): publish the lane host's requests group requests_running and requests_waiting from the ledger, waiting_prompt_tokens, filling_prompt_tokens_left, requests_started_total, requests_requeued_total, background_yields_total
feat(lanes): publish per-mode work and prefill busy time scheduler_tokens_total{mode} (prefill_compute, prefill_cache, decode), prefill_busy_seconds_total
feat(metrics): serve the load ledger as one JSON snapshot GET /v1/load, under the /metrics access rule, the read scope and --metrics-open
feat(metrics): publish KV capacity and the GLM page pool census kv_capacity_mode{mode}, lanes_free, kv_pool_{capacity,available,reclaimable,promised}_tokens{pool}, kv_pool_run_available; the pool reports each promise, take, release and eviction
fix(metrics): keep fill bounds and fallback counts honest filling_prompt_tokens_left counts only from a settled start; the fallback body keeps the generated-token gauge

The docs/api.md section "Scheduler load" lists every family. A changelog line, if it helps:

/metrics and a new GET /v1/load report scheduler load for a traffic shaper, from one ledger the server owns. A group an engine cannot count is left out rather than shown as zero, and while the engine is parked no engine value is shown. The lane host no longer reports preemptions_total 0 as a constant; it counts requeues and yields.

Receipt

  • Environment: this branch on main at f350cd3ea, Zig 0.17.0, Linux x86_64. No GPU was used: the CUDA binary was built, not run.
  • Exactness: not measured. No token path changes; the lane host gains ledger updates at enqueue, admission, requeue, cancel, completion and prompt-call boundaries, under the ledger's own mutex.
  • Decode speed before and after: not measured.
  • Prompt speed before and after: not measured. The added work is a few integer updates per state change; the HTTP thread reads the ledger under its mutex only and never takes a host lock or touches a pool.
  • Tests run: zig build test 441/441 steps succeeded, 181/183 tests passed, 2 skipped; zig build test-golden 322/335 equal to server goldens, 0 unexpected differences; zig build test-kv-pool and zig build native succeed; zig fmt --check zig/src is clean; tools/zig/lean_check.py reports 426 problems on f350cd3ea and 426 on this branch, so it adds none. The FAIL lines in the test output are the same 94 lines that main prints. New tests: ledger (busy time as a union, counters kept across park and reload, writes through a detached handle dropped), renderer (each group whole or absent, the parked body, fixed route groups at zero), lane host (requeues, yields, shutdown cancels, running, waiting and waiting_prompt_tokens consistent in every snapshot), pool (available + promised + taken == capacity after every transition) and /v1/load access and scopes.
  • Not run, and why: no served GB10 check yet, so no live scrape, scrape cost, or counter comparison against a client; I will add them here. macOS was not built: the Metal-only change is one line in flashnext_host.zig, the removed constant. Each commit built and passed the host suite on the earlier base; on f350cd3ea only the head was tested.
  • Overlap: atc overlap finds one textual conflict, with deepseek: fail fast on a lost CUDA context and on stalled engine operations #1646 in zig/src/core/lane_host.zig: both add a LaneHost field after pressure. Whichever lands second takes both lines; the merged file stays at or below 600 lines.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No scheduling change.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Not run on a GPU; no token path changes.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No arithmetic change.)
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (No kernel changed.)
  • Prompt processing is no slower than the last release. (Not measured.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (Linux host tests and the CUDA build; no GPU run; no macOS build.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (They test new families and cannot run before them.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@laudney

laudney commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

GB10 receipt

Environment. One NVIDIA GB10 (DGX Spark), Ubuntu 24.04.5, kernel 6.17.0-1032-nvidia, driver 580.178.04, nvcc 13.4.92, Zig 0.17.0. Two builds with zig build native -Dnvcc=<nvcc> -Dversion=1.1.8 (default sm_121): main at f350cd3ea (tensorfold-native sha256 063ca4176e498a45…) and this branch at b9188cc74 (0572a083c53ae453…). Checkpoint TensorFold/Qwen3.6-35B-A3B-MLX-4bit-MTP at f84b054c, served with --drafter <the same folder> --context 262144 at TP=1: 8 streams, drafts "MTP + copies". NVIDIA's NVFP4 checkpoint needs #1662, so it is not used here. Every client ran on a second DGX Spark over the wired link (0.6 ms round trip), not on the GPU host.

Before and after

A fresh server each round with --prompt-cache-gib 0, in the order base, branch, base, branch, then branch, base.

  • Exactness, bench_concurrent.py --levels 1,4 --alone --serial --tokens 256 --reps 3 --temperatures 0 on both builds: every concurrent reply equals its solo run (code and chat prompts, 3/3 at one stream and 12/12 at four), and the solo runs equal "draft": false. The token_sha of every bench_openai.py reply and of every cold reply below is the same on both builds.
  • Decode, bench_openai.py --tokens 256 --reps 3 --temperatures 0, median tok/s per round:
prompt base branch base branch branch base mean base mean branch
fibonacci-raw 136.4 136.3 138.4 138.8 139.2 139.0 137.9 138.1
gpu-chat-no-think 117.1 116.0 118.5 118.4 118.6 118.5 118.0 117.7
  • Cold prompt, bench_cache.py --require-cold --tokens 16 on exact token arrays, 0 cached tokens on every request, ttft_s in ms per round:
prompt tokens base branch base branch branch base mean base mean branch branch/base
2,048 420.8 422.9 424.2 422.9 424.9 421.4 422.1 423.6 1.003
8,192 1437.6 1445.2 1446.7 1446.9 1451.2 1445.0 1443.1 1447.8 1.003
32,768 6659.5 6669.5 6683.3 6706.8 6721.8 6701.9 6681.6 6699.4 1.003

The branch's cold prompt is about 0.3% slower at every size, and the reversed pair shows it too, so it does not come from the run order. That is 1.5 to 18 ms on 0.4 to 6.7 s. I have not found its cause yet.

The ledger on a served engine

This branch, prompt cache on as served. 12 unique 4.2K-token chat requests (a nonce first), max_tokens 256, all sent at once to 8 lanes, with /v1/load read every 100 ms (203 reads, 0 errors):

client ledger
requests 12 sent requests_started +12
prompt tokens 50,800, 0 cached prefill_compute +50,800, prefill_cache +0
output tokens 3,072 decode +3,060: each request's first token comes from its prompt pass
finished counters prompt_tokens_total +50,800, generation_tokens_total +3,072
  • Peaks: running 8, waiting 11, waiting_prompt_tokens 46,567, filling_prompt_tokens_left 29,770, http_active.chat_completions 12. running + waiting never went above 12, no counter went down, and every gauge was back at 0 after the run.
  • Prefill rate from the pair: 50,800 tokens over 10.29 s of busy_us is 4,935 tok/s; the cold rounds above give 4,835 to 5,677.
  • requests_requeued, background_yields and preemptions_total stayed at 0, now as counted values: nothing was requeued at this load.
  • Capacity: kv_capacity_mode{mode="window"} and lanes_free; this engine has no page plan.
  • Scrape cost from the client host, idle, p50: /health 0.97 ms, /metrics 0.89 ms (17,749 bytes), /v1/load 0.76 ms (581 bytes). During the 12-request run, /v1/load took 3.1 ms p50 and 4.2 ms p95.
  • Decode with both routes scraped at 10 Hz, against no scrape, three alternating pairs: fibonacci-raw 137.8 against 139.0, 137.9 against 139.5, 138.4 against 139.6 (about 1% lower each time); gpu-chat-no-think 118.8 against 116.5, 116.5 against 118.3, 117.4 against 117.4. A shaper scrapes about once a second.

Parked engine

--idle-unload 20. After 18 s idle: engine_parked 1, /v1/load parked: true, every engine family gone (requests, work, capacity, KV, memory, prompt cache), the server families kept, and the same instance. One request reloaded the engine in 14.8 s; then engine_parked 0, requests_started_total 1, scheduler_tokens_total{mode="decode"} 15, and still the same instance.

A problem this found. engine_parked turns 1 when park in idle_unload.zig detaches the engine from the ledger, which is before close_held finishes. During that close, reload refuses with 503 "the engine is still unloading; send the request again". In an earlier run of this receipt, a request sent as soon as /v1/load read parked: true got that 503. docs/api.md describes the gauge as 1 while --idle-unload has closed the engine, and a shaper that wakes a node on engine_parked 1 can lose its wake request. The fix I propose for this branch: detach with parked false before the close, so the engine values go absent and read as unknown, and set parked only where park moves to .unloaded, with a test of that order.

Not run

The paged census (GLM-5.3-Flash on two ranks) and requeues under memory pressure were not reached by this engine and load. macOS was not built.

@laudney

laudney commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: the parked fix on GB10, and the cold-prompt gap

Same machine, checkpoint, settings and client host as the receipt above.

Parked, with the fix (2731719db)

2731719db moves the parked mark to the end of the close: the park detaches the engine first, so its values go absent and read as unknown, and the ledger reads parked only where the park moves to unloaded, under the lock the reload also takes. During the close, the scrape's fallback body also hides the stub's zero counts. A gated-close test checks both surfaces, and a mutant with the old order fails it.

Three --idle-unload 20 cycles, with /v1/load, /metrics and /health read every 0.2 s:

cycle engine values gone, parked 0, /health 503 parked 1 close window wake
1 17.26 s 18.09 s 0.83 s 0 refusals, reloaded in 14.4 s
2 17.02 s 17.85 s 0.83 s 0 refusals, reloaded in 14.6 s
3 16.81 s 17.64 s 0.83 s 0 refusals, reloaded in 14.5 s

During the close window, /v1/load has no engine groups and parked: false, and /metrics renders no requests_running, requests_waiting or generation_tokens_running, so a shaper reads the node as unknown and does not send its wake. The wake, sent as soon as parked read true, succeeded each time with the same instance, and requests_started_total was 1 after it. In cycle 1, one 0.2 s sample read /v1/load with engine groups and /metrics already from the stub: the two routes were read a few milliseconds apart, the park in between.

The cold-prompt gap

Twelve fresh servers with --prompt-cache-gib 0, in the order base, branch, diag, diag, branch, base, base, branch, diag, branch, diag, base. diag is 2731719db with the ledger's publish at each host unlock turned off, a test build only. ttft_s from bench_cache.py --require-cold --tokens 16 on the same exact token arrays; every request had 0 cached tokens, and every reply's token_sha is the same at each size. The rounds drift up by 1.2 ms (8K) and 7.3 ms (32K) a round; the differences below are after that trend, with a permutation test over the 4 + 4 rounds:

prompt tokens base mean branch mean diag mean branch − base p diag − base p
8,192 1443.5 ms 1445.4 ms 1447.5 ms +2.2 ms (+0.15%) 0.60 +3.8 ms 0.37
32,768 6667.6 ms 6684.8 ms 6694.8 ms +19.0 ms (+0.28%) 0.20 +25.3 ms 0.17

The receipt's six rounds gave +0.29% (p 0.20) and +0.21% (p 0.30) by the same method. The branch is slower in all four, but no run separates it from the round-to-round spread, and diag, with less ledger work on the prompt path, is not faster than the branch. So the gap is not the per-unlock publish. The other prompt-path updates are one host lock and a few integer updates per 4,096-row chunk call, microseconds against the 2 ms per chunk that 0.3% at 32K would take. I leave it as an unexplained difference of at most 0.3%, within the noise at this sample size.

@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. We'll take this, with GET /v1/load and the native names as they are; the same answer is on #1558.

Your receipts and ours so far are clean: Qwen3.6 and Qwen3.8-27B on a GB10 and Flash Next on an M3 Ultra show the same tokens and speed within noise. Two checks are left before it lands: GLM-5.3-Flash at TP=2 on two GB10s, and a quiet re-run of one Nemotron cell on the M3 Ultra (4-stream greedy chat read 3% low once while other work was running there). We'll post both here.

@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Both checks are back, @laudney, and both are clean:

  • GLM-5.3-Flash NVFP4 at TP=2 on two GB10s, main against this, alternating fresh servers: 52 of 52 replies token-equal. Prefill is +0.4 to +0.5% at 2k, 8k and 32k, decode at one and two streams is within -0.2 to +0.4%, and chat resumes keep the same 26,624 cached tokens on both builds.
  • Nemotron 3.5 Lightning on an M3 Ultra, the 4-stream cell re-run with the machine quiet: 344.8 → 346.4 tok/s (+0.4%). The earlier -3% was the other work that was running at the time.

It lands in our next batch, with /v1/load and the native names as discussed. Thank you for the patience on this one.

laudney and others added 11 commits October 31, 2026 12:04
lane_host.zig sat at 596 of its 600 lines, and the load ledger needs
call sites there. The warm pass moves to lane_host_warm.zig and the
LaneMemory requeue joins the other job endings in lane_host_end.zig,
with no change in behavior; the lane host is now 541 lines.
A traffic shaper needs scheduler load that survives engine reloads
and never shows a closed host's values. The ledger holds server
values, route-group activity and the groups a host publishes through
an epoch-checked producer handle, which the new optional load vtable
entry hands out; detach is synchronous and folds counters into a base.
A shaper must tell a parked engine from an idle one and see which
model routes are busy. The server now owns the load ledger, attaches
the serving engine at startup and reload, detaches before every
close, counts model requests by route group, and renders identity,
parked state, lanes and every ledger group beside the existing
families, with engine gauges left out while the engine is parked.
A shaper needs request counts, queued prompt tokens and lane give-ups
that agree in one read. Each lane host unlock now publishes its
counts when they changed, with requeues after LaneMemory and
background passes that yield to foreground work counted apart; the
lane and Flash Next hosts no longer report a constant zero preemption
count, and memory_lanes changes only under the host lock.
A shaper derives the prefill rate from adjacent counter deltas, so
tokens and time must move together as the work happens. The lane
host now counts computed, restored and decoded tokens and times each
backend prompt call for the pass inside it; a pass moves its time
into the busy counter only with its own tokens, a batch counts once,
and addStreams reports which prompts completed before a failure.
A collector that computes deltas wants every value from one instant.
GET /v1/load returns the whole ledger from one read, leaves out the
keys of groups no host fills, and follows the /metrics access rule:
read-scoped keys reach it and --metrics-open opens it. docs/api.md
documents the scheduler load families and the preemption meaning.
A shaper needs lane and KV headroom, and must not read a missing pool
as an empty one. The core page pool now notifies once per outermost
change; the generic CUDA host reports window mode without a page plan,
and paged mode with the pool a family names, in tokens. GLM names
rank 0's pool, and the census reaches the ledger at attach and after
every change without the lane host lock.
A reuse hint set fill_at before the backend confirmed the restore, so
filling_prompt_tokens_left could fall below the work still to do, and
the fallback scrape body reported generation_tokens_running as zero
while a closing host still held generated tokens. A pass now records
when its start is settled and counts fill progress only from then,
began shows the fill under the lock whose unlock publishes it, so a
blocking prefill is seen from its start, and the fallback body takes
the status read's generated tokens.
On a GB10 the ledger read parked while the idle unload was still
closing the engine, and a wake sent then got 503 "still unloading",
so a shaper that wakes a node on engine_parked lost its request. The
park now detaches with parked false before the close and marks the
ledger parked only where it moves to unloaded, under the manager lock
the reload also takes, and the scrape's fallback body hides the
stub's zero counts during the close, so that window reads unknown,
not idle. The harness attaches its fake engine as serve does, and a
gated close checks both surfaces before and after it ends.
@ashhart
ashhart merged commit 4a0135e into ashhart:main Oct 31, 2026
9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in 1.2.1, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney! GET /v1/load and the scheduler load in /metrics are in 1.2.1: https://github.com/ashhart/TensorFold/releases/tag/v1.2.1

@laudney
laudney deleted the load-metrics-1558 branch November 2, 2026 21:03
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.

Scheduler load metrics for traffic shapers: the gap to SGLang, and a server-owned load ledger

2 participants