Support Desk 4: Busy and Quiet Periods
Uses Only Free-Tier SpiceGrinder
Problem statement
Lessons 3.2 and 3.3 described a desk by one number, its load: customers arrive at some average rate and each takes a minute. A load of 65% sounds comfortable. Of every hundred minutes, the agent is idle for 35 of them. But an average says nothing about when the customers come. Real desks have a busy hour after a product release and a quiet stretch at lunch, and the same average can be delivered in very different ways.
This lesson keeps the average load fixed at 65% and changes only how the arrivals are spread in time. The questions:
- If customers arrive in busy stretches and quiet ones, how much longer do they wait than if they arrive steadily at the same average rate?
- How bad is the worst wait of a week, the one the agent remembers and the manager hears about?
- Does it matter how long a busy stretch lasts?
The first two are answered by running the desk both ways and comparing, and the third by changing one number. The model also has an exact answer for the waits, so we can check the simulation against it.
The model
A row is now a minute. In lessons 3.2 and 3.3 a row was a customer, and a customer row has no clock: nothing in it can count “a busy period of about 40 minutes”. So the model turns around and makes one row per minute. In each minute some number of customers arrive, the agent serves one, and the model keeps the backlog. The busy and quiet periods are held for a random number of rows with the pattern from lesson 2.4 (Pool + Switch, the same pattern as the stressed months of the cash runway, and as machine-reliability.xml), so the explanation is not repeated here. Briefly:
PeriodIndexandStateFlaggive a flag that alternates 0, 1, 0, 1: quiet, busy, quiet, busy. A run starts quiet;QuietLengthisGeometricwith p = 1/120: a quiet period ends each minute with probability 1/120, so it lasts 120 minutes on average.BusyLengthhas p = 1/40 and lasts 40 minutes on average;Periodis aSwitchthat picks the length by the flag, andRegimeis aPoolwithcountColumnthat repeats the flag once per minute of the period;QuietArrivalsisPoissonwith mean 0.5 customers a minute andBusyArrivalsisPoissonwith mean 1.1, which is more than the desk can serve (one a minute).Minuteis aSwitchthat takes one or the other by the regime;Deskis aRecurthat keeps the backlog Q, the customers waiting or in service:Q = max(0, Q + arrivals - 1). This is lesson 3.1’s backlog with a floor and lesson 3.2’s single agent, in a clock that ticks once a minute. The agent serves exactly one a minute, so this is exact for a desk with a one-minute service time.
The busy minutes are 40 out of every 160 on average, 25%, so the average arrival rate is 0.75 x 0.5 + 0.25 x 1.1 = 0.65 customers a minute. That is the load of 65%. Here is the model, samples/simulation/support-desk-busy-quiet.xml, ten nodes, seed 304:
<dataset columns="backlog, busy, arrivals" seed="304">
<root node="Desk"/>
<nodes>
<Sequence name="PeriodIndex" start="0" step="1"/>
<Calculate name="StateFlag" expression="y[0] = mod(x[0], 2)">
<input name="PeriodIndex"/>
</Calculate>
<Geometric name="QuietLength" p="0.008333333333333333"/>
<Geometric name="BusyLength" p="0.025"/>
<Switch name="Period" key="0">
<input name="StateFlag" role="input"/>
<input name="QuietLength" value="0"/>
<input name="BusyLength" value="1"/>
</Switch>
<Pool name="Regime" countColumn="1" interleave="1">
<input name="Period"/>
</Pool>
<Poisson name="QuietArrivals" lambda="0.5"/>
<Poisson name="BusyArrivals" lambda="1.1"/>
<Switch name="Minute" key="0">
<input name="Regime" role="input"/>
<input name="QuietArrivals" value="0"/>
<input name="BusyArrivals" value="1"/>
</Switch>
<Recur name="Desk" initial="0" expression="y[0] = max(0, s[0] + x[1] - 1)" resetEvery="10080" appendInput="true">
<input name="Minute"/>
</Recur>
</nodes>
</dataset>
The output has three columns: column 0 is the backlog Q after the minute, column 1 is the regime (1 = busy) and column 2 is the number of arrivals that minute. (Minute passes on the flag and the arrivals; the expression reads the arrivals as x[1], and appendInput keeps the two columns next to the backlog.)
The week. resetEvery="10080" empties the desk at the start of every 10,080th row, so each block of 10,080 rows is one independent week of the desk, starting empty on Monday morning. The regime does not reset: only the backlog does, so a busy period that spans the boundary carries on into the next week with an empty desk. A run of 20,160,000 rows is 2,000 weeks.
What “wait” means here. A customer has no row of their own, so the wait is derived from the backlog. A customer who arrives during a minute waits as many minutes as the backlog the previous minute left behind: at one customer served a minute, the customers ahead of you are your wait in minutes (it is 0 in the first minute of a week). Each minute counts once per arrival, so a minute with five arrivals weighs five times a minute with one. This is an approximation to the minute: customers who arrive in the same minute are not counted ahead of one another. Every wait quoted below is computed this way from columns 0 and 2.
The comparison. samples/simulation/support-desk-steady.xml is the same desk with the arrivals Poisson(0.65) in every minute: two nodes, seed 304, no regimes, and the same average load:
<dataset columns="backlog, arrivals" seed="304">
<root node="Desk"/>
<nodes>
<Poisson name="Arrivals" lambda="0.65"/>
<Recur name="Desk" initial="0" expression="y[0] = max(0, s[0] + x[0] - 1)" resetEvery="10080" appendInput="true">
<input name="Arrivals"/>
</Recur>
</nodes>
</dataset>
Its two columns are the backlog and the arrivals.
Hand check, with the model’s own seed (304). Rows 31 to 41 of the busy-and-quiet model contain the start of the first busy period. It is the quiet flag until row 32, and from row 33 the flag is 1 and the arrivals rise:
| Row | Backlog Q | Regime | Arrivals | Check: previous Q + arrivals - 1 (not below 0) |
|---|---|---|---|---|
| 31 | 1 | 0 | 0 | |
| 32 | 1 | 0 | 1 | 1 + 1 - 1 = 1 |
| 33 | 1 | 1 | 1 | 1 + 1 - 1 = 1 |
| 34 | 0 | 1 | 0 | 1 + 0 - 1 = 0 |
| 35 | 1 | 1 | 2 | 0 + 2 - 1 = 1 |
| 36 | 3 | 1 | 3 | 1 + 3 - 1 = 3 |
| 37 | 4 | 1 | 2 | 3 + 2 - 1 = 4 |
| 38 | 4 | 1 | 1 | 4 + 1 - 1 = 4 |
| 39 | 8 | 1 | 5 | 4 + 5 - 1 = 8 |
| 40 | 10 | 1 | 3 | 8 + 3 - 1 = 10 |
| 41 | 11 | 1 | 2 | 10 + 2 - 1 = 11 |
(grind --count 41 support-desk-busy-quiet.xml shows these.) The backlog goes up in the busy minutes by whatever arrives beyond the one served, and it comes down by one in each minute with no arrival, never below 0. Then the week boundary. At row 80,640, the end of the eighth week, the desk is holding 3 and the regime is still busy. Rows 80,641 to 80,643 are the next week:
| Row | Backlog Q | Regime | Arrivals | Check |
|---|---|---|---|---|
| 80,640 | 3 | 1 | 1 | last row of week 8 |
| 80,641 | 0 | 1 | 0 | the desk starts week 9 empty: 0 + 0 - 1 is below 0, so 0 (without the reset: 3 + 0 - 1 = 2) |
| 80,642 | 4 | 1 | 5 | 0 + 5 - 1 = 4 (without the reset, 6) |
| 80,643 | 3 | 1 | 0 | 4 + 0 - 1 = 3 |
(grind --count 80643 support-desk-busy-quiet.xml | tail -4.) For a different desk each time, leave the seed out: grind --no-seed --count 20160000 support-desk-busy-quiet.xml.
Each model was run once at 20,160,000 rows, 2,000 weeks, with the model’s own seed (304), and every week was measured separately: the average wait, the 95th percentile of the waits in the week, the share of customers who waited more than 30 minutes, and the longest wait of any customer in the week. Each model served about 13.1 million customers, roughly 6,550 a week.
Result: the same average load, six times the waiting
Averages over the 2,000 weeks, with the standard error over the weeks in brackets:
| Busy and quiet periods | Steady arrivals | |
|---|---|---|
| Average wait (minutes) | 3.57 (0.02) | 0.60 (0.001) |
| 95th percentile of the wait in a week (minutes) | 17.2 (0.1) | 2.98 (under 0.01) |
| Customers waiting more than 30 minutes | 0.87% | about 0 |
| Longest wait in a week, average (minutes) | 36.1 (0.2) | 8.7 (0.04) |
| Longest wait in a week, median / 95th percentile / largest | 34 / 57 / 92 | 8 / 12 / 17 |
Customers waited on average 3.6 minutes when the arrivals came in busy stretches and 0.6 minutes when they came steadily: about six times as long, from exactly the same average load. The 95th percentile went from 3 minutes to 17, and the longest wait of the week from 9 to 36. Here is one real week of each, week 2 of the 2,000 (picked from the first ten as the one whose worst wait, 36 minutes, is closest to the average of 36.1):
In the steady week the backlog is mostly 0 to 3 and never exceeds 12. In the busy-and-quiet week the backlog is near 0 for much of the time too, which is why the average load looks harmless, but when a busy period arrives it does not simply double the backlog: it builds it up, because the desk is receiving more than it can serve and every extra customer stays in the line. The close-up shows the worst of the week: an unusually long busy period of about 3.5 hours (the average is 40 minutes) in which the backlog climbs to 36, and then almost an hour to clear it again, because the desk can only work a backlog down in the minutes when fewer customers arrive than it can serve.
Over all 2,000 weeks the worst waits look like this:
A steady desk has a worst wait of 8 or 9 minutes in about half of the weeks and never more than 17. The busy-and-quiet desk has a typical worst wait of about 34 minutes (the median), one week in twenty has a worst wait of 57 or more, and the worst week of the 2,000 reached 92 minutes, an hour and a half. No one looking at the average load of 65% would expect any of that.
Check: do the numbers match the math?
The regime. In the 20,160,000 minutes, 24.94% were busy (batch standard error 0.07 percentage points, against the exact 25%); the 126,028 complete quiet periods averaged 120.1 minutes (standard error 0.3, exact 120) and the busy periods 39.89 (standard error 0.11, exact 40); the average arrival rate was 0.6497 a minute against 0.65 (the steady model: 0.6499).
The waits. The exact distribution of the wait is computable, because the regime and the backlog together form a Markov chain: what happens in the next minute depends only on the current regime (and so on the chance of switching, 1/120 from quiet and 1/40 from busy) and the current backlog (and on the Poisson arrivals of that regime). Starting from an empty desk and a regime drawn with its stationary odds (75% quiet), the chain gives the full distribution of the backlog minute by minute, so the exact share of customers who wait 0, 1, 2, … minutes, pooled over a week. It was computed for the first 3,000 minutes of the week exactly, with the rest taken at the state the chain had reached by then (it has settled by then). For the steady model the chain has one regime. Against the measured values for all customers of the 2,000 weeks (standard errors by weeks):
| Measured (SE) | Exact | Gap in SE | |
|---|---|---|---|
| Busy and quiet: average wait of a customer | 3.596 (0.022) | 3.604 | -0.37 |
| Busy and quiet: 95th percentile | 17 | 17 | |
| Busy and quiet: share waiting more than 30 min | 0.89% (0.03) | 0.89% | +0.10 |
| Steady: average wait of a customer | 0.603 (0.001) | 0.603 | -0.36 |
| Steady: 95th percentile | 3 | 3 |
The whole tail agrees as well, not just these. At 12 waiting times (0, 1, 2, 5, 10, 15, 20, 30, 40, 60, 80 and 100 minutes) the share of customers who wait longer matches the exact value for the busy-and-quiet model within 1.3 standard errors at each of the nine times where the exact share is at least 0.1%, and for the steady model within 1.4 at each of the four; for example, the share waiting more than 10 minutes is 11.58% measured against 11.61% exact, and the steady model’s is 0.01% against 0.01%. The average of 3.57 minutes in the table above is the mean of the weekly averages, a little lower than the 3.60 for all customers pooled, because the pooled figure weights each week by its number of customers.
The longest wait in a week has no simple exact value, so there it is the measurement that carries the weight. The first 200 weeks alone give 36.40 (standard error 0.76) and all 2,000 weeks 36.13 (0.23): the same within 0.4 standard errors. The steady model gives 8.57 (0.10) after 200 weeks and 8.73 (0.04) after 2,000.
What if the busy periods are shorter, or longer?
Everything above had busy periods that last 40 minutes and quiet periods of 120. Other desks have the same average load but different rhythms: busy a quarter of the time, with the busy stretch shorter or longer. To keep the average load, the busy share (25%) and the arrival rates (0.5 and 1.1) have to stay the same, so the quiet period must be three times the busy one. For busy periods of 20 minutes use quiet periods of 60: change the two Geometric nodes to p = 1/60 = 0.016666666666666666 and p = 1/20 = 0.05. For 80 minutes use quiet periods of 240: p = 1/240 = 0.004166666666666667 and p = 1/80 = 0.0125. Nothing else changes (and the busy share is still 25%, the average arrival rate still 0.65). Each variant was run for 2,000 weeks (20,160,000 rows each; they are not shipped, they are the sample with those two numbers edited, with seeds 3420 and 3480):
| Busy / quiet periods (minutes) | Average wait (SE) | Exact average wait | 95th percentile | Longest wait in a week, average (SE) | Largest in 2,000 weeks |
|---|---|---|---|---|---|
| steady (no periods) | 0.60 (0.001) | 0.603 | 3.0 | 8.7 (0.04) | 17 |
| 20 / 60 | 2.34 (0.01) | 2.340 | 11.1 | 26.4 (0.14) | 61 |
| 40 / 120 (the model above) | 3.57 (0.02) | 3.604 (pooled) | 17.2 | 36.1 (0.23) | 92 |
| 80 / 240 | 5.87 (0.05) | 5.837 (pooled) | 28.4 | 51.4 (0.36) | 139 |
(The exact column is the Markov chain’s average over all customers; the measured column is the mean of the 2,000 weekly averages, which is slightly lower, as above. The pooled measured values are 2.349, 3.596 and 5.941.)
Halving the busy periods to 20 minutes, at the same average load and the same busy share, takes the average wait from 3.6 minutes to 2.3 and the longest wait of the week from 36 minutes to 26; doubling them to 80 raises the average wait to 5.9 and the worst of the week to 51. All three are far above the steady desk. The longer a busy stretch lasts, the further the backlog can climb before the quiet minutes bring it down, so the same load is paid for with longer waits. The average load of 65% tells you nothing about any of this.
A note on the 80 / 240 run: it sits a little high against the exact values. The measured pooled mean wait is 5.94 against 5.84 (2.1 standard errors) and the share of customers waiting more than 30 minutes is 4.23% against 4.04% (2.3). In this run the busy periods happened to average 80.66 minutes (standard error 0.32, 2.1 above 80) and the quiet ones 241.1 (standard error 1.0): a run’s own busy and quiet stretches wander, and the longer the stretches, the less of them 2,000 weeks hold, so the estimate is noisier. It is the same run-length lesson as in lesson 3.3 at work; the 20 / 60 and 40 / 120 runs are within 1.0 and 0.4 standard errors of exact on the pooled mean.
The companion page lets you pick the busy-period length (20, 40 or 80 minutes) and compare the average wait, the 95th percentile and the worst wait of the week against the steady desk, from these runs.
In Pro, a Perturb component would replace the period machinery here (the index, the flag, the two lengths, Period and Regime), as noted in lesson 2.4.
What this gives you: a desk model with a clock, one row a minute, in ten nodes: busy and quiet periods from Pool and Switch with Geometric lengths, Poisson arrivals that depend on the period, and a Recur that keeps the backlog Q = max(0, Q + arrivals - 1) and empties it every 10,080 rows with resetEvery, so that a block of rows is one week; a way to read a customer’s wait from the backlog; and a comparison that isolates one thing, the clustering of the arrivals, at the same average load of 65%. Customers waited 3.57 minutes on average with busy and quiet periods against 0.60 when arrivals were steady (2,000 weeks each); the 95th percentile of the wait was 17 minutes against 3, and the longest wait of the week 36 minutes against 9, with the worst of the 2,000 weeks at 92 minutes against 17. The measured average wait agrees with the exact Markov-chain value (3.596 against 3.604, 0.4 standard errors; steady 0.603 against 0.603), and so does the whole tail. Busy periods of 20, 40 and 80 minutes at the same load give a longest wait of 26, 36 and 51 minutes.
The last lesson of Module 3, 3.5, is about an agent who takes breaks. The average share of time the agent is away is not what matters there: it is how the absences cluster, breaks that come in stretches against breaks spread evenly through the day. Writing that cleanly takes a component that moves between states by a transition table, and that is the Markov generator.