#302Little's LawEasy

Little's Law

Background

Little's Law (L=λWL = \lambda W) 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:

L  =  λWL \;=\; \lambda \cdot W

where LL = concurrency, λ\lambda = throughput (req/s), WW = latency (s).

Input

  • throughputfloat > 0 or None. Steady-state arrival/serving rate in req/s.
  • latencyfloat > 0 or None. Average time in system, in seconds.
  • concurrencyfloat > 0 or None. 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: L=1000.05=5L = 100 \cdot 0.05 = 5 — 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. Lq=λWqL_q = \lambda W_q for the queue alone (excluding service). The same identity, different stage.
Python
Loading...

▶ 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