• Operating System Video Tutorials

Highest Response Ratio Next (HRRN) Scheduling



CPU scheduling algorithms are strategies that decide which process in the ready queue should execute next, in a multiprogramming environment. There are a number of scheduling strategies, among which Highest Response Ratio Next (HRNN) scheduling aims to provide one of the most optimal scheduling solutions.

Highest Response Ratio Next (HRRN) Scheduling

HRRN algorithm is a non-preemptive scheduling strategy which chooses the next process to execute based on a parameter called Response Ratio. Response ratio is calculated by the formula −

$$\mathrm{Response \: Ratio \: = \: \frac{(W \: + \: S)}{S}}$$

Here, W is the waiting time of the process until now and S is the burst time of the process.

When multiple processes are ready to execute, the scheduler calculates response ratio for each process and allocates the CPU to the process having the highest value. Since, HRRN is a non-preemptive algorithm, once a process gets CPU access, it executes to completion before another process can gain CPU access.

Features of HRRN Scheduling

  • HRRN algorithm is the most optimal algorithm since it chooses processes to execute based upon their response ratio.
  • HRRN gives preference to both shorter processes as well as processes which have been waiting in the ready queue for longer time.
  • It is envisaged as a modification of Shortest Job First algorithm that solves the starvation problem of SJF algorithm.
  • Since it is non-preemptive in nature, the scheduler is invoked when a process completes its execution or when a new process(es) arrives in an empty ready queue.
  • It does not require frequent context switches. This helps the CPU to focus mainly on execution of the processes.

Working Principle of HRRN Algorithm

  • Initially when the CPU is idle, the scheduler is invoked when one or more new processes arrive in the ready queue. The process with the shortest burst time is let in.
  • When the running process completes its execution, response ratio is calculated for each process waiting in the ready queue. The process with highest response ratio is assigned the CPU.
  • Step 2 is repeatedly executed until there are no processes in the ready queue.

Example of HRRN Scheduling Algorithm

We can understand the workings HRRN scheduling algorithm through the aid of the following example.

Let us consider a system that has four processes which have arrived at the same time in the order P1, P2, P3 and P4. The burst time in milliseconds of each process is given by the following table −

Process Arrival Time CPU Burst Time
P1 0 6
P2 4 10
P3 4 4
P4 8 5

Let us perform HRRN scheduling on this. We will draw GANTT chart and find the average turnaround time and average waiting time.

GANTT Chart Generation

To generate the GANTT charts, we will find the response ratio at each instance when the scheduler is invoked.

At Time = 0ms

Processes in the system: P1.

Since, P1 is the only process, it is scheduled immediately. It runs into completion at Time = 6ms.

GANTT chart up to this time is −

At Time 0 ms

At Time = 6ms

Process P1 completes execution and leaves system.

Processes in the system: P2 and P3 both of which have arrived at time= 4ms.

Response Ratio of P2 = (W + S) / S = (2 + 10) / 10 = 1.2

Response Ratio of P3 = (W + S) / S = (2 + 4) / 4 = 1.5

Since P3 has higher response ratio, P3 is assigned to the CPU.

GANTT chart up to this time is −

At Time 6 ms

At Time = 10ms

Process P3 completes execution and leaves system.

Processes in the system: P2 which had arrived at time= 4ms and P4 which has arrived at time = 8ms.

Response Ratio of P2 = (W + S) / S = (6 + 10) / 10 = 1.6

Response Ratio of P4 = (W + S) / S = (2 + 5) / 5 = 1.4

Since P2 has higher response ratio, P2 is assigned to the CPU.

GANTT chart up to this time is −

At Time 10 ms

At Time = 20ms

Process P2 completes execution and leaves system.

Only process in the system is P4 and so it is immediately scheduled.

Hence, the final GANTT chart is −

At Time 20 ms

From this we will calculate the turnaround time and waiting time of each process and their average values.

Turnaround Time of a process = Completion Time Arrival Time

TATP1 = TP1 - ATP1 = 6 - 0 = 6 ms

TATP2 = CTP2 - ATP2 = 20 - 4 = 16 ms

TATP3 = CTP3 - ATP3 = 10 - 4 = 6 ms

TATP4 = CTP4 - ATP4 = 25 - 8 = 17 ms

Average Turnaround Time

=Sum of Turnaround Time of each Process / Number of Processes

= (TATP1 + TATP2 + TATP3 + TATP4) / 4

= ( 6 + 16 + 6+ 17) / 4 = 11.25 ms

The waiting time is given by the time that each process waits in the ready queue. For a non-preemptive scheduling algorithm, waiting time of each process is calculated as −

Waiting Time of any process = Time of admission to CPU Arrival Time

WTP1 = 0 - 0 = 0 ms

WTP2 = 10 - 4 = 6 ms

WTP3 = 6 - 4 = 2 ms

WTP4 = 20 - 8 = 12 ms

Average Waiting Time

= Sum of Waiting Time of Each Process / Number of processes

= (WTP1 + WTP2 + WTP3 + WTP4) / 4

= (0 + 6 + 2 +12) / 4 = 5 ms

Advantages of HRRN Scheduling

  • HRRN algorithm is one of the most optimal algorithms.
  • It prefers shorter processes and so has all the advantages of Shortest Job First scheduling algorithm.
  • It solves the starvation problem as the response ratio computes to a higher value for processes which have been waiting in the ready queue for longer time, and are eventually assigned to the CPU.
  • Since it is non-preemptive in nature, it does not require frequent context switches. So the CPU cycles are not wasted on context switches and are instead used for execution of the processes.

Disadvantages of HRRN Scheduling

  • This works only when the CPU burst times are known in advance. The dynamic nature of most processes makes it difficult to ascertain the burst time prior to execution. An error in calculation of the burst time may render the entire algorithm erroneous.
  • The CPU is burdened with the added logic of calculating the response time of each process before assigning them to the CPU. If there are a large number of short processes in the system, CPU gets more engaged in the scheduling process than in the actual execution of the processes.
  • HRRN scheduling does not assign priorities to processes. If a high priority long process arrives in the system, it may have to wait for considerable time before it is let in. This may often hamper the overall performance of a system.

Conclusion

Highest Response Ratio Next scheduling algorithm is basically a modified Shortest Job First algorithm where the problem of starvation has been eliminated to a considerable extent. Theoretically, it is the most optimal algorithm. However, its practical applicability is restricted since burst times are unpredictable.

Advertisements