Size concurrency with Little's law

Why it matters Sizing an LLM endpoint's batch slots and replicas starts with this one line.

Little's law says the average number of requests in a system equals arrival rate times time in system.

Write needed_concurrency(rps, mean_latency_s, slots_per_replica). Return (in_flight, replicas) where in_flight = rps * mean_latency_s and replicas = ceil(in_flight / slots_per_replica).

Signaturedef needed_concurrency(rps, mean_latency_s, slots_per_replica)

Example

needed_concurrency(20, 3.0, 16) is (60.0, 4).

Understand the idea

Little's law is a simple rule for any queueing system: the average number of items inside equals the arrival rate times the average time each item spends inside. Think of a dhaba: if 10 customers arrive per minute and each stays 3 minutes, about 30 are seated at any time. For an LLM API, it tells you how many requests are in flight at once, and so how many servers you need. Worked example: 50 requests per second, mean latency 1.2 seconds, 8 concurrent slots per replica. In flight = 50 * 1.2 = 60 requests. Replicas = ceil(60 / 8) = ceil(7.5) = 8. Rounding down to 7 would give only 56 slots, so requests would queue. Rule: in_flight = rps * mean_latency_s; replicas = ceil(in_flight / slots_per_replica); return both, with in_flight as a float. Mean latency must include the full time in the system, not just compute time. Used in: capacity planning for model servers, sizing vLLM batch slots, and autoscaling targets.

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

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

  • Sample 1: exampleneeded_concurrency(20, 3.0, 16)
  • Sample 2: exactneeded_concurrency(10, 1.6, 16)
  • Test 3: smallneeded_concurrency(0.5, 4.0, 8)