Requests table: durations in h/m/s, and the seconds each phase took

Duration, TTFT and the two new columns use one formatter that grows units only
as the value reaches them: 142 ms, 7.52 s, 31.2 s, then 1m 20s, then
1h 02m 06s. Sub-minute values keep their old precision, which is where almost
every request lives; a long generation no longer reads as "80.4 s".

Prompt sec and Generated sec show the two phases the rates were already
computed over, so a row now says where its time went: an 8011-token prompt as
19.3 s of prefill at 415 tok/s, then 6.74 s generating 141 tokens at 20.9. The
seconds come from the same split as the rates beside them -- a test asserts
tok/s == tokens / seconds for both phases, so the two can't drift apart.

A request that didn't stream has no first-token mark and so no split: its
prompt seconds read "—" and its whole duration is charged to generation, which
the column subtitle now says rather than leaving to be inferred.

run_phases/run_row move out of the snapshot closure to module level, so the
suite exercises the real row-building instead of a copy of it that had to be
kept in step by hand.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-04 00:23:33 -08:00
parent e24c0b7712
commit c8f04f49b7
4 changed files with 67 additions and 40 deletions

View file

@ -62,6 +62,11 @@ PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64 # a 64 GB Mac
The dashboard (`http://<host>.local:11340`) shows the active model, throughput, KV cache, GPU utilization,
temperature and power with 10-minute charts, the server log, and buttons to switch models or stop the server.
It also lists the last 20 finished requests, each split into its two phases at the first generated token:
prompt tokens with the seconds and rate of the prefill, then generated tokens with the seconds and rate of
the generation. A request that didn't stream has no first-token mark, so its prompt seconds read `—` and its
whole duration counts as generation.
## Connecting opencode
**On the server itself**, setup handles it: if opencode isn't installed it offers to install it (official

View file

