Mental Models204 cards · 12 fields

Mental Models/Computing & Information

Queueing Theory

排队论

When things are almost too busy, a few more people make the line frighteningly long.

In the fall of 2021, out at sea off the Port of Los Angeles, container ships dropped anchor one after another to wait for a berth. The docks hadn't stopped, but imports had surged, and trucks and warehouses were stretched too: before one load had been hauled away, the next ships had already arrived. On October 13, Biden announced at the White House that the Port of Los Angeles would switch to working around the clock, using longer hours to handle more cargo.

An office has one service window. Each person takes one minute on average, so at most 60 people an hour can be served. People arrive at random, and some take longer than others. By queueing theory, when 30 people come an hour, the window sits idle half the time; you can be served almost as soon as you arrive, and the average wait is just one minute. On a busy day, arrivals go up to 54. That's only 80% more people, but the window is now busy 90% of the time, the average wait is nine minutes, nine times as long as before, and there are often eight or nine people in line.

At 90% busy, the average wait is 9 minutes
051015200%20%40%60%80%Window busyAverage wait (minutes)Times varyExactly 1 minute9 minutes
010200%25%50%75%Window busyAverage wait (minutes)Times varyExactly 1 minute9 minutes

One minute per person on average. 50% busy: a 1-minute wait; 80%: 4 minutes; 90%: 9. If each takes exactly a minute, the same busyness halves the wait.

At 80–90% busy, the wait multiplies

The window takes minutes per person on average, and the share of time it is busy is . Take the simplest setup: people arrive at random and independently of each other, service times vary, whoever comes first is served first, and nobody leaves the line partway. The average time spent in line is:

The busy share divided by the idle share, times each person's service time. In this setup, when you arrive there are on average people at the window, counting the one being served. You wait through them one by one, which comes to that many . With one minute per person:

Window busy Average wait in line
50% 1 minute
80% 4 minutes
90% 9 minutes
99% 99 minutes

When service times vary, the same busyness means a longer wait

At the same 90% busy, if everyone took exactly one minute, the average wait in line would be only 4.5 minutes, half of 9. When someone takes ten minutes, everyone who arrives in the meantime piles up behind them. When someone finishes early and nobody is waiting, the window sits empty, and that idle time can't be saved up to make up for a long job later.

The less spare capacity, the slower a backlog clears

The window can serve 60 people an hour. When 48 come, it can still serve 12 more an hour; that is the spare capacity. If 6 extra people suddenly show up, they are cleared in half an hour. When 57 come, the spare capacity is only 3 people an hour, and the same 6 people take two hours to clear.

A single window, random arrivals, first come first served: that kind of line fits this curve best. In systems where customers leave after waiting too long, the formula will put the wait too high, because once impatient people leave, the line gets shorter. Treating "80% busy" as a safety line that holds everywhere is a mistake. How much slack to leave depends on how irregular arrivals and service times are, and how long you are willing to let people wait.

Design
Set staffing for each shift on a customer service line: from the number of calls at peak hours and the average length of a call, work out how many agents you need so that the average wait before a call is answered is no more than a minute.
Predict
Estimate how much longer callers will wait to get through if calls rise 10% next month: look at which part of the curve you're on now, rather than just adding 10%.
  1. What share of the time is the window for this line busy? Have I measured both how fast people arrive and how long each person takes?
  2. In the busiest hour, how many times the average number of people arrive? How much of the service time do the few longest jobs take up?
  3. For the backlog I need to work through, is there enough spare capacity to clear it before the next wave arrives?

Transportation

Full runways: one gust and the day runs late

For years, London Heathrow's two runways have been used at around 98% of the airport's yearly flight limit. Flights always arrive a bit earlier or later than the timetable says, and each plane holds the runway for a different length of time. A strong gust of wind, or one plane holding up the runway, pushes back every takeoff and landing behind it, and the delays roll on until that evening before they clear.

Personal life

The homework piles up

You set aside two hours each evening to grade your students' homework, and over a week the work averages exactly two hours. On two days one class hands theirs in late, and it all comes at once. The extra work spills into the next day, and the next day's work is buried under new homework. Three weeks later you always have a stack of ungraded work at hand, and by the time students get their homework back, two weeks have gone by.

Health care

Once 85% of the beds are full

In 1999, Bagust and colleagues published a study of hospital beds in the British Medical Journal. Using random simulation, they built an imaginary emergency hospital in England, where emergency patients were admitted at random and stayed for different lengths of time. Once average bed occupancy passed 85%, the risk of having no bed for an emergency patient began to appear; above 90%, bed shortages became routine, with a bed crisis every so often.

Queueing TheoryMarginal ThinkingTo decide on one more step, weigh only what that step adds in gain and cost.You run a medical imaging department, and the machines are already booked to 90%. Sales wants to take on a batch of scans referred from other hospitals. Marginal thinking does the sums for this one order: the machines are running anyway, one more scan costs almost nothing, so take it. Queueing theory does the sums for everyone: a few points busier, and every patient's average wait doubles, so the income from the new orders has to be weighed against the cost of the existing patients' extra waiting. Which sums to go by depends on whether waiting in this department has a price.Queueing TheoryGoodhart's LawOnce a number becomes a target, people chase the number and it stops telling the truth.Head office makes equipment utilization a performance target, so the plant manager fills the schedule to the brim. Goodhart's law sees the number being made to look good; queueing theory sees that once the schedule is full, every order's wait multiplies. Keep tracking utilization, but judge people on delivery times and waiting.Queueing TheoryStocks and FlowsAs long as more comes in than goes out, the pile grows, day by day.A line is a stock: people arriving are the inflow, and people served are the outflow. When the line grows, don't just count the people in it; look at whether the inflow is faster than the outflow all the time. If it is faster all the time, the line won't go back down; if it is only faster now and then, and there is enough spare capacity, the line slowly clears.

A tourist site has two ticket gates. Each gate can check 30 people an hour, and some checks take longer than others. Visitors arrive at random, 54 an hour in all. Right now each gate has its own line; visitors pick a line when they arrive and don't switch. The site is thinking of switching to one snaking line, where the next person goes to whichever gate is free. Arrivals and checking speed stay the same.

With one shared line, what is most likely to happen to visitors' average wait?

You take over a car repair shop. Cars are first inspected, then painted, and there is a line in front of each step. The inspection bay can handle 20 cars an hour, and on average 19 arrive each hour. The paint booth can handle 40 cars an hour, and the same 19 an hour come through. The budget only covers speeding up one step, raising its speed by 20%.

Which step should you speed up to cut more of customers' total wait from arriving to finished paint?

A lawyer offers consultations every afternoon, booking one client every 30 minutes, and clients all arrive on time. Half the consultations take 8 minutes and half take 40, for an average of 24 minutes, shorter than the gap between bookings.

Over an afternoon, what is the clients' waiting most likely to look like?