#!/usr/bin/env python3 """Mixed chat + agent-session load for the flow-control article, with per-class TTFT and shed counts. For content/standalone/06-serving-in-production/07-serving-stack-flow-control (written 2026-10-29; run 2026-10-30 on the GX10 and 2026-10-31 on the Mac). Used on the GX10 (two vLLM replicas behind EPP + Envoy, arms R0/R1), on the Mac against llm-d-router in Kind over llm-d-inference-sim replicas (arms A0-A4b), and against the Dynamo 1.6.1 frontend + Mocker (arms D0-D3). Needs Python 3.10+ and httpx (present in the vLLM venv; `pip install httpx` elsewhere). Workload (Research Notes, "Harness"): - chat: Poisson arrivals at --chat-rate req/s, --chat-prompt-tokens random-word prompts (512), --chat-max-tokens output (128); llm-d headers objective `chat-premium` and fairness ID `chat-` (Part A) or `chat` (Part B, --fairness per-class); Dynamo header `x-dynamo-meta-policy-class: chat`. - agents: --sessions closed-loop sessions; turn 1 is an --agent-prefix (8,000) token prompt; each turn appends the model's output plus a "tool result" so the prompt grows by --agent-growth (1,500) tokens; when the next turn would pass --agent-cap (30,000 in Part A, 16,000 in Part B) the session starts over with a new 8k prefix and a new fairness ID; --agent-max-tokens (256) output; --think (2 s) between turns. A shed turn (429/503/529) is retried after the think time with the same prompt. Headers: objective `agent-sheddable`, fairness ID `agent--` (Part A) or `agents` (Part B); Dynamo `x-dynamo-meta-policy-class: agent`. Prompts are random common English words, about one token each in Qwen3's tokenizer and exactly one in the simulator's fallback tokenizer; every prompt starts with a unique header (arm label, session or request number), so no two sessions, and no two arms run back to back on the same replicas, share a cached prefix; the word sequences themselves repeat across arms (same --seed). Each point: --warmup (60 s) discarded, --measure (300 s) measured (requests sent in that window), then up to --grace (120 s) for in-flight requests before they are cancelled and recorded as "cut". Outputs in --out/