Round Robin Algorithm with Examples

Published on February 2017 | Categories: Documents | Downloads: 51 | Comments: 0 | Views: 203
of 6
Download PDF   Embed   Report

Comments

Content

Introduction:Round Robin (RR) is one of the simplest scheduling algorithms for processes in an
operating system, which assigns time slices to each process in equal portions and in circular
order handling all processes without priority arguably, the major issue in RR is the time slice .
Round Robin scheduling is both simple and easy to implement, and starvation-free. Different
variants of Round Robin scheduling can be applied to other scheduling problems such as data
packet scheduling in computer networks . Effectiveness and efficiency of RR are arising from
its low scheduling overhead O(1) of which means scheduling the next task takes a constant
time...

The scheduler is concerned mainly with:
 CPU utilization: (time CPU is doing useful work)/(total elapsed time)
 want to keep the CPU as busy as possible
 in a real system, should range from 40% (light load) to 90% (heavy load
 Throughput - number of processes that complete their execution per time unit.
 want to complete as many processes/jobs as possible
 actual number depends upon the lengths of processes (shorter  higher
throughput)
 Turnaround - total time between submission of a process and its completion.
 want to minimize time it takes from origination to completion
 again: average depends on process lengths
tat = t(process completed) – t(process submitted)

 Waiting time - amount of time a process has been waiting in the ready queue.
 want to minimize time process is in the system but not running
 less dependent on process length
 Response time - amount of time it takes from when a request was submitted until the first
response is produced.
 in a time-sharing environment, want to minimize interaction time for user
 rule-of-thumb:
 response time of 0.1 sec req'd to make interaction seem instantaneous
response time of 1.0 sec req'd for user's flow of thought to stay uninterrupted
response time of 10 sec req'd to keep user's attention focused
rt = t(first response) – t(submission of request)

 Fairness - Equal CPU time to each thread.

 Context Switching:
Context switching is how the computer's operating system multitasks different
processes. It lets one process run for a while and then saves a copy of the process' run state
(such as register values) off to the side, restores the run state of the next process back into the
processor, and runs it for a while. Context switching is this process of swapping one program
out of the CPU and replacing it with another process.

Working:



If there are n processes in the ready queue and the time quantum is q, then each
process gets 1/n of the CPU time in chunks of at most q time units at once. No
process waits more than (n-1)q time units.
Performance of the round robin algorithm
I.
q large Þ FCFS
II.
q small Þ q must be greater than the context switch time; otherwise, the
overhead is too high

In order to schedule processes fairly, a round-robin scheduler generally employs timesharing, giving each job a time slot or quantum (its allowance of CPU time), and
interrupting the job if it is not completed by then. The job is resumed next time a time slot is
assigned to that process. In the absence of time-sharing, or if the quanta were large relative to
the sizes of the jobs, a process that produced large jobs would be favored over other
processes... In a computer for example, the user starts three applications, Email, a
web browser, and a word processor. These applications are loaded into system
memory as processes and each is allowed to run without the user considering
which applications are running in the background. Round-robin scheduling handles the

sharing of resources between the three application processes (and the countless others running
in the background completely invisible to the user). This scheduling works well because each
application gets a certain amount of time per processor cycle. A processor cycle is the amount
of time it takes the CPU to manage each process running, one time. With round robin
scheduling, interactive performance depends on the length of the quantum and the number of
processes in the run queue. A very long quantum makes the algorithm behave very much like
first come, first served scheduling since it’s very likely that a process with block or complete
before the time slice is up. A small quantum lets the system cycle through processes quickly.
This is wonderful for interactive processes. Unfortunately, there is an overhead to context
switching and having to do so frequently increases the percentage of system time that is used
on context switching rather than real work.

There is a Queue of processes that need to work on and each process has it's time
requirement to complete,

eg:
process processor time
A3
B8
C6
D4
if the processor give 1 processor time to each process , then A->B->C->D will run each taking
1 processor time and complete a cycle and each process that is not complete will add to the
end of the queue, if a process is completed it will remove from the queue(not enqueueing).
This process will continue until all the process are completed and the queue is empty.
Above que will work as follows.
A->B->C->D->A->B->C->D->A->B->C->D>B->C->D->B->C->B->C->B->B-> Que is
empty
in each highlighted position process that complete their process time remove from the queue
and therefore the rest are processing according to queue.


Advantages:
simple, low overhead, works for interactive systems
 Disadvantages: if quantum is too small, too much time
wasted in context switching; if too large (i.e. longer than
mean CPU burst), approaches FCFS.
Working Diagram:-

Exapmle 1 :
Time Quantum = 4

Process

Burst Time

P1

24

P2

3

P3

3

The Gantt chart is:

P1

0

P2

4

P3

7

Average waiting time =

P1

10

P1

14

P1

18

[(30-24)+4+7]/3 = 17/3 =5.66

P1

22

P1

26

30

Exapmle 2:
Time Quantum=3 units
Process=4

Process

Arrival Time

Execute Time

P0

0

5

P1

1

3

P2

2

8

P3

3

6

P0

P1

P2

P3

P0

P2

P3

P2

0

3

6

9

12

15

18

21

Wait time of each process is following
Process

Wait Time : Service Time - Arrival Time

P0

(0-0) + (12-3) = 9

P1

(3-1) = 2

P2

6-2) + (15-9) = 10

24

P3

(9-3) + (18-12) = 12

Average Wait Time: (9+2+10+12) / 4 = 8.25

Example: Job 1: 24 units,
 Job 2: 3 units,
 Job 3: 3 units
q RR schedule with time quantum=3:
| Job 1 | Job 2 | Job 3 | Job 1 |
0
3
6
9
30
 Total waiting time: 6 + 3 + 6 = 15
 Average waiting time: 5
 Total turnaround time: 30 + 6 + 9 = 45
 Average turnaround time: 15
 RR gives intermediate wait and turnaround

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close