Simulating Systems (e.g., Queues)
Executing a single-server queue simulation
A first-come, first-served (FCFS) single-server queue can be simulated by moving from one arrival or service completion to the next. At each event, update the server and the people or jobs waiting. The resulting event history supports calculations of waits and server use over a clearly stated interval.
Process events in order
Keep an event clock, a waiting line, the server's busy or idle state, and the next scheduled arrival and completion. Advance the clock to the earlier event rather than stepping through every minute. If times tie, state a rule for processing simultaneous events.
An arrival finding an idle server begins service at once. Otherwise, it joins the end of the line. At a completion, give the server to the oldest waiting job; if no job waits, make the server idle. Record each service start before computing a wait.
Worked example
Suppose three jobs arrive at minutes 0, 3, and 6 and need 4, 2, and 3 minutes of service. The first runs from 0 to 4.
The second waits from 3 to 4, then runs to 6. The third starts at 6 and finishes at 9; the completion and arrival coincide, but there is no older waiting job.
The service starts are 0, 4, and 6. Their waiting times, each start minus its arrival, are 0, 1, and 0 minutes, so the mean wait for these three jobs is 1/3 minute. Each job's time in system also includes its own service duration.
Summarize the run
For the observation horizon from minute 0 to minute 10, count only work done inside that interval. The server is busy continuously from 0 to 9, or 9 minutes, so utilization is 9/10. If service crosses the horizon boundary, count only its in-horizon portion.
With stochastic arrivals or service durations, draw times from the stated model and repeat independent runs to describe simulation uncertainty. A finite run gives an estimate for its stated conditions; it does not establish an exact steady-state quantity.
One server is processing A from minute 0 to 4. B arrives at minute 1 and needs 2 minutes; C arrives at minute 5 and needs 1 minute. Under FCFS, when does C start service?
Mark Yourself Question
- Grab a piece of paper and try this problem yourself.
- When you're done, check the "I have answered this question" box below.
- View the solution and report whether you got it right or wrong.
A FCFS server observes jobs arriving at minutes 0, 1, and 7 with service durations 3, 2, and 2 minutes. The observation horizon is [0, 10]. Give each start time, the mean waiting time among these three jobs, and server utilization over the horizon.