Scheduling Algorithms
Notes
- This is 5.3
- The average waiting time is as you would expect
- Add up all of the time processes spend waiting
- Divide by the number of processes
- This is a simple measure of performance and consistency
- Notation Pn-t
- n is the process number
- t is the time for a burst
- So if we are scheduling P1-24, P2-3, P3-3 we would take 30 seconds for all three to run.
- We are currently assuming no preemption
- First Come First Served - no preemption (FCFS) : the first process in the queue runs for its burst then the next, then the next, ...
- Queue: P1-24, P2-3, P3-3
- Wait times: P1:0, P2: 24, P3:27
- Average 51/3 = 17
- Queue: P2-3, P3-3, P1-24
- Wait times: P1:6, P2: 0, P3:3
- Average 9/3 = 3
- The system tends to degenerate into the first example
- This is called the convoy effect
- FCFS is good because
- Easy to implement
- Fair in that every process gets an equal chance to run
- No starvation
- Very low cost algorithm
- Very predictable
- But it is not
- Good for interactive systems.
- And has a high average waiting time.
- Shortest-job first - no preemption
- Select the shortest job and let it run first.
- To do this, we need to estimate the next burst time
- This can be done with the algebraic average
- But it is better with an exponential average
- $\tau_{n+1} = \alpha t_n + (1- \alpha) \alpha t_{n-1} + ... + (1-\alpha)^i \alpha t_{n-i} + ... + (1-\alpha)^{n+1}t_0$
- $0 \le \alpha \le 1$
- And $\tau_{n+1} = \alpha t_n + (1-\alpha)\tau_n$
- This considers all bursts, but places more weight on the last burst.
- See figure 5.4
- Advantages
- Minimum waiting time, but for short processes
- High Throughput
- Short turnaround
- But
- Starvation
- Unfair
- Higher overhead.
- Round Robin
- FCFS with preemption
- define a time quantum or time slice.
- This is how long a process can run without interruption
- The size of the quantum is important
- Small supports lower average wait time
- But also means that more time is spent in os operations (less progress)
- Larger means more progress
- But waiting time goes up, and it does not feel as interactive.
- The quantum should be large compared to the time for a context switch
- A good rule of thumb is that 80% of the bursts should be less than the quantum.