Unit 6 of 12 · about 4 hours · explain, implement
Cancellation, disconnects, overload, rejection and SLO-aware goodput
Load always exceeds capacity eventually. Requests that miss their deadline are wasted work, and cancelled requests that leak blocks slowly strangle the server.
You'll be able to
- Explain cancellation and client-disconnect handling with cleanup ownership at every request phase.
- Explain early rejection and load shedding as goodput protection under overload.
- Implement an abort path that frees blocks, records a terminal state and keeps goodput accounting honest.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Early rejection and fault toleranceAI Systems Performance Engineering - Chapters 16 and 18, scheduling and admission
Early Rejection (Admission Control) (pp.1144-1147): predicting SLO misses from queue and throughput signals, fail-fast against queue-then-miss, Fig 18-8 instance load on p.1147; the Quality of Service tail (pp.1147-1148) with TTFT and TPOT p99 monitoring and the prefill and decode queue split; Fault Tolerance (p.1148) with decode-node failover via KV pooling
- Mini-SGLang abort pathMini-SGLang - Scheduler and Overlap Scheduling
PrefillManager.abort_reqinpython/minisgl/scheduler/prefill.pywithDecodeManager.abort_reqinpython/minisgl/scheduler/decode.py, dispatched from_process_one_msginpython/minisgl/scheduler/scheduler.py; trace where each path frees the request's resources - vLLM cancellation endpointsvLLM v0.31.0 online serving
/abort_requestsfor all in-flight or listed request ids without pausing the scheduler; the Responses cancel API at/v1/responses/{response_id}/cancel. The page does not cover client disconnects, which the v0.31.0 server handles inwith_cancellation; confirm on your engine that dropping a streaming client stops its tokens and frees its blocks - Terminal accounting in vLLM metricsvLLM v0.31.0 metrics design
The queue-time against inference-time split, and TTFT, inter-token and end-to-end latency histograms as the goodput inputs.
vllm:request_successwith itsfinished_reasonlabel (abortamong the v0.31.0 values) is listed on the Production Metrics page, https://docs.vllm.ai/en/v0.31.0/usage/metrics/
Focus on
- Cancel at any phase: waiting removal, prefill-chunk abandonment and decode eviction must all free blocks and mark a terminal state, or the leak accumulates one request at a time.
- A client disconnect is an implicit cancel. The server cannot rely on the client to say goodbye, so streaming endpoints must watch the connection and abort promptly.
- Early rejection protects the accepted load: refusing work that would miss its SLO keeps TTFT and TPOT for the rest, while queueing everything maximizes completions and minimizes goodput.
- Goodput counts only completions that meet the SLO over offered requests. Aborted, rejected and late requests are not throughput, and retried work multiplies load as the systems overload-control unit shows.
Common mistakes · 3
- Deleting the request from the queue and calling it cancelled. Its KV blocks stay reserved until something frees them, so the leak only shows under sustained cancel load.
- Counting retries as new offered load. Client retries multiply the original overload, which is why rejection must pair with retry budgets rather than replace them.
- Averaging latency over completed requests only. Dropped and late requests vanish from that mean while users still waited, so goodput over offered load is the honest denominator.
Try it yourself
Closed-book, before checking anything
abort(request_id) in your simulator: remove the request from whichever set holds it, free its blocks, append a terminal ABORTED record with its phase, and assert no block stays reserved. Then compute goodput for 10 offered requests with 7 on-time completions, 2 late completions and 1 abort: , not 9/10.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A decode request disconnects mid-stream. List what the server must do.Answer
Abort the in-flight request, free its KV blocks, mark it terminal with an abort reason, and stop scheduling further tokens for it. Anything less leaks memory or burns compute on a gone client.
2.Why does early rejection raise goodput while lowering raw completions?Answer
It refuses requests predicted to miss their SLO, so the accepted ones meet TTFT and TPOT targets. Raw completions fall by the rejected count, but SLO-meeting completions over offered load rise.
3.Ten requests are offered: 7 on time, 2 late, 1 aborted. What are throughput and goodput denominators telling you?Answer
9 completions over 10 offered is completion rate, not success. Goodput is 7/10: only on-time completions count, because late outputs already failed the contract.
4.Where does Mini-SGLang route a cancel, and why two paths?Answer
Through
_process_one_msgtoPrefillManager.abort_reqorDecodeManager.abort_req. A request can sit in either manager, so the cancel must reach whichever one owns it.
You're done when
Your abort path passes a cancel-at-every-phase test with zero leaked blocks, and you compute goodput over offered load without notes.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 14 more in the section
- AI Systems Performance Engineering - Chapters 16 and 18, scheduling and admissionChris Fregly (O'Reilly) · required
Read "Dynamic Batching, Scheduling, and Routing" in Chapter 16 and "SLO-Aware Request Management and Fault Tolerance" in Chapter 18 (early rejection, quality of service).
- Mini-SGLang - Scheduler and Overlap SchedulingSGLang Project · required
Read docs/structures.md, scheduler implementation and tests/core/test_scheduler.py, then compare overlap scheduling with the Nano-vLLM loop. Use the online benchmark only after fixing the same workload and hardware contract.
- vLLM v0.31.0 metrics designvLLM Project · reference
Read the WAITING, RUNNING and PREEMPTED request states and the queue, inference, prefill and decode interval definitions. Swapped-preemption metrics are legacy in v1. The exported counters, including
vllm:num_requests_waiting_by_reasonandvllm:num_preemptions, are listed on the Production Metrics page, https://docs.vllm.ai/en/v0.31.0/usage/metrics/ - vLLM v0.31.0 online servingvLLM Project · reference
Read the
/abort_requestsendpoint and the Responses cancel API for request cancellation. Verify client-disconnect aborts on your engine; the page does not cover them.
Also in this section
- Hands-On LLM Serving and Optimization - Chapter 6, batching and schedulingChi Wang and Peiheng Hu (O'Reilly) · primary
Read "Request Batching and Scheduling-Level Optimizations" in Chapter 6: dynamic, continuous and chunked-prefill batching. Rebuild each policy in a small event simulator and state the user-visible metric it can improve or harm.
- Orca: A Distributed Serving System for Transformer-Based Generative ModelsUSENIX OSDI · required
Study iteration-level scheduling and selective batching, including the workload assumptions. Reproduce one scheduling timeline by hand and use it as the correctness baseline for the simulator.
- Sarathi-Serve: Tackling Throughput-Latency Tradeoffs in LLM InferenceMicrosoft Research · required
Focus on chunked prefills, stall-free batching and the throughput-latency trade-off. Implement a fixed-token chunk policy and preserve a workload where chunking loses to the simpler scheduler.
- Nano-vLLM - Scheduler, Block Manager and Engine LoopGeeeekExplorer · required
Trace scheduler.py with llm_engine.py and block_manager.py. Add event logging in your own fork or project, explain every transition, and implement one bounded admission or chunking change with regression tests.
- AI Systems Performance Engineering - Continuous Batching LabChris Fregly · support
Run the Chapter 15 baseline and optimized continuous-batching pair under CPU-safe or available-GPU settings. Inspect the shared comparison contract and re-measure rather than quoting bundled deltas.
- TensorTonic Language Modeling from Scratch - Simulate Continuous Decode BatchingTensorTonic · support
Solve after the continuous-batching unit, then compare its admission rule with your own simulator.
- LLM Inference: From scratch, one token at a time - Module 05Tushar Amrit · support
Work the Batching module's arithmetic and checkpoint before the static and continuous batching units.
- LLM Inference Systems Laboratory - SchedulerRoadmap-Final · support
Add token and memory admission, chunking, priority, cancellation, overload and fairness to the simulator, then carry one policy through the real engine path with a reference fallback.
- vLLM v0.31.0 serve CLI and scheduler argumentsvLLM Project · reference
Look up scheduler flags and defaults:
--max-num-seqs,--max-num-batched-tokens,--max-num-active-seqs,--enable-chunked-prefill,--long-prefill-token-thresholdand--scheduling-policy. Runtime defaults vary by GPU class, so check them against the installed v0.31.0 behavior. - vLLM v0.31.0 benchmark CLIvLLM Project · support
Use
vllm bench servewith--request-ratefor offered-load sweeps, andvllm bench throughputandvllm bench latencyfor offline endpoint and phase baselines. Fix the dataset, lengths, request rate, warmup and sampling, and keep raw per-request results; do not copy example rates as targets. - vLLM v0.31.0 LoRA adaptersvLLM Project · reference
Read per-request
LoRARequestserving, server-wide--lora-moduleswithmax_lorasandmax_lora_rank, and why adapter-slot pressure rewards grouping same-adapter requests. - vLLM v0.31.0 structured outputsvLLM Project · reference
Read the xgrammar and guidance backends, the
choice,regex,json,grammarandstructural_tagoptions inStructuredOutputsParams, and the--structured-outputs-config.backendflag. - vLLM v0.31.0 multimodal inputsvLLM Project · reference
Read
limit_mm_per_prompt, content hashing withmulti_modal_uuidsin Cached Inputs, and the video pruning flags as examples of encoder-side scheduling cost. - TensorTonic Language Modeling from Scratch - Route Cache-Aware Prefill RequestsTensorTonic · support
Solve after the affinity unit: assign each request to a feasible worker by longest cached prefix, lowest projected uncached load, greatest remaining capacity, then lowest worker id, with -1 when infeasible.