Skip to content
nonconvexcard

Simulate M/M/1 and verify the utilisation wall

CodingIntermediate⏱ 1 hourAI Systemssimulationqueueinglittle's lawutilisation

Problem

Implement the closed forms for M/M/1 and a discrete-event simulation of the same queue, then check they agree.

  1. theoretical_mm1(lam, mu) returning ρ\rho, E[W]\E[W], E[Wq]\E[W_q] and E[N]\E[N].
  2. simulate_mm1(lam, mu, n_requests, seed) returning the same four quantities measured from a first-come-first-served simulation.

Measure E[N]\E[N] from the simulation independently — as the time-average occupancy — rather than computing it as λE[W]\lambda\E[W]. Little's law should then fall out of the measurements as a check, instead of being assumed.

Implement it, then check the implementation against something you can verify independently.

Write it

Solve it here8 tests · Python runs in your browser
⌘/Ctrl + ↵ to run · limit 90s · draft saved in this browser
8 tests will run against your code. The first run downloads the Python runtime — several megabytes, once per browser.

Hints

Hints — 0 of 2 revealed

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
Simulate distance contrast runClassical MLCodingBeginner30 min
Apply Little's law to a serving targetLLM OpsProofIntermediate30 min
Balls into bins, with one choice and with two runAI SystemsCodingIntermediate1 hour
Cache hit rates under Zipf popularity runAI SystemsCodingIntermediate1 hour
Derive the M/M/1 queue from detailed balanceAI SystemsProofIntermediate1 hour