13
Shortest - Remaining - Time (SRT) Scheduling A variation of the SJF. New jobs can arrive in the wait queue while another job is still running. If the remaining time of the running job is larger than that of the newly-arrived job, the running job is preempted and returned to the wait queue while the next shortest job is processed. Very large variance of response times: long processes wait even longer than under SPF Not always optimal Short incoming process can preempt a running process that is near to completion Context-switching overhead can become significant 28-09-2020

Shortest-Remaining-Time (SRT) Scheduling

Embed Size (px)

Citation preview

Shortest-Remaining-Time (SRT)Scheduling

– A variation of the SJF. New jobs can arrive in the wait queue whileanother job is still running. If the remaining time of the running jobis larger than that of the newly-arrived job, the running job ispreempted and returned to the wait queue while the next shortestjob is processed.

– Very large variance of response times: long processes wait evenlonger than under SPF

– Not always optimal

• Short incoming process can preempt a running process that isnear to completion

• Context-switching overhead can become significant

28-09-2020

Shortest Process First Scheduling

• Example: Process Arrival Time Burst Time

P1 0 7

P2 2 4

P3 4 1

P4 5 4

• Non preemptive SJF

P1 P3 P2

7

P1(7)

160

P4

8 12

Average waiting time = (0 + 6 + 3 + 7)/4 = 4

2 4 5

P2(4)

P3(1)

P4(4)

P1‘s wating time = 0

P2‘s wating time = 6

P3‘s wating time = 3

P4‘s wating time = 7

28-09-2020

Shortest Process First SchedulingCont’d• Example: Process Arrival Time Burst Time

P1 0 7

P2 2 4

P3 4 1

P4 5 4

• Preemptive SJF

P1 P3P2

42 110

P4

5 7

P2 P1

16

Average waiting time = (9 + 1 + 0 +2)/4 = 3

P1(7)

P2(4)

P3(1)

P4(4)

P1‘s wating time = 9

P2‘s wating time = 1

P3‘s wating time = 0

P4‘s wating time = 2

P1(5)

P2(2)

28-09-2020

Example of Shortest-remaining-time-first

28-09-2020

i.e. Preemptive SJF

◼ Now we add the concepts of varying arrival times and preemption to

the analysis

Process Arrival Time Burst Time

P1 0 8

P2 1 4

P3 2 9

P4 3 5

◼ Preemptive SJF Gantt Chart

0 1 5 10 17 26

◼ Average waiting time = [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5

msec

P1 P2 P4 P1 P3

ISSUES:

• Completion time must be known ahead, but it is difficult to predict.

• SJF is often used for long-term scheduling in a batch system (Job scheduler).Here, the submitting user’s estimated process time limit can be used.Lower values means faster response time, but too low a value will causetime-limit-exceeded error and require resubmission.

• SJF cannot be implemented for short-term CPU scheduling (CPU scheduler)since there is no way to predict the length of the next CPU burst, however,it can be approximated based on values of previous processes. Future bursttime can be predicted using exponential average.

• SJF implemented with preemptive policy may cause very long turnaroundtimes or even process starvation. This can occur when a job with largeremaining time is stuck in the wait queue due to arrival of shorter jobs.

28-09-2020

Priority based Scheduling

• Each process is assigned a priority. Process with highest priority is to be executed first and so on.– A priority number (integer) is associated with each process

• Process scheduling is preemptive :a low priority running process is preempted if a higher priority process becomes ready.

• Process priorities are static.

• Processes with same priority are executed on first come first served basis.

• Priority can be decided based on memory requirements, time requirements or any other resource requirement.

28-09-2020

Example of Priority Scheduling

Process Burst Time(ms) Priority

P1 10 3

P2 1 1

P3 2 4

P4 1 5

P5 5 2

◼ Priority scheduling Gantt Chart assuming all arrive at time 0

◼ Average waiting time = (0+1+6+16+18)/5 = 8.2 msec

28-09-2020

• Multiple-level queues are not an independent scheduling algorithm. They make use of other existing algorithms to group and schedule jobs with common characteristics.

• Multiple queues are maintained for processes with common characteristics.

• Each queue can have its own scheduling algorithms.

• Priorities are assigned to each queue.

• For example, CPU-bound jobs can be scheduled in one queue and all I/O-bound jobs in another queue. The Process Scheduler then alternately selects jobs from each queue and assigns them to the CPU based on the algorithm assigned to the queue.

Multilevel Queue Scheduling

28-09-2020

Multilevel Queue Scheduling

28-09-2020

Multilevel Queue• Ready queue is partitioned into separate queues:

EX:

• foreground (interactive)background (batch)

• Each queue has its own scheduling algorithm

EX– foreground – RR– background – FCFS

• Scheduling must be done between the queues– Fixed priority scheduling; (i.e., serve all from foreground then from

background). Possibility of starvation.– Time slice – each queue gets a certain amount of CPU time which it can

schedule amongst its processes;EX80% to foreground in RR20% to background in FCFS

28-09-2020

Example of Multilevel Feedback Queue

• Three queues:– Q0 – RR with time quantum 8

milliseconds– Q1 – RR time quantum 16

milliseconds– Q2 – FCFS

• Scheduling– A new job enters queue Q0 which

is served FCFS. When it gains CPU,job receives 8 milliseconds (RR). Ifit does not finish in 8 milliseconds,job is moved to queue Q1.

– At Q1 job is again served FCFS andreceives 16 additional milliseconds(RR). If it still does not complete,it is preempted and moved toqueue Q2.

– AT Q2 job is served FCFS28-09-2020

Summary

• Scheduling: selecting a process from the ready queue and allocating the CPU to it

• FCFS Scheduling:

• Run processes to completion in order of submission

• Pros: Simple (+)

• Cons: Short jobs get stuck behind long ones (-)

• Round-Robin Scheduling:

• Each process is provided a fix time to execute called quantum.

• Once a process is executed for given time period. Process is preempted and other process executes for given time period.

• Context switching is used to save states of preempted processes.

• Pros: Better for short jobs (+)

• Cons: Poor when jobs are of same length (-)

28-09-2020

• Shortest Job First (SJF)/Shortest Remaining Time First (SRTF):• Run whatever job has the least amount of computation to do/least

remaining amount of computation to do• Pros: Optimal (average response time) • Cons: Hard to predict future, Unfair

• Priority Scheduling• Each process is assigned a priority.

• Process with highest priority is to be executed first and so on.

• Processes with same priority are executed on first come first serve basis. Priority can be decided based on memory requirements, time requirements or any other resource requirement.

• Multi-Level Feedback Scheduling:• Multiple queues of different priorities• Automatic promotion/demotion of process priority in order to approximate

SJF/SRTF

28-09-2020