CIS 307: TOPIC: Scheduling

[Introduction], [First-Come-First_Served (FCFS), and Shortest Job First (SJF)], [Exponential Averaging], [Round Robin (RR)]

Scheduling is treated in Tanenbaum Section 2.4

Introduction

Consider a single server queue system:
		  ---+   +--+
	--------->||||-->|  |----> Departures
	Arrivals  ---+   +--+
		Queue    Server
The scheduling discipline (or policy) is used to select a job out of the queue whenever the server becomes available. Examples of scheduling disciplines are FCFS (First Come First Served), SJF (Shortest Job First), RR (Round Robin).
What should we look for in selecting which scheduling policy to use? Usually we look for the following:
  • Utilization: The ratio between the time the server is busy and the total observation time. Utilization is particularly significant when the cost of the server is high with respect to the cost of the time of the users. [This was the case in the Sixties when computers were very expensive. Computer centers in those days mainly cared about keeping their systems busy.]
  • Response Time: The time interval between when a job arrives to the system and when it leaves the system. Response time matters to users. The smaller the response time, the happier the user [of course, below certain response times, say a few hundredths of a second, it does not matter any more].
  • Fairness: Providing response times that are similar for users of the same kind. Fairness matters to users, expecially when it takes the form of a guaranty that the delay will not exceed a specified value.
  • Throughput: Number of jobs completed per unit of time. A useful observation is that we can determine easily a maximum throughput, called the saturation throughput. It is just the inverse of the service time. For example, for a disk where reads take 10 milliseconds we can do at most 100 reads per second.
  • Unfortunately it is not possible to have a scheduling discipline that is optimal from all viewpoints. Currently people tend to favor fairness, over response time, over utilization. Or they favor response time, over fairness, over utilization.

    A scheduling discipline can be simple or complex. Typically, the more frequent the scheduling decisions, the less sophisticated the scheduling discipline that is used. For example, the scheduling discipline used in the ready queue (micro-scheduling), is usually fairly simple, just priority scheduling. The scheduling discipline used for batch or swapped out jobs (macro-scheduling) tends to be more sophisticated.

    The following features are used to classify scheduling disciplines (Ruschitzka&Fabry):

    Decision Mode
    It expresses when and how scheduling decisions are made. It can be:
    Scheduling Function
    It acts as a priority function. It is usually time based. It can represent:
    Arbitration Rule
    It breaks ties in the scheduling function. It usually takes values:
    Feasibility
    It indicates if the scheduling discipline can be actually implemented. It takes values:
    Here are a few scheduling disciplines and their features:
    
    	               | Priority | Decision  | Arbitration | Feasibility
    Scheduling Algorithm   | Function | Rule      | Rule        | 
    ========================================================================
    FIFO (FirstInFirstOut) | r        | No-Preempt| Random      | Realistic
    ------------------------------------------------------------------------
    LIFO (LastInFirstOut)  | -r       | No-Preempt| Random      | Realistic
    ------------------------------------------------------------------------
    SJF (ShortestJobFirst) | -t       | No-Preempt| Chronologic | Ideal
    ------------------------------------------------------------------------
    SRT(ShortestRemainTime)| a-t      | Preempt   | Chronologic | Ideal
    ------------------------------------------------------------------------
    RR (RoundRobin)        | constant | Preempt   | Cyclic      | Realistic
    =======================================================================
    
    

    First-Come-First_Served (FCFS), and Shortest Job First (SJF)

    Let's evaluate FCFS and SJF in the case of the following jobs, listed in arrival order:
    
    	Job | Time
    	=========
    	1   | 6
    	2   | 3
    	3   | 8
    	4   | 7
    
    
    The schedule for FCFS is

    1:2:3:4

    and the (average) Response Time is

    R = (6)+(6+3)+(6+3+8)+(6+3+8+7) = 1*7+2*8+3*3+4*6 = 56/4 = 14.

    The schedule for SJF is

    2:1:4:3

    and the (average) Response Time is

    R = (3)+(3+6)+(3+6+7)+(3+6+7+8) = 1*8+2*7+3*6+4*3 = 52/4 = 13.

    Note that different scheduling disciplines reorder the execution of the tasks. This observation, when properly stated and verified, leads to the following result:

    Theorem: SJF is optimal among non-preemptive scheduling disciplines.

    Exponential Averaging

    We have seen that SJF is not directly implementable since we do not have reliable values for the execution times of jobs. However we may get fairly satisfactory estimates of the actual execution times. The reasoning goes as follows.

    A job does not execute to completion without interruptions. Instead, it runs for a while, then blocks, then runs again, then blocks, etc. If we focus on these separate runs, and their execution times t1, t2, .., tn, we see a time series. If i runs have already taken place, and we need to estimate the time taken by the (i+1)th run, we can use information about the execution times and the estimated times that have occurred up to now. Here is a method for doing such estimating.

    Let a be a real number in the interval [0,1]. Let e1 be an initial time estimate, then, for any i >= 1, we set

    ei+1 = a*ti + (1-a)*ei

    For example, if we assume that a job has runs that take always 6 seconds, i.e t1=t2=..=6, our initial estimate e1 is 10 and we set a to 0.5, we get as successive estimates:

    e2=8, e3=7, e4=6.5, e5=6.25, ..

    That is, our estimates move towards the correct value first rapidly, then more gradually since at each step the difference between estimate and correct time is halved (in general, it is proportional to (1-a)). For this reason this estimation method is called Exponential Averaging.

    A way to use the ideas of exponential averaging is the following (quantum is the amount of time that a process is allowed to run before it is preempted):

    Another way is the following:

    In this solution all processes share the same quantum.

    An important thing to remember is that the scheduling we are discussing here (often called macroscheduling) is concerned with re-adjusting priorities that will then be used in (micro) scheduling at the level of the ready queue. These re-adjustments are done at regular intervals (usually more than one second).

    Round Robin (RR)

    Round Robin is the scheduling discipline whereby, if we are given jobs j1, j2, ..jn, and we have chosen a time Quantum q, we run j1 for up to q seconds, then give control to j2 for up to q seconds, then to j3 and so on until we start again with j1, j2, ... Whenever a job terminates we continue the round robin with the remaining jobs.

    Going back to the jobs considered earlier, let's examine their response time under the RR scheduling discipline for a variety of values of Q.

    In case that Q is 2, the schedule has form

    1:2:3:4:1:2 :3:4:1 :3:4:3 :4

    and job 2 will terminate after 11 seconds, job 1 after a total of 17 seconds, job 3 after a total of 23 seconds, and job 4 after 24.
    That is, the (average) Response Time is (11+17+23+24)/4 = 75/4 = 18.75.

    In case that Q is 1, the schedule has form

    1:2:3:4:1:2:3:4:1:2 :3:4:1:3:4:1:3:4:1 :3:4:3:4 :3

    and job 2 will terminate after 10 seconds, job 1 after a total of 19 seconds, job 4 after a total of 23 seconds, and job 3 after 24.
    That is, the (average) Response Time is (10+19+23+24)/4 = 76/4 = 19.

    As you have seen, in Round-Robin both the schedule and response time change with changes in the Quantum Q. For example, if Q is chosen sufficiently large, say, greater than the service time of any job, then RR becomes equal to FCFS. People have chosen to evaluate RR when the value of the quantum goes to 0. In this case we say that we are in the processor sharing situation. Processor sharing seems to be the fairest way of using the computer since each user receives at all times the same amount of time, but it is inefficient because of all the process switches it requires (each process switch takes from 0.1 to 1ms, (thread switches can be almost an order of magnitude faster)). In practice the quantum tends to be 10 to 100 milliseconds.

    In our example, job 2 will terminate after 12 seconds, job 1 after a total of 21 seconds, job 4 after a total of 23 seconds, and job 3 after 24 seconds. That is, the (average) Response Time becomes 80/4 = 20.

    Notice that:

    ingargiola.cis.temple.edu