Simulate systems over timeLesson 41 of 76 · 9 min

A queue remembers earlier arrivals

Compute waiting times using arrival and service timelines.

A queue’s wait is not just its service duration. A customer may arrive while earlier work still occupies the server. For one first-come-first-served server, service starts at the later of the arrival time and the previous completion.

Each row is one sequence of one hundred customers, initially empty. Inter-arrival time is the gap between arrivals. With arrival rate λ and mean service work m, arriving work per time unit is λm. One server has capacity 1; if λm exceeds 1, backlog grows on average. The example starts below that load.

A steady state is a distribution of queue conditions that no longer changes with time; it requires stability and is not guaranteed by a finite run. At arrival rate 1.1 and mean service time 1, arriving work exceeds capacity. Compare longer horizons, keeping initial state and unfinished work explicit. Waits within a trace share queue state, so use independent trace summaries for error estimates.

For customer i, aia_i is arrival time, viv_i service duration, sis_i start time, fif_i finish time and wiw_i wait. The previous customer's finish is fi−1f_{i-1}.

A customer inherits earlier work
  1. Arrival
    aia_i
  2. Service can start
    si=max⁡(ai,fi−1)s_i=\max(a_i,f_{i-1})
  3. Finish and wait
    fi=si+vi,wi=si−aif_i=s_i+v_i,\quad w_i=s_i-a_i
Reference illustration. One trial is an entire queue of customers. The current customer waits for unfinished earlier service; customer readings within a path are not independent queue experiments.

Can waiting increase even when the service-time distribution stays unchanged?

Write a prediction (optional)

Seeded teaching simulation

Select Run Python below with the code unchanged.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

Published example output

This result comes from the original Python. Your runs appear above. Build environment ↗

Mean customer wait (minutes): 3.054
P(customer wait > 5 minutes): 0.2201
Mean of final customer's wait: 3.619

Read the first result

Customers within one trace share queue state and are not independent samples. Use independent trace summaries for a run-level uncertainty calculation.

Try an edit

Replace arrival_rate, service_mean = .8, 1.0 with arrival_rate, service_mean = 1.1, 1.0 and run. Then replace trials, customers = 1000, 100 with trials, customers = 1000, 300. Select Run Python again. Compare Mean of final customer's wait at the longer and shorter horizons. The short run begins with an empty queue. Why can it understate how long overloaded queues will make later customers wait?

Back to the Python editor

Scope. This is a finite single-server model with exponential arrivals and services, not a calibrated staffing recommendation.

Try a fresh case

Why are successive waiting times in one queue trace usually dependent?

Choose an answer
Need a hint?
Hint 1

Track the previous completion time.

Hint 2

Ask what a slow service leaves for the next customer.

Your notes