Job Scheduling

Scheduling Algorithms
Scheduling disciplines are algorithms used for distributing resources among parties which simultaneously and asynchronously request them. Scheduling disciplines are used in routers (to handle packet traffic) as well as in operating systems (to share CPU time among both threads and processes), disk drives (I/O scheduling), printers (print spooler), most embedded systems.

The main purposes of scheduling algorithms are to minimize resource starvation and to ensure fairness amongst the parties utilizing the resources. Scheduling deals with the problem of deciding which of the outstanding requests is to be allocated resources. There are many different scheduling algorithms. In this section, we introduce several of them. In packet-switched computer networks and other statistical multiplexing, the notion of a scheduling algorithm is used as an alternative to first-come first-served queuing of data packets.

The simplest best-effort scheduling algorithms are round-robin, fair queuing (a max-min fair scheduling algorithm), proportionally fair scheduling and maximum throughput. If differentiated or guaranteed quality of service is offered, as opposed to best-effort communication, weighted fair queuing may be utilized. In advanced packet radio wireless networks such as HSDPA (High-Speed Downlink Packet Access ) 3.5G cellular system, channel-dependent scheduling may be used to take advantage of channel state information. If the channel conditions are favourable, the throughput and system spectral efficiency may be increased. In even more advanced systems such as LTE, the scheduling is combined by channel-dependent packet-by-packet dynamic channel allocation, or by assigning OFDMA multi-carriers or other frequency-domain equalization components to the users that best can utilize them.

First in first out
Also known as First­ Come, First ­Served (FCFS), is the simplest scheduling algorithm, FIFO simply queues processes in the order that they arrive in the ready queue.

Since context switches only occur upon process termination, and no reorganization of the process queue is required, scheduling overhead is minimal. Throughput can be low, since long processes can hold the CPU Turnaround time, waiting time and response time can be high for the same reasons above No prioritization occurs, thus this system has trouble meeting process deadlines. The lack of prioritization means that as long as every process eventually completes, there is no starvation. In an environment where some processes might not complete, there can be starvation. It is based on Queuing. First-Come, First-Served (FCFS) Scheduling    Process         Burst Time  P1                                24   P2                                3  <p class="MsoNormal" style="text-autospace: none"><font face="Arial"> P3                                </i> 3 </b> <p class="MsoNormal" style="text-autospace: none">  Suppose that the processes arrive in the order: <font face="Arial"> P1 </i> , <font face="Arial">  P2 </i> , <font face="Arial">  P3 </i> </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"> </i> <p class="MsoNormal" style="text-autospace: none"> The Gantt Chart for the schedule is: <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"> 0                                                 24                                    27                                                       30 <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"> <p class="MsoNormal" style="text-autospace: none">  Waiting time for <font face="Arial"> P1 </i> = 0; <font face="Arial"> P2 </i> = 24; <font face="Arial"> P3 </i> = 27 </b> <p class="MsoNormal" style="text-autospace: none">  Average waiting time: (0 + 24 + 27)/3 = 17 </b> <p class="MsoNormal" style="text-autospace: none"> Suppose that the processes arrive in the order <p class="MsoNormal" style="text-autospace: none"><font face="Arial"> P2 </i> , <font face="Arial">  P3 </i> , <font face="Arial">  P1 </i> . </b> <p class="MsoNormal" style="text-autospace: none"> <b> The Gantt chart for the schedule is: </b> <p class="MsoNormal" style="text-autospace: none">

Waiting time for P1 = 6; P2 = 0; P3 = 3

Average waiting time: (6 + 0 + 3)/3 = 3

Much better than previous case.

Convoy effect short process behind long process

Shortest remaining time
Similar to Shortest­ Job­ First (SJF). With this strategy the scheduler arranges processes with the least estimated processing time remaining to be next in the queue. This requires advanced knowledge or estimations about the time required for a process to complete. If a shorter process arrives during another process' execution, the currently running process may be interrupted (known as preemption), dividing that process into two separate computing blocks. This creates excess overhead through additional context switching. The scheduler must also place each incoming process into a specific place in the queue, creating additional overhead.

This algorithm is designed for maximum throughput in most scenarios. Waiting time and response time increase as the process' computational requirements increase. Since turnaround time is based on waiting time plus processing time, longer processes are significantly affected by this. Overall waiting time is smaller than FIFO, however since no process has to wait for the termination of the longest process.

