SGLang OME is two layers: the OME control plane and SGLang, its primary runtime. OME is a Kubernetes control plane: a ServingRuntime tells it how to run a model server, and OME composes the service from an engine, an optional decoder and a router. SGLang is OME’s primary runtime. It serves as the model server in OME’s engine pods, and its scheduler and cache code lives in the SGLang GitHub repository. SGLang’s scheduler and its RadixAttention prefix cache decide which requests join the next batch and which KV cache is kept and reused. An advertised throughput figure measures maximum throughput, not your own p95. Its queue and cache metrics, read next to a profiler trace, show where that time goes.
What OME Decides and What SGLang Decides
When an InferenceService names a base model but no runtime, OME picks one. It only considers runtimes that support the model (including its size range, where known), have an entry marked autoSelect: true, are not disabled and list the right accelerator classes. Among those, a namespaced ServingRuntime beats a ClusterServingRuntime. After that the highest score wins: the format and framework weights of the runtime’s best entry added together, times its priority, with ties going to the closest size range. If spec.runtime.name names a runtime, OME uses it even when the runtime doesn’t declare support for the model.
OME’s controller also picks a deployment pattern. The options are a single engine, separate prefill and decode, multi-node serving for very large models, or scale-to-zero through Knative. The router discovers engine and decoder pods through the Kubernetes APIs. In a standard deployment it balances load by tracking KV cache state across workers and sending each request to the worker most likely to hold its prefix.
| Layer | What it decides | Where you see it |
|---|---|---|
| OME control plane | Which runtime serves the model, deployment pattern | InferenceService and ServingRuntime resources |
| OME router (SGLang router) | Which worker gets each request; prefill/decode hand-off in disaggregated mode | Prefix cache hit rate, which cache-aware routing aims to raise |
| SGLang scheduler | Which waiting requests join the next batch, in what order | Queue depth, queue time, TTFT |
| RadixAttention cache | Which KV cache is kept, reused or evicted | cache_hit_rate, cached_tokens_total, token_usage |
| Model executor | Forward passes, CUDA graphs, attention backend | PyTorch Profiler traces of kernel execution time |
How SGLang’s Engine Differs from a Naive Model Server
A naive inference engine throws away a request’s KV cache once the request finishes, so it can’t reuse that cache on later calls. SGLang keeps the KV cache for prompts and generated tokens in a radix tree, evicts the least recently used entries, and schedules with the cache in mind to raise the hit rate. The cache does not have a fixed pool of its own. Cached tokens share one memory pool with running requests, and when enough requests are waiting the system evicts cached tokens to make room for a bigger batch. The cache therefore competes with batch size for the same memory, and the balance shifts with load.
The cache adds negligible overhead when it misses. In the SGLang paper’s ShareGPT test, which had no reuse opportunities, managing the radix tree took 0.2 seconds out of a 74.3-second run, under 0.3%. RadixAttention also works alongside continuous batching and paged attention, so it adds to the usual serving machinery rather than replacing it.
The second difference sits on the CPU. LMSYS wrote in its SGLang v0.4 post that an unoptimised engine can spend up to half its time on CPU work such as batch scheduling, memory allocation and prefix matching. SGLang’s overlap scheduler runs one batch ahead and prepares the next batch’s metadata while the GPU computes, which hides costs like radix cache operations. LMSYS checked this in Nsight Systems and showed five consecutive decode batches with no GPU idle time. It also noted that the profile used the Triton attention backend, and that a small gap still showed with FlashInfer. That caveat is a reason to check your own backend’s timeline before assuming the scheduler adds no overhead.
Scheduling Policies, and When LPM Hurts the Tail
SGLang’s scheduling-policy module offers cache-aware policies and cache-agnostic ones. The cache-aware ones are LPM (longest prefix match), which puts requests with longer cached prefixes first, and DFS-Weight, which uses depth-first weighting to maximise reuse. The cache-agnostic ones are FCFS, longest-output-first, random and routing-key. The official tuning guide suggests --schedule-policy lpm for workloads with many shared prefixes, and warns that LPM adds scheduling overhead.
Experiments on SGLang v0.4.1 with Llama-3.1-8B on eight A100s found that FCFS does better at low request rates and LPM does better at higher ones. In that study, LPM consistently gave the lowest median TTFT. When the shared prefix is a small part of each prompt, though, FCFS gives lower high-percentile TTFT, because no request sits in the queue for too long. Those authors built a variant, k-LPM, as an extension to SGLang; plain LPM and FCFS are stock policies. With short shared prefixes, LPM’s good median can hide a bad p99.
Why the Headline Tokens-per-Second Figure Hides p95
SGLang’s benchmark tools answer different questions. bench_offline_throughput creates the engine in-process and submits every request at once, which measures the maximum achievable throughput with no network overhead. bench_serving sends requests at controlled rates to a running server and reports TTFT, TPOT, inter-token latency and throughput. The maximum-throughput figure comes from the first kind of test. Realistic online serving latency comes from the second.
Published speedups need the same care. The SGLang paper reports up to 6.4× higher throughput and up to 3.7× lower latency. They are ‘up to’ figures, and the authors attribute them partly to KV cache reuse. Three things widen the gap between a headline figure and a tail:
- Queueing. Nexus (2025) found that waiting time dominates total latency under load.
- Prefill-decode interference. In the same study, raising the prefill KV length from 2,000 to 10,000 tokens made an identical decode batch 36% slower, because of memory bandwidth contention. Mixed chunked-prefill batches ran 8× to 10× slower than prefill-only or decode-only batches.
- Metric scope. SGLang’s TTFT runs from request creation in the API server to the first token, and for streaming requests that first output may contain no printable text.
sglang:request_time_per_output_token_secondsleaves out the first token and is recorded once per finished request, and it skips aborted requests and PD prefill workers.
Reading Prefill and Decode Separately in a Profiler
Prefill processes the whole prompt in one forward pass. It is usually compute-bound and sets TTFT. Decode produces one token per request per step, has to read the model weights and the whole KV cache each time, is limited by memory bandwidth, and sets the time between tokens. Preble’s profiling of Mistral 7B on an A6000 found that prefill time grows roughly linearly with prompt length, so the more of a prompt the prefix cache serves, the lower prefill time is.
RadixAttention reduces prefill computation and so lowers first-token latency. After a month of serving, the SGLang authors measured cache hit rates of 52.4% for LLaVA-Next-34B and 74.1% for Vicuna-33B, and the Vicuna hit rate cut first-token latency by an average of 1.7×.
SGLang ships several ways to see this:
- The PyTorch Profiler shows kernel execution time, call stacks, overlap and occupancy. Traces open in Perfetto or
chrome://tracing, and you can shrink oversized traces by limiting prompt count and length. - Layerwise NVTX annotations combined with Nsight Systems give per-layer timing. NVTX markers are not emitted for kernel launches captured by CUDA graphs, so you need
--disable-cuda-graphto see every marker. With graphs off you are profiling a slightly different decode path from the one production runs, so take launch-overhead conclusions from a graphs-on trace. --enable-profile-cuda-graphprofiles the CUDA graph capture, and it covers only the decode graph runner.- For TP, DP, PP and SGLang expert-parallel setups, SGLang can merge profiling traces from all ranks automatically.
On the metrics side, sglang:realtime_tokens_total breaks token counts down by mode (prefill_compute, prefill_cache and decode), and sglang:per_stage_req_latency_seconds breaks latency down by internal stage. The first gives the token split between prefill and decode before you open a trace. Our broader guide to profiling AI inference and reading its numbers covers the tooling beyond SGLang. For kernel-level work, see occupancy and bandwidth analysis for GPU kernels.
Which SGLang Metrics Show Whether It Is Tuned for Your Workload
SGLang exposes Prometheus metrics at /metrics when metrics are enabled. Under steady full load, the server log also prints a decode-batch line with running requests, token usage, CUDA graph status, generation throughput and queue depth. The table below is a health check. Only the first two rows come with thresholds from the official guide.
| Signal | Where | How to read it |
|---|---|---|
token usage / sglang:token_usage |
Log line, gauge (0.0 to 1.0) | Above 0.9 means good KV cache utilisation |
#queue-req / sglang:num_queue_reqs |
Log line, gauge | A frequent 0 means the client is sending requests too slowly; the guide’s healthy range begins at 100 |
sglang:cache_hit_rate |
Gauge (0.0 to 1.0) | No universal target; set it against how much prefix your traffic shares |
sglang:cached_tokens_total vs sglang:prompt_tokens_total |
Counters | Their windowed ratio gives a hit rate over a period you choose |
sglang:time_to_first_token_seconds |
Histogram | Prefill plus queueing; its buckets give p95/p99 through histogram_quantile |
sglang:time_per_output_token_seconds |
Histogram | Decode health, first token excluded |
sglang:queue_time_seconds |
Histogram | Admission delay, separate from compute |
sglang:estimated_flops_per_gpu_total, read/write bytes |
Counters (needs --enable-mfu-metrics) |
MFU-related signals for compute-bound vs bandwidth-bound |
Handle the hit-rate gauge with care. A gauge is a point-in-time value. We would chart the counter ratio over a window and treat the gauge as a spot check. We read the research figures as a range, not a target. Across the SGLang paper’s benchmarks hit rates ran from 50% to 99%, and cache-aware scheduling reached 96% of the optimal hit rate on average. Workloads whose prompts share little prefix gain little from RadixAttention. Our explainer on where a radix cache cuts LLM inference latency covers what decides which case you are in.
When a Config Change Captures the Win, and When the Model Has to Change
Change an SGLang setting only after the metrics have named the bottleneck that setting controls. That follows a position we hold generally: optimisation choices only make sense in context, and the context comes from profiling, not from rules of thumb.
| Symptom in metrics or log | What it means | Lever |
|---|---|---|
Token usage often below 0.9 while #queue-req > 0 |
Scheduler too conservative about admitting work | Lower --schedule-conservativeness, e.g. to 0.3 |
| Token usage very high, “KV cache pool is full. Retract requests” warnings | Scheduler admitting too aggressively | Raise --schedule-conservativeness, e.g. to 1.3 |
| KV cache pool too small for the batch you need | Static memory split between weights and KV pool | --mem-fraction-static sets (weights + KV pool) as a share of GPU memory |
| Many shared prefixes, low hit rate | Request order is not favouring cache hits | Try --schedule-policy lpm, then check p99 TTFT |
| Low hit rate across replicas with shared prefixes | Router is ignoring cache locality | Cache-aware routing; LMSYS reported in its SGLang v0.4 post 1.9× throughput and hit rate rising from 20% to 75% on its own benchmark |
| Mixed prefill/decode interference inflating decode latency | Both phases contending on one GPU | Prefill-decode disaggregation through OME; LMSYS’s OME post claims 2.5× throughput for mixed workloads |
Once those rows are clean, we would look at the model or the hardware next. The same logic runs the other way: if p95 TTFT is mostly queue time, swapping the model leaves the queue where it was. Comparing accelerators is a measurement question in its own right, and needs results from controlled runs, not runtime defaults.
How to Attribute Cost per Request to SGLang’s Scheduling Stages
SGLang’s exported metrics include no cost-per-request metric or per-stage cost split. What you can build is a derived split from the counters SGLang does export. Use it as an estimate, not an accounting record.
- Take the GPU-seconds the engine actually used from
sglang:gpu_execution_seconds_total, labelled by forward-mode category, over a fixed window. - Split work between computed prefill, cache-served prefill and decode with
sglang:realtime_tokens_totalby mode. - Divide each share by
sglang:num_requests_totalfor the same window to get average GPU-seconds per request per phase. - Multiply by what you pay per GPU-second on that node. This is arithmetic on your own bill, with nothing assumed about prices.
- Keep
sglang:queue_time_secondsseparate: it measures time requests spend waiting in the queue, not GPU execution.
LLMVisor (2026) models batch latency as a linear function of per-request terms (tokens processed, context tokens loaded, a quadratic attention term), so it can split a batch’s latency additively across requests. Its authors report average prefill relative errors of 0.02 at p90 and 0.09 at p99, against 0.05 and 0.30 for the VTC baseline. LLMVisor is a research model that works at the scheduling stage.
Turning these phase shares into a KPI you can manage is the subject of our load-aware cost-per-request model for inference. For how OME’s choices move cost per request at the deployment level, see SGLang OME and inference cost per request. Teams that run inference as their product face this attribution problem on every release, which is the setting of our AI infrastructure and SaaS work. The open question is how well a derived split holds up under your traffic mix. Check it against a profiler trace at least once before you base a roadmap on it.
FAQ
Is SGLang Open Source?
The runtime’s source, including the scheduler in python/sglang/srt/managers/scheduler.py and the radix cache in python/sglang/srt/mem_cache/radix_cache.py, is public in the SGLang repository.
Where Did SGLang Originate?
The SGLang authors introduced the runtime and RadixAttention. They found that existing systems handled KV cache reuse poorly in programs that make several LLM calls. The accompanying paper presents SGLang as a domain-specific language embedded in Python, with a runtime that executes its programs.
What Is Prefill?
Prefill is the first forward pass over all input tokens, before output tokens are decoded one at a time. It produces the KV cache that decoding then reuses.