Laboratory: Process Scheduling
CSC 105 - The Digital Age

Summary and Goals:

In this lab, you will use a simulation of an operating system scheduler. You will measure the effectiveness and tradeoffs of several scheduling algorithms, including:

Preparation

  1. In a terminal window, move to your 105 directory.
  2. Copy the following files to your directory (remember, the last dot is important!):
     cp ~weinman/courses/CSC105/labs/sim* .
     cp ~weinman/courses/CSC105/labs/jobdata.txt .
  3. Open an new OpenOffice spreadsheet for collecting simulation data.

You will be running scheduler simulations on a set of jobs with random arrival times, required processing times (job length), and priorities. The file jobdata.txt that you copied contains this information (each row is the data for one job). Below is a plot illustrating the data. The horizontal axis is an arbitrary time unit (say, milliseconds). Each line represents a job. The left endpoint of the line illustrates the start time and the right endpoint the end time. Thus, the length of the line is the processing time. Lines are organized vertically by arrival time so that it is easy to see overlapping requests. The color corresponds to priority--warmer being higher priority, and cooler being lower priority.

For instance, you should be able to see that at time 1500 there are a lot of short jobs arriving near the same time, and at about time 2250 several longer jobs arrive.

Part I: Non-Preemptive Scheduling

Recall that an operating system using non-preemptive scheduling has some mechanism for choosing jobs that have arrived to be processed but lets each task run to completion before choosing the next to run.

The first come first served (FCFS) scheduling method simply makes the jobs "get in line" as they arrive, and chooses the first job in line to be run. The shortest job next (SJN) scheduling method always selects the job requiring the least amount of running time from among those waiting.

Remember that there is some overhead in choosing the next job to run. That is, the scheduler itself takes time away from jobs that are asking for processing time. In this part, you will experiment with the effectiveness of these algorithms under varying amounts of overhead.

Exercise 1

  1. The program simfcfs simulates a FCFS operating system using the jobs in jobdata.txt. In your terminal window, the command to run the simulation has the form:

      ./simfcfs jobdata.txt overhead
    where overhead is a number representing the amount of time required by the scheduler to choose the next job to run.

    For instance, you can run a simulation with an overhead of 1 ms with the command:

      ./simfcfs jobdata.txt 1

    Run the program for an arbitrary value of overhead. (You may wish to know that the average job length in the list of jobs is about 34ms, and the median is 7ms. Presumably, scheduler overhead is much shorter than this.)

  2. Inspect the summary statistics output by the program to make sure you understand what it is reporting.

Exercise 2

  1. Gather statistics on the number of context switches, system throughput, and average wait time for a range of values for the overhead. I.e., you might try at least: 0, 0.01, 0.02, 0.03, and 0.04. Record these values in an organized fashion in your spreadsheet.
  2. Try more extreme values for the overhead. What happens to the throughput and wait time as the overhead gets much larger, approaching the magnitude of the typical job length?

Exercise 3

  1. The program simsjn simulates a shortest job next (SJN) operating system . In your terminal window, the command to run the simulation has the form:
      ./simsjn jobdata.txt overhead
    Run the program for an arbitrary value of overhead.
  2. Gather the same statistics using the same overhead values for the SJN algorithm as you did for FCFS, entering them into your spreadsheet.
  3. If you do not notice any difference in performance, you may wish to try new values for the overhead for either FCFS or SJN or both, in an effort to draw conclusions.

Exercise 4

  1. For FCFS, what is the trend on system throughput as overhead increases? For SJN?
  2. What is the optimal throughput?
  3. For FCFS, what is the trend on average wait time as overhead increases? For SJN?
  4. How does average wait time compare between the FCFS and SJN algorithms?

Part II: Preemptive Scheduling

A preemptive scheduler runs part of a job for some small portion of time (called the quantum), before reclaiming the processor for another job. Eventually, a partially run job will return to the CPU for processing. The exact ordering depends on the scheduling algorithm.

The round-robin (RR) scheduling algorithm rotates through all jobs waiting. In other words, everyone forms a line, just like FCFS, but the job using the CPU gets kicked out after a set amount of time and goes to the back of the line. Longer jobs will therefore have to get in line more times than shorter jobs.

