Little's Law
Background
Little's Law () is the universal identity of queueing systems: the average number of items in a stable system equals the average arrival rate times the average time each spends in the system. For ML serving it directly answers "how many concurrent requests do we need to support X QPS at Y latency?" — and any one variable is solvable given the other two.
Problem statement
Implement littles_law(throughput=None, latency=None, concurrency=None). Exactly one of the three must be None. Solve for it via:
where = concurrency, = throughput (req/s), = latency (s).
Input
throughput—float > 0orNone. Steady-state arrival/serving rate in req/s.latency—float > 0orNone. Average time in system, in seconds.concurrency—float > 0orNone. Average number of inflight requests.
Output
Returns a Python float — the value of whichever variable was None.
Examples
Example 1 — solve for concurrency
Input: throughput=100, latency=0.05
Output: 5.0
Explanation: — five inflight requests at any time.
Example 2 — solve for latency
Input: throughput=100, concurrency=5
Output: 0.05
Example 3 — solve for throughput
Input: latency=0.05, concurrency=5
Output: 100.0
Constraints
- Exactly one of the three args is
None. ValueError otherwise. - All given values must be positive.
- Return a plain Python
float.
Notes
- System must be stable. Little's Law assumes a steady state — arrival rate equals departure rate over the measurement window. It does not apply during a traffic spike or while warming up.
- Capacity planning. Multiply by a safety margin (1.5–2×) when sizing: peak/avg ratio for online traffic is rarely 1.
- Variant. for the queue alone (excluding service). The same identity, different stage.
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example: solve for concurrency
- •Reference: solve for latency
- •Sample: solve for throughput