Size prefill and decode pools for disaggregated serving

Why it matters Splitting prefill and decode onto separate pools is a common way to meet both first-token and per-token latency targets, and sizing each pool is the first planning step.

Disaggregated serving runs prompt processing (prefill) and token generation (decode) on separate GPU pools, because the two phases stress the hardware differently. Each pool is sized from its own token load.

Write size_pools(req_per_s, prompt_tokens, output_tokens, prefill_tps, decode_tps, max_util). Prefill load is req_per_s * prompt_tokens tokens per second; decode load is req_per_s * output_tokens. One prefill GPU handles prefill_tps tokens per second and one decode GPU handles decode_tps, but each GPU should run at most max_util of its capacity (for example 0.8). Return (n_prefill, n_decode), each the smallest integer count that keeps utilization at or below max_util, and at least 1. Treat values within 1e-9 of an integer as that integer before rounding up.

Signaturedef size_pools(req_per_s, prompt_tokens, output_tokens, prefill_tps, decode_tps, max_util)

Example

10 req/s, 1000 prompt tokens, 200 output tokens, prefill 5000 tok/s, decode 1000 tok/s, max_util 0.8 gives (3, 3).

Understand the idea

A restaurant can split its staff into prep cooks and line cooks, because chopping and plating are different jobs that peak differently. LLM serving does the same: prefill reads the whole prompt in a big, compute-heavy burst, while decode produces one token at a time and is limited by memory speed. Worked example: 10 requests per second with 1000 prompt tokens is 10,000 prefill tokens per second. A prefill GPU does 5000 but you only want it 80 percent busy, so it gives 4000 usable. 10,000 / 4000 = 2.5, so 3 GPUs. Decode: 2000 tokens per second over 800 usable is 2.5, so 3. Rule: n = ceil(load / (capacity x max_util)), at least 1. Headroom below 100 percent keeps queues short so latency stays stable during bursts.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 4.

  • Sample 1: examplesize_pools(10, 1000, 200, 5000, 1000, 0.8)
  • Sample 2: exact fitsize_pools(8, 500, 100, 5000, 1000, 0.8)
  • Test 3: tiny loadsize_pools(0.1, 100, 50, 20000, 3000, 0.9)
  • Test 4: decode heavysize_pools(4, 300, 2000, 10000, 1500, 0.75)