Skip to content

Studio: per-request perf stats and slot usage in the API monitor - #8045

Merged
danielhanchen merged 36 commits into
unslothai:mainfrom
NilayYadav:api-monitor-stats
Aug 8, 2026
Merged

danielhanchen merged 36 commits into
unslothai:mainfrom
NilayYadav:api-monitor-stats

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Adds tok/s, time-to-first-token and stop reason to each request in the API monitor, plus a live slots readout (busy/queued) in the status strip, sourced from the existing admission queue. Engine timings are used when llama.cpp reports them (streaming and non-streaming), with a measured fallback for other backends. Old backends degrade gracefully.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56a1fd1b8d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be13ddb26f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f00d860de6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d12d1162d8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/routes/inference.py Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 80ab66b051

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: c31ad19395

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	studio/backend/routes/inference.py
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: aac3641d0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The relay filter ran a full json.loads on every SSE line of every proxied
stream. A usage chunk always spells the key literally, so a substring test
rejects content deltas 16x cheaper and leaves the parse to decide the rest.
@danielhanchen

Copy link
Copy Markdown
Member

Ran a performance check on this against main, since the monitor now does work on every streamed chunk.

Setup: two isolated Studios from the same commit pair (main at 58cc1b2 vs this branch merged onto it), separate UNSLOTH_STUDIO_HOME each, same model and quant (Qwen3-1.7B-GGUF Q4_K_M, 4096 ctx), same llama-server flags, pinned temperature and seed.

Microbenchmark, per streamed chunk (best of 7, 20k iterations each):

path main branch
append_reply 0.37 us 0.50 us
set_usage 0.41 us 0.64 us
_monitor_openai_chunk (content) 0.83 us 1.38 us
_monitor_openai_chunk (reasoning) 0.55 us 1.39 us
snapshot(), 50 rows 64.9 us 88.0 us

So roughly 0.6 to 0.8 us added per chunk. At 500 tok/s that is under 0.05% of the per-token budget.

The one item worth changing was the relay filter. _is_openai_usage_only_sse ran a full json.loads on every line of every proxied stream, at 1.64 us per content chunk, to find the rare choices: [] chunk. A usage chunk always spells the key literally, so a substring test in front of the parse rejects content deltas 16x cheaper (1.64 us to 0.10 us) with no cost on the usage chunk itself. Pushed as 7144169, with a case covering content that quotes the key so the parse is still what decides.

End to end, interleaved pre/post request by request, both llama-servers warm and on the same GPU, 40 pairs at 1000 max_tokens:

pre  median 0.661s   min 0.504s
post median 0.644s   min 0.441s
paired mean diff -0.027s (95% CI -0.052 to -0.002)

No slowdown. Two earlier runs did show a difference and both turned out to be the harness, not the diff: a sequential A/B put +11% on this branch purely because the two Studios sat on GPUs with different tenant load, and a same-GPU rerun put -51% on it because one llama-server had a warm prompt cache and the other had just restarted. The per-pair trace converged to zero by pair 25. Only the warm steady-state number above is meaningful, and it is a wash.

Also confirmed the new readouts against a live server rather than only in tests. Polling /api/inference/monitor across a real generation, the branch reports queue going active 0 -> 1 -> 0 against capacity 4 while main reports no queue at all, and the finished row carries ttft_ms 73, tok_per_sec 465.42, stop_reason "stop" where main has all three as null.

@danielhanchen

Copy link
Copy Markdown
Member

Screenshots for the before/after, since the change is mostly a UI one. Two isolated Studios from the same commit pair, main at 58cc1b2 on the left and this branch merged onto it on the right, driven through the same chat with Playwright. Same model and quant (Qwen3-1.7B-GGUF Q4_K_M, 4096 ctx), same llama-server flags.

Request detail. Six fields before, nine after: FIRST TOKEN, SPEED and STOP REASON are the new ones.

Request detail before and after

Mid-generation. Both headers say "Serving requests", but only the branch shows the live slot readout (SLOTS 1/4 busy), and only the branch puts a token rate on each finished row.

In flight before and after

Settled. SLOTS 0/4 busy in the header, 465 tok/s on the row.

Finished before and after

Whole run side by side, left main, right this branch:

Side by side run

Same thing from the API rather than from pixels. Polling /api/inference/monitor across a real generation:

main    status ready -> generating -> ready   queue None
branch  status ready -> generating -> ready   queue active 0 -> 1 -> 0 of capacity 4

and the finished row:

main    ttft_ms None  tok_per_sec None    stop_reason None
branch  ttft_ms 73    tok_per_sec 465.42  stop_reason "stop"

Performance numbers behind the comment above are in the same folder: pre.json, post.json for the per-chunk microbenchmark, and e2e_interleaved.json for the interleaved end-to-end A/B.

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.

2 participants