FCFS: metrics and the convoy effect
Trace first come, first served on one CPU, measure how a long job delays short ones, and tell an idle CPU from waiting. CPU scheduling · Operating systems.
A short job can spend longer waiting than running. In first come, first served (FCFS), the CPU takes the waiting job that arrived earliest. Once a job starts, it keeps the CPU until its current work finishes. A short job arriving in the middle must wait its turn.
Serving jobs in arrival order
Start with one CPU and two of the jobs in the example below. H starts at time 0 and needs nine units of processor time. That stretch of work is its CPU burst. J arrives at time 2 and needs only one unit. H is still running, so J joins the ready queue, the line of jobs that have arrived and are waiting for the CPU.
At time 9, H finishes and J takes the CPU. J waited from time 2 to time 9, so it spent seven units waiting for one unit of work.
The example gives each job one known CPU burst and leaves out input, output and the time spent switching jobs. Jobs that arrive together join the queue in the order listed.
Four jobs: H arrives at 0 and needs 9 units, J arrives at 2 and needs 1, K arrives at 4 and needs 2, and M arrives at 5 and needs 1.
Three short jobs behind one long burst
Read the steps as text
- 4 processes share one CPU under first come, first served. The ready queue is shown before each dispatch, and a process's metrics fill in when it finishes.
- At t=0, H is the only process ready and runs 9 units until t=9. J, K and M arrive during the run; FCFS does not interrupt it. H finishes at t=9.
- At t=9, J heads the ready queue (J, K, M) and runs 1 unit until t=10. J finishes at t=10.
- At t=10, K heads the ready queue (K, M) and runs 2 units until t=12. K finishes at t=12.
- At t=12, M is the only process ready and runs 1 unit until t=13. M finishes at t=13.
- All 4 processes are finished at t=13, after 3 context switches. Response averages 5, waiting 5 and turnaround 8.25.
What the short jobs pay
In the full run, K and M arrive while H is still running. At time 9 the queue holds J, K, M in that order. J runs from 9 to 10, K from 10 to 12, and M from 12 to 13. This is the convoy effect. Several short jobs finish late because one long job was already ahead of them.
Follow J from arrival at 2 to first run at 9 to finish at 10. Those three clock readings tell us how long J waited and how long it spent in the system. Give each measurement a name before applying it to the other jobs.
| Measurement | How to read it for J |
|---|---|
| Completion time (CT) | J finishes at time 10. This is a clock reading. |
| Turnaround time (TAT) | From arrival to finish, 10 − 2 = 8 units. |
| Waiting time (WT) | J spends one of those eight units running, leaving 8 − 1 = 7 units waiting. |
| Response time (RT) | From arrival to first run, 9 − 2 = 7 units. |
The same measurements for the full run are below.
| Job | Arrival | Burst | First run | CT | TAT | WT | RT |
|---|---|---|---|---|---|---|---|
| H | 0 | 9 | 0 | 9 | 9 | 0 | 0 |
| J | 2 | 1 | 9 | 10 | 8 | 7 | 7 |
| K | 4 | 2 | 10 | 12 | 8 | 6 | 6 |
| M | 5 | 1 | 12 | 13 | 8 | 7 | 7 |
The average waiting time is (0 + 7 + 6 + 7) / 4 = 5. The average turnaround is (9 + 8 + 8 + 8) / 4 = 8.25. The averages summarize the run. J makes the effect concrete by spending most of its eight units in the ready queue.
In every row WT equals RT. Each job runs once without interruption, so all of its waiting happens before its first run. That is a property of this model, not of the definitions. When a policy can pause a job and resume it later, the job can wait again after it first ran, and the two numbers come apart.
Same jobs, different arrival order
Keep the four bursts but change who arrives first: J at 0, K at 1, M at 2, and the long job H at 3. FCFS runs J from 0 to 1, K from 1 to 3, M from 3 to 4, and H from 4 to 13. The waits are now 0, 0, 1 and 1, an average of 0.5 against 5 before. The average turnaround falls from 8.25 to 3.75.
The same jobs, the long one last
Read the steps as text
- 4 processes share one CPU under first come, first served. The ready queue is shown before each dispatch, and a process's metrics fill in when it finishes.
- At t=0, J is the only process ready and runs 1 unit until t=1. J finishes at t=1.
- At t=1, K is the only process ready and runs 2 units until t=3. M arrives during the run; FCFS does not interrupt it. K finishes at t=3.
- At t=3, M heads the ready queue (M, H) and runs 1 unit until t=4. M finishes at t=4.
- At t=4, H is the only process ready and runs 9 units until t=13. H finishes at t=13.
- All 4 processes are finished at t=13, after 3 context switches. Response averages 0.5, waiting 0.5 and turnaround 3.75.
The policy did not change; only the arrival order did. FCFS never looks at burst length, so it cannot correct for an unlucky order. The next lesson shows policies that do look.
When nobody is ready
Waiting and idling are different. Waiting is a job with no CPU. Idling is a CPU with no job. Take X arriving at 3 and needing 2, Y arriving at 7 and needing 3, and Z arriving at 7 and needing 1, with Y listed before Z. Nothing has arrived before t=3, so the CPU idles from 0 to 3; FCFS cannot run a job from the future. X runs from 3 to 5, and the CPU idles again from 5 to 7.
An empty CPU, then two jobs arriving together
Read the steps as text
- 3 processes share one CPU under first come, first served. The ready queue is shown before each dispatch, and a process's metrics fill in when it finishes.
- The CPU idled from t=0 to t=3. At t=3, X is the only process ready and runs 2 units until t=5. X finishes at t=5.
- The CPU idled from t=5 to t=7. At t=7, Y heads the ready queue (Y, Z) and runs 3 units until t=10. Y finishes at t=10.
- At t=10, Z is the only process ready and runs 1 unit until t=11. Z finishes at t=11.
- All 3 processes are finished at t=11, after 2 context switches. Response averages 1, waiting 1 and turnaround 3.
At t=7 Y and Z arrive together. The tie goes to Y because it is listed first, even though Z is shorter. Y runs from 7 to 10 and Z from 10 to 11, so Z's WT is 10 - 7 = 3. The CPU idled for 5 of the 11 units and was busy for 6, yet Z still waited. Idle time belongs to the CPU and counts from t=0. A job's waiting counts only from its own arrival.
Tracing a workload yourself
Mark each job's arrival. When the CPU is free, run the earliest-arrived waiting job to the end of its burst. If nobody is waiting, mark an idle gap until the next arrival. Then compute CT, TAT = CT - arrival, WT = TAT - burst and RT = first run - arrival for each job, and average them over the same jobs.
A busy CPU can still serve short jobs badly. The CPU stays busy throughout the first trace, while J, K and M wait seven, six and seven units. On real machines, some jobs waiting for the CPU also have disk work to do later. Delaying those jobs can leave the disk idle.
Recap
- No: a short job that arrives mid-run waits for the running burst to finish, then runs in arrival order. A long job placed first can leave every short job behind it waiting, as J waited 7 units for 1 unit of work.
- CT is a clock reading, TAT = CT - arrival, WT = TAT - burst and RT = first run - arrival. In this one-burst, no-I/O model WT equals RT, which stops being true once jobs can be interrupted.
- The damage depends on arrival order (average waiting 5 against 0.5 for the same bursts). An idle CPU, where no job has arrived, is not a waiting job, and jobs arriving together go in listed order.