No particular attention is given to deadlines, the programmer can only attempt to make processes with deadlines as short as possible. Starvation is possible, especially in a busy system with many small processes being run. <font color="#800000">Shortest-Job-First (SJR) Scheduling </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <b> Associate with each process the length of its next CPU </b> burst. Use these lengths to schedule the process with the shortest time. <p class="MsoNormal" style="text-autospace: none"> <b> Two schemes: </b> <p class="MsoNormal" style="text-autospace: none"> <b><font color="#800000" face="Arial" style="font-size: 11pt">1. <font color="#800000"> non pre- emptive – once CPU given to the process it cannot </b> be preempted until completes its CPU burst. <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> <font color="#800000">2. <font color="#800000">preemptive – if a new process arrives with CPU burst length </b> less than remaining time of current executing <p class="MsoNormal" style="text-autospace: none"> process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). <p class="MsoNormal" style="text-autospace: none"> <b> SJF is optimal – gives minimum average waiting time for </b> a given set of processes. <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> Process Arrival Time    Burst Time <p class="MsoNormal" style="text-autospace: none"><b><font face="Arial"><i> P1                   </i> 0.0                        7 </b> <p class="MsoNormal" style="text-autospace: none"><b><font face="Arial"><i> P2                   </i> 2.0                        4 </b> <p class="MsoNormal" style="text-autospace: none"><b><font face="Arial"><i> P3                   </i> 4.0                        1 </b> <p class="MsoNormal" style="text-autospace: none"><b><font face="Arial"><i> P4                   </i> 5.0                        4 </b> <p class="MsoNormal" style="text-autospace: none"> <b> SJF (non-preemptive) </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"> 0                                 7                               8                         12                                     16 <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"> <p class="MsoNormal" style="text-autospace: none"> <b> Average waiting time = [0 +(8-2)+(7-4) +(12-5)] /4 =4 </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <font face="Arial" color="#800000"> Example of Preemptive SJF  <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b> <p class="MsoNormal" style="text-indent: .5in; text-autospace: none"> Proces Arrival Time               Burst Time <p class="MsoNormal" style="text-indent: .5in; text-autospace: none"><b> <font face="Arial"><i> P1                                   </i> 0.0                              7 </b> <p class="MsoNormal" style="text-indent: .5in; text-autospace: none"><b> <font face="Arial"><i> P2                  </i> 2.0                              4 </b> <p class="MsoNormal" style="text-indent: .5in; text-autospace: none"><b> <font face="Arial"><i> P3                                   </i> 4.0                              1 </b> <p class="MsoNormal" style="text-indent: .5in; text-autospace: none"><b> <font face="Arial"><i> P4                                    </i> 5.0                             4 </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> SJF (preemptive) </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"> 0                  2                       4                     5                         7                      11               16 <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> Average waiting time = (9 + 1 + 0 +2)/4 =3 </b> <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"><b> Determining Length of Next CPU Burst </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b> <p class="MsoNormal" style="text-autospace: none"> <b> Can only estimate the length. </b> <p class="MsoNormal" style="text-autospace: none"> <b> Can be done by using the length of previous CPU bursts, </b> using exponential averaging. <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> Prediction of the Length of the Next CPU Burst </b> <p class="MsoNormal" style="text-autospace: none"> Pn+1 = a tn +(1-a)Pn <p class="MsoNormal" style="text-autospace: none"> This formula defines an exponential average <p class="MsoNormal" style="text-autospace: none"> Pn stores the past history <p class="MsoNormal" style="text-autospace: none"> tn contents are most recent information <p class="MsoNormal" style="text-autospace: none"> the parameter “a “controls the relative weight of recent and past history of  in our prediction <p class="MsoNormal" style="text-autospace: none"> If a =0 then Pn +1 =Pn <p class="MsoNormal" style="text-autospace: none"> That is prediction is constant <p class="MsoNormal" style="text-autospace: none"> If a = 1 then Pn +1 = tn <p class="MsoNormal" style="text-autospace: none"> Prediction is last cpu burst <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> <font color="#800000">Priority Scheduling </b> <p class="MsoNormal" style="text-autospace: none"> <b> A priority number (integer) is associated with each </b> process <p class="MsoNormal" style="text-autospace: none"> <b> The CPU is allocated to the process with the highest </b> priority (smallest integer &#8801; highest priority). <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. Preemptive </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 2. nonpreemptive </b> <p class="MsoNormal" style="text-autospace: none"> <b> SJF is a priority scheduling where priority is the predicted </b> next CPU burst time. <p class="MsoNormal" style="text-autospace: none"> <b> Problem &#8801; Starvation – low priority processes may never </b> execute. <p class="MsoNormal" style="text-autospace: none"> <b> Solution &#8801; Aging – as time progresses increase the </b> priority of the process.

Fixed priority pre-emptive scheduling
The OS assigns a fixed priority rank to every process, and the scheduler arranges the processes in the ready queue in order of their priority. Lower priority processes get interrupted by incoming higher priority processes. Overhead is not minimal, nor is it significant.

FPPS has no particular advantage in terms of throughput over FIFO scheduling. Waiting time and response time depend on the priority of the process. Higher priority processes have smaller waiting and response times. Deadlines can be met by giving processes with deadlines a higher priority. Starvation of lower priority processes is possible with large amounts of high priority processes queuing for CPU time.

Round-robin scheduling
Main article: Round-robin scheduling The scheduler assigns a fixed time unit per process, and cycles through them. RR scheduling involves extensive overhead, especially with a small time unit. Balanced throughput between FCFS and SJF, shorter jobs are completed faster than in FCFS and longer processes are completed faster than in SJF.

Poor average response time, waiting time is dependent on number of processes, and not average process length. Because of high waiting times, deadlines are rarely met in a pure RR system. Starvation can never occur, since no priority is given. Order of time unit allocation is based upon process arrival time, similar to FCFS. <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"><b> <font color="#800000">Round Robin (RR) </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <b> Each process gets a small unit of CPU time ( <font face="Arial"><i> time quantum </i> ), usually 10-100 milliseconds. After this time </b> has elapsed, the process is preempted and added to the end of the ready queue. <p class="MsoNormal" style="text-autospace: none"> <b> If there are <font face="Arial"><i> n </i> processes in the ready queue and the time quantum is <font face="Arial"><i> q </i> , then each process gets 1/ <font face="Arial"><i> n </i> of the </b> <p class="MsoNormal" style="text-autospace: none">  C  <b> PU time in chunks of at most <font face="Arial"><i> q </i> time units at once. No process waits more than ( <font face="Arial"> n  -1) <font face="Arial"><i> q </i> time units. </b> <p class="MsoNormal" style="text-autospace: none">  Performance  <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. <i> q </i> large <font face="Arial"> _ FIFO </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 2. <i> q </i> small <font face="Arial"> _ <i> q </i> must be large with respect to context switch, </b> otherwise overhead is too high. <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"><b> Example of RR with Time Quantum = 4 </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> Process Burst Time <p class="MsoNormal" style="text-autospace: none"><b><font face="Arial"><i> P1                   </i> 24 </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><i> P2                    3 </i> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><i> P3                    3 </i> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <b> The Gantt chart is: </b> <p class="MsoNormal" style="text-autospace: none"> 0         4               7              10            14            18             22          26            30  <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> Average waiting time =   [(30-24)+4+7]/3  = 17/3 =5.66

Multilevel queue scheduling
Main article: Multilevel feedback queue This is used for situations in which processes are easily divided into different groups. For example, a common division is made between foreground (interactive) processes and background (batch) processes. These two types of processes have different response-time requirements and so may have different scheduling needs. It is very useful for shared memory problems. <p class="MsoNormal" style="text-autospace: none"><b> Ready queue is partitioned into separate queues: </b> <p class="MsoNormal" style="text-autospace: none"> foreground (interactive) <p class="MsoNormal" style="text-autospace: none"> background (batch) <p class="MsoNormal" style="text-autospace: none"> <b> Each queue has its own scheduling algorithm, </b> <p class="MsoNormal" style="text-autospace: none"> foreground – RR <p class="MsoNormal" style="text-autospace: none"> background – FCFS <p class="MsoNormal" style="text-autospace: none"> <b> Scheduling must be done between the queues. </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. Fixed priority scheduling; (i.e., serve all from foreground </b> then from background). Possibility of starvation. <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 2. Time slice – each queue gets a certain amount of CPU time </b> <p class="MsoNormal" style="text-autospace: none"> which it can schedule amongst its processes; i.e., 80% to foreground in RR <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. 20% to background in FCFS </b> <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b>

Multilevel Feedback Queue
<p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> <font color="#800000"> Multilevel Feedback Queue </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b> <p class="MsoNormal" style="text-autospace: none"> <b> A process can move between the various queues; aging </b> can be implemented this way. <p class="MsoNormal" style="text-autospace: none"> <b> Multilevel-feedback-queue scheduler defined by the </b> following parameters: <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. number of queues </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 2. scheduling g algorithms for each queue </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 3. method used to determine when to upgrade a process </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 4. method used to determine when to demote a process </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 5. method used to determine which queue a process will enter </b> when that process needs service <p class="MsoNormal" style="text-autospace: none"> <p class="MsoNormal" style="text-autospace: none"> <font face="Arial"><b> <font color="#800000">Example of Multilevel Feedback Queue </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b> <p class="MsoNormal" style="text-autospace: none"><font face="Arial"><b> </b> <p class="MsoNormal" style="text-autospace: none"> <b> Three queues: </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. <i> Q </i> 0 – time quantum 8 milliseconds </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 2. <i> Q </i> 1 – time quantum 16 milliseconds </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 3. <i> Q </i> 2 – FCFS </b> <p class="MsoNormal" style="text-autospace: none"> <b> Scheduling </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 1. A new job enters queue <font face="Arial"><i> Q0 </i> which is served FCFS. When it </b> gains CPU, job receives 8 milliseconds. <p class="MsoNormal" style="text-autospace: none"> If it does not finish <b> in 8 milliseconds, job is moved to queue <font face="Arial"><i> Q </i> 1. </b> <p class="MsoNormal" style="text-autospace: none"> <b><font face="Arial"> 2. At <font face="Arial"><i> Q </i> 1 job is again served FCFS and receives 16 additional </b> milliseconds. If it still does not complete, <p class="MsoNormal" style="text-autospace: none"> it is preempted <b> and moved to queue <font face="Arial"><i> Q </i> 2. </b> <p class="MsoNormal" style="text-autospace: none">