WHY percentiles, not the mean? Because users feel the tail. If mean latency is 50 ms but p99 is 2 s, then 1 in 100 requests is painfully slow — and a page that makes 100 backend calls will almost always hit that slow tail once. The tail dominates perceived quality.
Model the server as an M/M/1 queue: requests arrive at rate λ, each takes mean service time s, so service rate μ=1/s. Define utilizationρ=λ/μ=λs.
Derivation sketch: In M/M/1 the mean number in system is ρ/(1−ρ). By Little's LawN=λ⋅E[L], so
E[L]=λN=λρ/(1−ρ)=λ(1−ρ)ρ=1−ρs
using ρ=λs⇒ρ/λ=s.
WHY this matters: as ρ→1 (server ~100% busy), E[L]→∞. Latency explodes nonlinearly. This is the single most important cost-vs-latency fact: running hardware "hot" saves money but destroys tail latency.
Derivation: cost/inference = (cost/second) / (inferences/second) = (H/3600)/X. Multiply by 106. So cost is inversely proportional to throughput — anything that raises X (batching, quantization, better utilization) lowers $$$.
The tail is what users feel; request fan-out makes rare slow requests hit almost every page load.
State the M/M/1 mean latency formula and its variables.
E[L]=s/(1−ρ), where s=mean service time, ρ=λs=utilization.
Why does latency explode as utilization ρ→1?
E[L]=s/(1−ρ)→∞; queue waiting time grows without bound when the server is nearly always busy.
Compute-time floor formula from FLOPs?
Lcompute≥F/(ηP) — work divided by achievable rate (peak P times efficiency η).
Why is cost per inference ∝1/X?
C1M=106H/(3600X); more requests per second amortize the fixed hourly machine cost.
What is the batching trade-off?
Larger batches raise throughput (↓cost) but waiting to fill them raises latency; cap with a max-wait timeout.
Little's Law?
N=λE[L] — average number in system = arrival rate × average time in system.
Two cheapest big wins for LLM inference latency?
KV-cache reuse and quantization (fp16/int8) — both cut compute and bytes moved.
Why not target 100% GPU utilization?
Queueing latency diverges near ρ=1; target ρ≈0.6–0.8 and autoscale.
Recall Feynman: explain to a 12-year-old
Imagine one cashier at a shop. If people arrive slowly, you're served fast. As the line gets busier and the cashier is almost never resting, the wait balloons — one extra shopper adds huge delay. That's why we don't keep our computer 100% busy: it gets a giant line. To serve more people cheaply, the cashier bundles several orders together (batching) — but if she waits too long to bundle, early customers get annoyed. So we bundle, but only for a moment. And using a smaller, lighter machine (a simpler model, smaller numbers) lets each order finish quicker and costs less.
Dekho, inference deploy karte waqt teen cheezein aapस ko balance karni padti hain: latency (ek prediction kitni jaldi aati hai), throughput (ek second mein kitni predictions), aur cost (paisa per prediction). Tinon ko ek saath jeetना mushkil hai — ek ko push karo to doosra bigadta hai. Engineer ka kaam hai: sabse sasta setup dhoondhna jo phir bhi latency SLA (jaise "p99≤200 ms") ko meet kare.
Sabse important baat: server ko 100% busy mat chalao. Formula hai E[L]=s/(1−ρ), jahan ρ utilization hai. Jaise-jaise ρ 1 ke paas jaata hai, latency phat jaati hai — 50% busy pe 40 ms, 99% busy pe 2000 ms! Same hardware, sirf zyada bhara hua. Isliye ρ ko lagbhag 0.7 pe rakho aur autoscaling use karo. Ye queueing theory ka Little's Law (N=λL) se aata hai.
Cost kam karne ka master lever hai batching. GPU ko akeli request bhejo to zyादातर cores waste ho jaate hain; 32 requests ek saath do to throughput X kai guna badh jaata hai, aur cost C∝1/X hoti hai — matlab throughput badha to cost automatically gir gayi. Lekin batch bharne ke liye thoda wait karna padta hai, jisse latency badhti hai — isliye ek max-wait timeout lagao. Baaki bade wins: quantization (fp16/int8 — kam bytes, fast math), KV-cache (dobara compute mat karo), aur distillation (chhota model, kam FLOPs).
Yaad rakho BQ-CACHE: Batch, Quantize, Cache, Autoscale, Cut-model, Hardware-rightsize, Evaluate-tail. Aur hamesha p95/p99 dekho, mean nahi — kyunki user tail latency feel karta hai, aur ek page 100 backend calls kare to slow tail lagbhag har baar hit hota hai.