Sizing a Serving Cluster End to End
Putting Little's law, the KV-cache budget and the utilisation wall together into a single sizing formula, and reading off which constraint actually binds.
The three constraints
Fix a replica and a request profile. Write:
- — bytes of device memory left for KV cache after weights and workspace;
- — KV bytes for one resident sequence at its expected length;
- — the fraction of the cache actually usable, after fragmentation;
- — mean end-to-end request latency, the quantity the SLO constrains;
- — offered load in requests per second for the whole service;
- — the target utilisation, chosen from the utilisation wall.
The number of requests a replica can hold concurrently is at most
To serve offered load at mean latency while keeping each replica at utilisation , the number of replicas required is
Key idea
Every term in that formula is measurable, and each one is a lever:
| Lever | Effect on | How |
|---|---|---|
| linear | shorter contexts, grouped-query attention, KV quantisation | |
| inverse | paged allocation instead of contiguous reservation | |
| inverse | smaller weights (quantisation), bigger device | |
| linear | faster decode, less queueing | |
| inverse | accept a worse tail |
Note that and are not independent: raising raises through the factor, so pushing utilisation up buys less than the formula suggests when read naively.
Working an example
Take a replica with GB of spare memory, a request profile whose expected KV footprint is MB, and paged allocation giving . Then
With mean latency s and target utilisation , one replica sustains requests per second. Serving requests per second needs
Now change one thing. Halving — by quantising the KV cache to 8 bits — doubles to and halves to . Halving does the same. Raising from to reduces to if stayed fixed, but does not stay fixed: by the utilisation wall the queueing component grows by a factor , and unless queueing was a small part of to begin with, the change is a net loss.
Which constraint binds
There is a second ceiling on concurrency, from compute: the batch size at which decode stops being weight-bound. Call it . The replica's effective cap is , and:
- if the replica is memory-bound — buy KV capacity, not FLOPs;
- if it is compute-bound — a bigger cache buys nothing.
By the decode arithmetic in Inference Arithmetic and the Roofline, arithmetic intensity in weight-limited decoding is for batch and bytes per parameter, so is roughly the batch at which reaches the hardware's compute-to-bandwidth ratio. For a machine with ratio and , that is . A replica whose memory allows only concurrent sequences is therefore firmly memory-bound, and its idle arithmetic units are not a bug to be tuned away — they are the direct consequence of the KV budget.
What this does not say
This treats and as single numbers. Both are distributions, and by the Pollaczek–Khinchine formula their variance affects queueing independently of their means. A profile mixing 200-token and 20,000-token contexts has an whose mean badly misrepresents the memory behaviour, because a handful of long sequences can consume the budget that the mean says should hold dozens. Sizing on means and then operating on a mixed workload is a standard way to discover the tail the hard way.
References
- PaperR. Pope et al. (2022). Efficiently Scaling Transformer InferencePartitioning and batching analysis for transformer serving, consistent with the arithmetic used here.
- PaperW. Kwon et al. (2023). Efficient Memory Management for Large Language Model Serving with PagedAttentionShows how much of the nominal KV budget is lost to fragmentation, quantified here as the utilisation factor of the cache.
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- PropositionThe memory ceiling on concurrencyproof includedA replica's KV-cache budget divided by the per-sequence cache size is a hard cap on how many requests it can hold at once.
- PropositionMaximum throughput of one replicaproof includedCombining the memory ceiling with Little's law bounds a replica's throughput by its concurrency cap divided by request latency.
- TheoremThe sizing formulaproof includedThe replica count needed is offered load times latency, divided by the product of the concurrency cap and the target utilisation.
- CorollaryWhich constraint bindsproof includedComparing the memory-limited and compute-limited concurrency caps says whether to buy memory, buy FLOPs, or shorten requests.