Types of Schedulers

Introduction

This chart shows the function of each of the three types of schedulers (long-term, short-term, and medium-term) for each of three types of operating systems (batch, interactive, and real-time).

Chart

 batchinteractivereal-time
long-termjob admission based on characteristics and resource needs sessions and processes normally accepted unless capacity reached processes either permanent or accepted at once
medium-termusually none--jobs remain in storage until done processes swapped when necessary processes never swapped
short-termprocesses scheduled by priority; continue until wait voluntarily, request service, or are terminated processes scheduled on rotating basis; continue until service requested, time quantum expires, or pre-empted scheduling based on strict priority with immediate pre-emption; may time-share processes with equal priorities

Job Scheduling Algorithms

Introduction

This handout shows how the various job scheduling algorithms work.

First Come, First Serve (FCFS)

This policy services jobs in the order they arrive.

job namearrival timeservice timestart timefinish timeturnaround timewaiting timeresponse ratio
A0100101001.0
B12910393891.3
C233942403713.3
D37424946396.6
E412496157454.8
mean    38265.4

Shortest Job Next (SJN)

This policy services the shortest job next.

job namearrival timeservice timestart timefinish timeturnaround timewaiting timeresponse ratio
A0100101001.0
B129326160312.1
C2310131183.7
D37132017102.4
E412203228162.3
mean    25132.3

Pre-emptive Shortest Job Next (PSJN)

This policy services the shortest job next, pre-emptively.

job namearrival timeservice timestart timefinish timeturnaround timewaiting timeresponse ratio
A01002pre-empted by C
  8122020102.0
B129326160312.1
C2325301.0
D37512921.3
E412203228162.3
mean    24121.7

Highest Response Ratio Next (HRN)

This policy services the job with the highest response ratio next.

job arrival service start finish turnaround waiting response

job namearrival timeservice timestart timefinish timeturnaround timewaiting timeresponse ratio
A0100101001.0
B129326160312.1
C2310131183.7
D37132017102.4
E412203228162.3
mean    25132.3

Round Robin (RR)

This policy services jobs for a fixed quantum (here, 5).

job namearrival timeservice timestart timefinish timeturnaround timewaiting timeresponse ratio
A01005end of quantum; B starts
  5232828182.8
B129510end of quantum; C starts
  242833end of quantum; D starts
  194045end of quantum; E starts
  14476160312.1
C2310131183.7
D371318end of quantum; E starts
  2333532254.6
E4121823end of quantum; A starts
  73540end of quantum; B starts
  2454743313.5
mean    35233.3

Multilevel Feedback (MLFB)

The variant of this class of scheduling algorithms uses three levels:

The jobs A, B, C, D, and E have been augmented by F, a 1-second job arriving at time 13, and G, an 11-second job arriving at time 50. These are to demonstrate that quanta are usually not interrupted.

In what follows, the number in parentheses in the comment field is the remaining service time for the job.

timelevel 1level 2level 3comments
0A----A(10) arrives, runs
1AB----B(29) arrives, A continues quantum
2BCA--C(3) arrives, A's quantum expires (8), moves to level 2, B runs
3BCDA--D(7) arrives, B continues quantum
4CDEAB--E(12) arrives, B's quantum expires (27), moves down, C runs
6DEABC--C's quantum expires (1), moves down, D runs
8EABCD--D's quantum expires (5), moves down, E runs
10--ABCDE--E's quantum expires (10), moves down, A runs from level 2 (level 1 is empty)
13FABCDE--F(1) arrives, A's quantum continues
14FABCDE--A's quantum expires (4), F runs (at level 1)
15--ABCDE--F finishes, B runs from level 2 (level 1 is empty)
19--ABCDE--B's quantum expires (23), C runs
20--ABDE--C finishes, D runs
28--ABDE--E's quantum expires (6), A runs
32--BDE--A finishes, B runs
36--DEBB's quantum expires (19), moves down, D runs
37--EBD finishes, E runs
41----BEE's quantum expires (2), moves down, B runs from level 3 (since there is nothing in higher levels)
50G--BEG arrives(11), B continues to run
60G--EB finishes, G runs (since it is in the highest level)
62--GEG's quantum expires (9), moves down, G runs from level 2
66--GEG's quantum expires (5), G runs
70----EGG's quantum expires (1), moves down, E runs
72----GE finishes, G runs
73------G finishes
The relevant numbers (ignoring start and finish time) are:
job namearrival timeservice timestart timefinish timeturnaround timewaiting timeresponse ratio
A01002preempted by B
  81014preempted by F
  4283232223.2
B12924preempted by C
  271519preempted by C
  233236preempted by D
  19416059302.0
C2346preempted by D
  1192018156.0
D3768preempted by E
  52024preempted by E
  1363734274.9
E412810preempted by A
  102428preempted by A
  63741preempted by B
  2707268565.7
F1311415212.0
G50116070preempted by E
  1727323122.1
mean    33.723.33.7


Fair Share Scheduler

Introduction