@ -244,8 +244,8 @@ pre {
<table>
<thead><tr>
<th>Finished</th><th>Duration</th><th>TTFT</th>
<th>Prompt tok</th><th>Prompt tok/s</th>
<th>Generated tok</th><th>Gen tok/s</th><th>Peak KV</th>
<th>Prompt tok</th><th>Prompt sec</th><th>Prompt tok/s</th>
<th>Generated tok</th><th>Generated sec</th><th>Gen tok/s</th><th>Peak KV</th>
</tr></thead>
<tbody id="runs-body"></tbody>
<tfoot id="runs-foot"></tfoot>
@ -311,6 +311,15 @@ const fmt = {
dur: (s) => { if (s == null) return ""; s = Math.floor(s); const d = Math.floor(s / 86400), h = Math.floor(s % 86400 / 3600), m = Math.floor(s % 3600 / 60);
return d ? `${d}d ${h}h` : h ? `${h}h ${m}m` : m ? `${m}m ${s % 60}s` : `${s}s`; },
secs: (v) => v == null ? "—" : v < 1 ? Math.round(v * 1000) + " ms" : v < 10 ? v.toFixed(2) + " s" : v.toFixed(1) + " s",
// A request's own clock: seconds while that reads precisely, then minutes and hours as
// it passes them -- never a unit the value hasn't reached.
span: (v) => {
if (v == null) return "—";
if (v < 60) return fmt.secs(v);
const t = Math.round(v), h = Math.floor(t / 3600), m = Math.floor((t % 3600) / 60), s = t % 60;
const pad = (n) => String(n).padStart(2, "0");
return h ? `${h}h ${pad(m)}m ${pad(s)}s` : `${m}m ${pad(s)}s`;
},
ctx: (n) => n == null ? "" : n >= 1024 ? Math.round(n / 1024) + "k ctx" : n + " ctx",
};
@ -512,11 +521,13 @@ function renderRuns(s) {
const tr = document.createElement("tr");
if (r.aborted) tr.className = "aborted";
cell(tr, clock(r.t));
cell(tr, ...dash(r.dur, fmt.secs));
cell(tr, ...dash(r.ttft, fmt.secs));
cell(tr, ...dash(r.dur, fmt.span));
cell(tr, ...dash(r.ttft, fmt.span));
cell(tr, ...dash(r.prompt, (v) => fmt.big(v)));
cell(tr, ...dash(r.prompt_s, fmt.span));
cell(tr, ...dash(r.prompt_tps, (v) => fmt.n(v, 0)));
cell(tr, ...dash(r.gen, (v) => fmt.big(v)));
cell(tr, ...dash(r.gen_s, fmt.span));
cell(tr, ...dash(r.gen_tps, (v) => fmt.n(v, 1)));
cell(tr, ...dash(r.kv_peak_pct, (v) => fmt.n(v, 1) + "%"));
body.append(tr);
@ -529,15 +540,18 @@ function renderRuns(s) {
const peak = Math.max(...runs.map((r) => r.kv_peak_pct ?? 0));
const tr = document.createElement("tr");
cell(tr, `${runs.length} shown`);
cell(tr, ...dash(avg("dur"), fmt.secs));
cell(tr, ...dash(avg("ttft"), fmt.secs));
cell(tr, ...dash(avg("dur"), fmt.span));
cell(tr, ...dash(avg("ttft"), fmt.span));
cell(tr, ...dash(avg("prompt"), (v) => fmt.big(v)));
cell(tr, ...dash(avg("prompt_s"), fmt.span));
cell(tr, ...dash(avg("prompt_tps"), (v) => fmt.n(v, 0)));
cell(tr, ...dash(avg("gen"), (v) => fmt.big(v)));
cell(tr, ...dash(avg("gen_s"), fmt.span));
cell(tr, ...dash(avg("gen_tps"), (v) => fmt.n(v, 1)));
cell(tr, ...dash(peak > 0 ? peak : null, (v) => fmt.n(v, 1) + "%"));
foot.append(tr);
$("runs-sub").textContent = "newest first · averages below · tok/s split at first token";
$("runs-sub").textContent = "newest first · averages below · phases split at the first token; "
+ "a request that didn't stream has none, so all of it counts as generation";
}
const CW = 300, CH = 90, CN = 300; // chart viewBox width/height, max samples

View file

@ -94,6 +94,30 @@ def run_kv_peak(history, run, now, current):
return current if now - run["end"] <= 2 * SAMPLE_SECONDS else None
def run_phases(r):
"""How long a run spent on each phase, and the rate of each. Time to first token
covers the prompt's prefill (queueing with it, there being nothing finer to measure
from), and what's left of the duration is generation; a rate over the whole duration
would blur the two together.
A run that didn't stream has no first-token mark and so no split: its prompt time is
unknown and its whole duration is charged to generation -- which the table says, by
showing no prompt seconds beside it."""
dur, ttft = r.get("dur") or 0, r.get("ttft")
prompt_s = ttft
gen_s = (dur - ttft) if (ttft is not None and dur > ttft) else dur
return {"prompt_s": prompt_s, "gen_s": gen_s or None,
"prompt_tps": (r["prompt"] / prompt_s) if (prompt_s and r.get("prompt")) else None,
"gen_tps": (r["gen"] / gen_s) if (gen_s and r.get("gen")) else None}
def run_row(r, kv_peak):
"""One finished request as the dashboard's table wants it."""
return {"t": r["end"], "dur": r.get("dur"), "gen": r.get("gen"),
"prompt": r.get("prompt"), "ttft": r.get("ttft"), **run_phases(r),
"kv_peak_pct": kv_peak, "aborted": bool(r.get("aborted"))}
def parse_vllm_metrics(text):
vals = {}
for line in text.splitlines():
@ -227,15 +251,6 @@ class Sampler:
def ratio(a, b):
return shown[a] / shown[b] if shown.get(b) else None
def run_rates(r):
"""Split a run into its two phases: time to first token covers the prefill, the
rest is generation. Rates over the whole duration would blur the two together."""
dur, ttft = r.get("dur") or 0, r.get("ttft")
prompt_tps = (r["prompt"] / ttft) if (ttft and r.get("prompt")) else None
gen_window = dur - ttft if (ttft is not None and dur > ttft) else dur
gen_tps = (r["gen"] / gen_window) if (gen_window and r.get("gen")) else None
return gen_tps, prompt_tps
last_log = None
if phase in ("loading", "failed"):
lines = [l for l in service.logs("model", 20) if l.strip() and not OWN_POLL_RE.search(l)]
@ -254,14 +269,7 @@ class Sampler:
if key in self._seen_runs or r.get("start") is None:
continue
self._seen_runs.add(key)
gen_tps, prompt_tps = run_rates(r)
self.runs.append({
"t": r["end"], "dur": r.get("dur"), "gen": r.get("gen"),
"prompt": r.get("prompt"), "ttft": r.get("ttft"),
"gen_tps": gen_tps, "prompt_tps": prompt_tps,
"kv_peak_pct": run_kv_peak(self.history, r, now, point["kv"]),
"aborted": bool(r.get("aborted")),
})
self.runs.append(run_row(r, run_kv_peak(self.history, r, now, point["kv"])))
if len(self._seen_runs) > 4 * RUNS_SHOWN:
# The proxy only ever re-offers its own last RECENT_RUNS, so forgetting the
# oldest keys can't resurrect a run we already have.

View file

@ -66,34 +66,27 @@ for t, kv in ((99.0, 10.0), (101.0, 40.0), (105.0, 72.5), (109.0, 55.0), (111.0,
s.history.append({"t": t, "kv": kv, "gen": None, "prompt": None, "ttft": None,
"util": None, "temp": None, "power": None})
point = {"t": 111.0, "kv": 90.0}
gen_tps, prompt_tps = (None, None)
# exercise the real merge code by calling the block through a tiny shim
# The merge loop's own bookkeeping, around the real run_row/run_kv_peak it calls.
def merge(sampler, recent, point):
metrics = {"recent": recent}
def run_rates(r):
dur, ttft = r.get("dur") or 0, r.get("ttft")
p = (r["prompt"] / ttft) if (ttft and r.get("prompt")) else None
w = dur - ttft if (ttft is not None and dur > ttft) else dur
g = (r["gen"] / w) if (w and r.get("gen")) else None
return g, p
for r in metrics["recent"]:
for r in recent:
key = (r.get("start"), r.get("end"))
if key in sampler._seen_runs or r.get("start") is None: continue
sampler._seen_runs.add(key)
window = [q["kv"] for q in sampler.history
if q["kv"] is not None and r["start"] <= q["t"] <= r["end"]]
g, p = run_rates(r)
sampler.runs.append({"t": r["end"], "dur": r.get("dur"), "gen": r.get("gen"),
"prompt": r.get("prompt"), "ttft": r.get("ttft"),
"gen_tps": g, "prompt_tps": p,
"kv_peak_pct": max(window) if window else point["kv"],
"aborted": bool(r.get("aborted"))})
sampler.runs.append(web.run_row(r, max(window) if window else point["kv"]))
merge(s, [run], point)
r = s.runs[-1]
check("prompt seconds = time to first token", r["prompt_s"] == 2.0, r["prompt_s"])
check("generated seconds = what's left of the duration", r["gen_s"] == 8.0, r["gen_s"])
check("the two phases account for the whole run", r["prompt_s"] + r["gen_s"] == r["dur"], r)
check("prompt tok/s = prompt / ttft", abs(r["prompt_tps"] - 7667 / 2.0) < 1e-6, r["prompt_tps"])
check("gen tok/s excludes the prefill", abs(r["gen_tps"] - 200 / 8.0) < 1e-6, r["gen_tps"])
check("each rate matches the seconds shown next to it",
abs(r["prompt_tps"] - r["prompt"] / r["prompt_s"]) < 1e-9
and abs(r["gen_tps"] - r["gen"] / r["gen_s"]) < 1e-9, r)
check("peak KV from the run's own window", r["kv_peak_pct"] == 72.5, r["kv_peak_pct"])
check("points outside the window ignored", r["kv_peak_pct"] != 90.0)
merge(s, [run], point)
@ -104,8 +97,15 @@ s2 = S()
merge(s2, [{"start": 1.0, "end": 1.0, "dur": 0.0, "gen": 0, "prompt": 0, "ttft": None}], {"t": 1, "kv": None})
r2 = s2.runs[-1]
check("no rates, no crash", r2["gen_tps"] is None and r2["prompt_tps"] is None, r2)
check("no seconds either, rather than a zero", r2["prompt_s"] is None and r2["gen_s"] is None, r2)
merge(s2, [{"start": 2.0, "end": 3.0, "dur": 1.0, "gen": 5, "prompt": 9, "ttft": 1.0}], {"t": 3, "kv": None})
check("ttft == dur -> gen rate falls back to duration", s2.runs[-1]["gen_tps"] == 5.0, s2.runs[-1])
check("...and the generated seconds say so too", s2.runs[-1]["gen_s"] == 1.0, s2.runs[-1])
merge(s2, [{"start": 4.0, "end": 6.0, "dur": 2.0, "gen": 8, "prompt": 40, "ttft": None}], {"t": 6, "kv": None})
nos = s2.runs[-1]
check("a run that didn't stream has no prompt seconds", nos["prompt_s"] is None, nos)
check("...no prompt rate to go with them", nos["prompt_tps"] is None, nos)
check("...and its whole duration counts as generation", nos["gen_s"] == 2.0 and nos["gen_tps"] == 4.0, nos)
check("no KV history -> current value", s2.runs[-1]["kv_peak_pct"] is None)
print("\n6. the broken-pipe traceback you saw collapses to one line")