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

@ -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.