Scheduling Algorithms
Scheduling Algorithms
• Turnaround time: The time at which the job completes minus the
time at which the job arrived in the system:
7
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time.
3. Each job runs to completion
0 20 40 60 80 100 120
Time (Second)
8
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time.
3. Each job runs to completion
0 20 40 60 80 100 120
Time (Second)
𝟏𝟎 + 𝟐𝟎 + 𝟑𝟎
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟐𝟎 𝒔𝒆𝒄
𝟑
9
What is the problem with FIFO – convoy
effect
• Let’s relax assumption 1: Each job no longer runs for the same
amount of time
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time
3. Each job runs to completion
4. All jobs only use the CPU (i.e., they perform no I/O).
5. The run-time of each job is known
• When could FIFO perform poorly in terms of turn around time?
A B C
• Run the shortest job first, then the next shortest, and so on
B C A
0 20 40 60 80 100 120
Time (Second)
𝟏𝟎 + 𝟐𝟎 + 𝟏𝟐𝟎
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟓𝟎 𝒔𝒆𝒄
𝟑
11
Whats the problem with shortest job first
[B,C arrive]
• Let’s relax assumption 2: Jobs can arrive at
any time. A B C
14
New Metric: Response Time
• The time from when the job arrives to the first time it is scheduled
𝑻𝒓𝒆𝒔𝒑𝒐𝒏𝒔𝒆 = 𝑻𝒇𝒊𝒓𝒔𝒕𝒓𝒖𝒏 − 𝑻𝒂𝒓𝒓𝒊𝒗𝒂𝒍
• Using STCF
▪ A arrives at t=0 and needs to run for 100 seconds.
▪ B and C arrive at t=10 and each need to run for 10 seconds
[B,C arrive]
A B C A
0 20 40 60 80 100 120
15
Time (Second)
Round Robin (RR) Scheduling
• Time slicing Scheduling
▪ Run a job for a time slice and then switch to the next job in the run queue
until the jobs are finished
o Time slice is sometimes called a scheduling quantum
16
RR Example
• A, B and C arrive at the same time.
• They each wish to run for 5 seconds
A B C
0 + 5 + 10
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 5𝑠𝑒𝑐
3
0 5 10 15 20 25 30
Time (Second)
17
RR Example A B C
0 + 5 + 10
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 5𝑠𝑒𝑐
3
A B CA B CA B CA B CA B C
0+1+2
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 1𝑠𝑒𝑐
3 18
Timeslice length is important
• The shorter time slice
▪ Better response time
▪ The cost of context switching will dominate overall performance.
19