What happens to a queue when service times have wild outliers?¶
Some data have extreme values on both sides, and the Cauchy distribution is the standard model of that. It has no mean at all. The script runs the same bench five times with a Cauchy service and with a tight normal one centred on the same minute.
from nagasim import build as nb
def mean_waits(service, seeds):
waits = []
for seed in seeds:
m = nb.Model(time_limit=2000, warmup=0)
m.add_resource(name="Bench")
m.create(distribution=nb.Exponential(rate=0.5)) >> m.process(
resource_name="Bench", distribution=service) >> m.dispose()
waits.append(m.run(seed=seed).kpi("resource/Bench/Time in Queue Avg"))
return " ".join(f"{w:7.1f}" for w in waits)
# Both services centre on 1 minute. Cauchy has no mean, so the average over a run never settles: one
# extreme draw ties up the bench for hours. A negative Cauchy draw is cut to 0 with a warning.
seeds = range(1, 6)
print("mean wait over five runs, one per seed (minutes):")
print(" Cauchy(x0=1, gamma=0.1) ", mean_waits(nb.Cauchy(x0=1, gamma=0.1), seeds))
print(" Normal(1, 0.15) ", mean_waits(nb.Normal(mean=1, stddev=0.15), seeds))
Save it as recipe-wild-outliers.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.
mean wait over five runs, one per seed (minutes):
Cauchy(x0=1, gamma=0.1) 2.8 33.1 12.5 14.9 0.6
Normal(1, 0.15) 0.5 0.5 0.5 0.4 0.5
How it works¶
Cauchy(x0, gamma)has a location and a scale but no finite mean, so the average over a run never settles.- A negative draw is cut to 0 with a warning, and one very large draw ties up the bench for a long time.
- Five runs give waits from under a minute to over thirty, while the normal service gives half a minute every time.
Elements used¶
Back to all recipes.