Exercise 1

  1. The program simfcfs also simulates a round-robin operating system scheduler. In your terminal window, the command to run the simulation has the form:

      ./simfcfs jobdata.txt overhead quantum
    where overhead is a number representing the amount of time required by the scheduler to choose the next job to run, and quantum is the length of time a job runs before being preempted.

    Run the program for arbitrary values of overhead and quantum. (You may wish to know that the average job length in the list of jobs is about 34ms, and the median is 7ms. Presumably, scheduler overhead is much shorter than this and the time quantum is longer than the overhead.)

  2. The summary statistics output by the program are the same. Be sure they make sense.

Exercise 2

  1. Gather statistics on the number of context switches, system throughput, and average wait time for a range of values for the overhead and time quantum. Try at least: 0, 0.01, 0.02, 0.03, and 0.04 for the overhead and 0.05, 0.1, 0.15, and 0.2 for the quantum. Record these values in an organized fashion in your spreadsheet.

    In other words, you should be able to fill in the following table for context switches, throughput, and average wait time:
    Time Quantum
    0.05 0.10 0.15 0.20
    Overhead 0.00
    0.01
    0.02
    0.03
    0.04

  2. Explore how the data changes as the overhead approaches the time quanta (i.e., when they become very close in value).

Exercise 3

  1. What is the trend on system throughput as overhead increases?
  2. What is the trend on average wait time as overhead increases?
  3. What is the trend on system throughput as the time quantum increases?
  4. What is the trend on average wait time as the time quantum increases?
  5. What do you suppose should happen if you increased the time quantum to the longest job length? (In this data, it is about 180ms).
  6. Run the program to test your hypothesis.
  7. How do the average wait times compare for this preemptive algorithm and the two non-premptive algorithms?
  8. How does the system throughput compare for this preemptive algorithm and the two non-premptive algorithms?

Part III: Priority Scheduling

A priority scheduling algorithm also uses variation on the preemptive round-robin approach. Every job has a priority associated with it. We want high priority jobs to run sooner than low priority jobs. Therefore, we maintain separate lines for jobs of each priority. A job of a certain priority is selected to run ONLY when no jobs of higher priority are waiting. In addition, to ensure that high priority jobs don't wait very long, the time quantum for low priority jobs is shorter than the time quantum for high priority jobs.

Exercise 1

  1. The program simpri simulates a preemptive priority operating system scheduler. In your terminal window, the command to run the simulation has the form:

      ./simpri jobdata.txt overhead quantum
    where overhead is a number representing the amount of time required by the scheduler to choose the next job to run, and quantum is the length of time the highest priority jobs run before being preempted. Successively lower priorities receive half the time quantum.

    Run the program for arbitrary values of overhead and quantum. (You may wish to know that the average job length in the list of jobs is about 34ms, and the median is 7ms. Presumably, scheduler overhead is much shorter than this and the time quantum is longer than the overhead.)

  2. The summary statistics output by the program are mostly the same. However, in addition to the previous statistics, average wait time is now also reported for each job priority. Be sure to ask if you have questions about this.

Exercise 2

  1. Run the program with quantum of both 0.2 and 0.5, where the overhead is 0.01 both times. Collect the number of context switches, system throughput and average wait time by priority (ten values) for both quanta.
  2. Based on this data, you may wish to experiment with various values for the time quanta (and/or overhead) to see how they relate.

Exercise 3

  1. How does the average wait time by priority tend to change when the quantum is increased? Is this true for all priorities? (I.e., where are there exceptions?)
  2. If there are exceptions to the trend, why do you suppose they exist?
  3. How do the average wait times for the higher priority jobs compare to the other scheduling algorithms you have investigated. Is this an improvement?
  4. How do the average wait times for lower priority jobs compare to the other scheduling algorithms? Is this acceptable?
  5. How does the number of context switches for priority scheduling compare to the round-robin scheduling algorithm?
  6. How does the total throughput for priority scheduling compare to the other algorithms? Why is this so? (Consider the number of context switches and the scheduler overhead.)
  7. Given the throughput and average wait time by priority, is this an acceptable scheduling algorithm? Why or why not?
Created: Jerod Weinman, 17 March 2009
Updated: Jerod Weinman, 15 May 2011
Copyright © 2009-2011 Jerod Weinman.
CC-BY-NC-SA This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License .