A fair share scheduler is used when CPU time is to be divided equally between groups of processes. For this scheduling algorithm, processes are divided into groups based upon external factors. Such factors include the organizational divisions of the owners of the computer, or classes of customers, or other criteria.

For example, suppose group A has 1 process, group B has 2 processes, group C has 3 processes, and group D has 4 processes. Under a regular scheduler, each of the 10 processes would get 10% of the CPU. Under a fair share scheduler, each of the 4 groups would get 25% of the CPU.

Example

Suppose there are 3 processes. Process p1 is in group A, and processes p2 and p3 are in group B. The following formula assigns process pi a priority Pi:

Pi = (pi's recent CPU usage)/2 + (pi's group CPU usage)/2

In addition, a decay function decrements the current CPU usage of all processes. This "spreads out" the priority of the processes in the ready queue. The decay Di for pi is:

Di = (pi's recent CPU usage)/2

In this system, the lower the numerical value of Pi, the higher the priority of process pi.

The following shows how processes execute, given a quantum of 60 ticks. All arithmetic is integer arithmetic, and the decay function is applied after the most recent CPU time is added in, but before the priorities are computed.

First 60-Tick Interval

At the beginning of this interval, all priorities are equal, so the process to run is chosen randomly. Say p1 is selected to run. It runs, and at the end of the interval, its CPU usage is updated to 60. The group CPU usage for group A, to which p1 belongs, also is updated to 60. The decay function is then applied, cutting both to 30. The CPU usage for p2 and p3, and for group B, are 0, so the decay function does not change them. The priority P1 of p1 becomes

P1 = (p1's recent CPU usage)/2 + (p1's group CPU usage)/2 = 30/2 + 30/2 = 15 + 15 = 30

Second 60-Tick Interval

At the beginning of this interval, P2 and P3 are equal, and both are less than P1, so either p2 or p3 will run. Say p2 is selected to run. It runs, and at the end of the interval, its CPU usage is updated to 60. The group CPU usage for group B, to which p2 belongs, also is updated to 60. The decay function is then applied, cutting both to 30. It also cuts the CPU usage of p1 to 15, and the group CPU usage of group A to 15. The CPU usage for p3 is 0, so the decay function does not change it. The priorities become

P1 = (p1's recent CPU usage)/2 + (p1's group CPU usage)/2 = 15/2 + 15/2 = 7 + 7 = 14
P2 = (p2's recent CPU usage)/2 + p2/2 = 30/2 + 30/2 = 15 + 15 = 30
P3 = (p3's recent CPU usage)/2 + (p3's group CPU usage)/2 = 0/2 + 30/2 = 0 + 15 = 15

Third 60-Tick Interval

At the beginning of this interval, P1 is less than P2 or P3, so p1 runs. At the end of the interval, its CPU usage is updated to 15 + 60 = 75. The group CPU usage for group A, to which p1 belongs, is similarly updated to 15 + 60 = 75. The decay function is then applied, cutting both to 37. It also cuts the CPU usage of p2 to 15, and the group CPU usage of group B to 15. The CPU usage for p3 is 0, so the decay function does not change it. The priorities become

P1 = (p1's recent CPU usage)/2 + (p1's group CPU usage)/2 = 37/2 + 37/2 = 18 + 18 = 36
P2 = (p2's recent CPU usage)/2 + (p2's group CPU usage)/2 = 15/2 + 15/2 = 7 + 7 = 14
P3 = (p3's recent CPU usage)/2 + (p3's group CPU usage)/2 = 0/2 + 15/2 = 0 + 7 = 7

Fourth 60-Tick Interval

At the beginning of this interval, P3 is less than P1 or P2, so p3 runs. At the end of the interval, its CPU usage is updated to 0 + 60 = 60. The group CPU usage for group B, to which p2 belongs, is similarly updated to 15 + 60 = 75. The decay function is then applied, cutting p3's CPU usage to 30 and the group CPU usage to 37. It also cuts the CPU usage of p1 to 18, the CPU usage of p2 to 7, and the group CPU usage of group A to 18. The priorities become

P1 = (p1's recent CPU usage)/2 + (p1's group CPU usage)/2 =18/2 + 18/2 = 9 + 9 = 18
P2 = (p2's recent CPU usage)/2 + (p2's group CPU usage)/2 =7/2 + 37/2 = 3 + 18 = 21
P3 = (p3's recent CPU usage)/2 + (p3's group CPU usage)/2 = 30/2 + 37/2 = 15 + 18 = 33

Summary Table

This table summarizes the first 8 seconds. The figures shown are for after the ticks, and after the calculations of priorities.

ticksPrioritiesCPU Usage After DecayGroup CPU Usage After Decayruns
 p1p2p3p1p2p3AB 
000000000A
6030003000300B
120143015153001530A
18036147371503715C
240182133187301837A
300381016393153918B
360183422193171939A
420381610391533919C
..............................

You can also obtain a PDF version of this. Version of April 22, 2008 at 9:51 PM