- Concepts and terms
- Tasks and commands
- Annotated code
- Diagrams
- Defaults and numbers
- Troubleshooting
- Questions and tips
Start a server#
export HF_HUB_OFFLINE=1no Hub contact once the models are cachedsglang serve --model-path <model> --host 127.0.0.1 --port 30000 --enable-cache-report --enable-metrics --mem-fraction-static 0.85the L4 flagscurl http://127.0.0.1:30000/ready200 when the server accepts requestsThree processes#
Requests and checks#
| Task | Code |
|---|---|
| Send one native request | POST / |
| Ask in the OpenAI chat format | POST / |
| Read the cache hits of one request | meta_info field cached_tokens |
| Probe readiness | / |
| Fix the length spread of a benchmark | --random-range-ratio 1.0 |
| Sweep one concurrency cap | --max-concurrency 8 |
| Send a fixed arrival rate | --request-rate <rate> |
| Test output stability | python3 -m sglang.test.test_deterministic --n-trials 50 --test-mode single |
Benchmark your server#
| Command | What it does |
|---|---|
python -m sglang.benchmark.serving --backend sglang --port 30000 --dataset-name random --num-prompts 32 --max-concurrency 8 --seed 7 | Sends 32 random prompts with at most 8 in flight, then prints the report |
--random-input-len 512 --random-output-len 128 | Sets the prompt and answer lengths |
--random-range-ratio 1.0 | Keeps every prompt at the length you asked for. The default 0.0 makes the average about half |
--request-rate <rate> | Sends requests on a schedule, so the server can fall behind like real traffic |
Defaults that matter#
| Setting | Default | Note |
|---|---|---|
--schedule-policy | fcfs | lpm is the paper's order, not the default |
--schedule-conservativeness | 1.0 | Raise it when the log shows retractions |
--radix-eviction-policy | lru | Change only after a measured hit rate |
--kv-cache-dtype | auto | Keeps the model data type |
--stream-interval | 1 | Streams after every step |
--tp-size | 1 | One GPU unless the weights need more |
--cache-threshold | 0.3 | Gateway match rate for prefix affinity |
Numbers to watch#
- sglang:token_usage
- near 1.0 means the KV pool is full.
- sglang:num_queue_reqs
- above 0 for minutes means the server is past its knee.
- sglang:cache_hit_rate
- a gauge over one interval. Compute the rate from
sglang:prefill_effective_tokens_total. - cached_tokens
- the count of prompt tokens reused from the cache.
- Goodput
- requests per second that meet the TTFT and TPOT targets together.
Incidents on record#
- Issue #36889
- a Mamba cap set the request limit to 2, and only an info line said so.
- Issue #17411
- a FlashInfer upgrade made Hopper decode seven times slower.
- Issue #5274
- EAGLE-3 doubled batch-1 speed and cut concurrency 20 by a quarter.
- Issue #35129
- removing a per-session hash raised the hit rate from 66.8 to 94.4 percent.
Tips#
- Start servers with
--enable-cache-reportand--enable-metrics. - Read the pool size in the startup log before you size clients.
- Send SIGTERM to the main process only.
- Set
SGLANG_ENABLE_HEALTH_ENDPOINT_GENERATION=falsefor liveness probes.
Fix these errors#
| Symptom | Cause | Fix |
|---|---|---|
RuntimeError: [METAL] Command buffer execution failed at 32 requests | Pool sized at 87 percent of free memory | Pass --mem-fraction-static 0.4 and restart |
| Median TTFT near 28 s with free GPU memory | Admission queues requests for a full pool | Raise --schedule-conservativeness or lower --max-running-requests |
KV cache pool is full. Retract requests. in a loop | The forecast is too bold | Raise --schedule-conservativeness and send realistic max_new_tokens |
RuntimeError: The memory capacity is unbalanced | One TP card shares memory with other pods | Free the other card and restart. No flag disables the check |
cuda graph: False on decode lines under load | Decode batch above the graph limit | Set --cuda-graph-max-bs-decode to peak concurrency |
ambiguous option: --cuda-graph-max-bs | The flag was split at v0.5.22 | Use --cuda-graph-max-bs-decode or --cuda-graph-max-bs-prefill |
#cached-token: 0 on every repeat | Random ID at the start of the system prompt | Move the ID to the end or remove it |
Tune in this order#
Glossary#
- ITL
- inter-token latency, the gap between tokens.
- MLA
- multi-head latent attention, a compact KV layout used by DeepSeek.
- MoE
- mixture of experts, where each token uses a few experts.
- EPLB
- expert placement load balancing across GPUs.
- PD
- prefill-decode disaggregation, with prefill and decode on separate servers.
Questions#
- Where do I look when time to first token is high and the GPU is idle?
- Check the tokenizer process before the kernels.
- Why does a bigger pool add no throughput?
- The pool was never full at 64 users in our runs.
- Should I deploy
latest? - No. Pin a tag such as
v0.5.22.