Week 09 · Continuous-time Markov chains and queues

Relate high utilization to long waits in a single-server system.

← Week 8 · Subject contents · Week 10 →

Relate high utilization to long waits in a single-server system.

Work through the problem

In an M/M/1 queue, Poisson arrivals occur at rate λ and exponential service completes at rate μ while the server is busy. The number in the system is a birth-death chain. In equilibrium πₙ₊₁ μ = πₙ λ. Summing the geometric series gives πₙ = (1−ρ)ρⁿ for ρ = λ/μ < 1.

Mean number in the system is ρ/(1−ρ), so mean sojourn time from Little’s law is 1/(μ−λ). Subtract 1/μ to obtain mean queue wait. With μ = 10 jobs/hour, increasing λ from 5 to 9 raises mean queue wait from 0.1 to 0.9 hours.

Run the Python lab

import numpy as np
def run(rate, seed):
    rng = np.random.default_rng(seed)
    arrivals = rng.exponential(1/rate, 120000).cumsum()
    service = rng.exponential(.1, len(arrivals))
    end = 0
    waits = []
    for arrival, duration in zip(arrivals, service):
        start = max(end, arrival)
        waits.append(start-arrival)
        end = start + duration
    return np.mean(waits[3000:])
for rate in [5, 9]:
    theory = 1/(10-rate)-.1
    estimate = run(rate, 102+rate)
    print(rate, f"theory {theory:.3f}, simulation {estimate:.3f}")
    assert abs(estimate-theory) < .15

Output from the lab

5 theory 0.100, simulation 0.100
9 theory 0.900, simulation 0.921

Practice

  1. What fails at λ = μ?

Check your reasoning

  1. The stationary geometric series cannot be normalized. The finite-run average does not estimate a finite steady-state mean wait.

← Week 8 · Subject contents · Week 10 →

Further reading · MIT 6.262 · Discrete Stochastic Processes