CS 111 - Operating Systems Principles

      Notes by Wade Norris


Lecture 19: Thursday, June 3, 2010

Topic: Scheduling and Cloud Computing

Textbook Reading: Sections 6.3 to 6.3.3

Outside Reading: Above the Clouds (PDF)


Scheduling

Introduction

Scheduling provides a solution to the the common problem of too much demand for computation with too little resources. If your computer cannot handle the number of processes currently running then the OS must decide which processes to run when. If many processes are asking for common resources how will we divide up access to these processes. When the kernel decide the order of execution of these many processes it will strive to do so in a fair way that enhances the preformance of the computer. In some situtions we may not want to even give access to the resources to some requests, making scheduling essentially a "glorified bouncer".

Types of Scheduling

Scheduling Metrics

Scheduling metrics are different methods of measuring the effectiveness of a scheduler at giving processes access to the CPU. There are multiple metrics used for measuring different aspects of the processes' execution timing. There different metrics all important for different things: some applications require a quick initial batch of execution while others are only concerned with how long it takes untill they complete execution. The following metrics are the ones we will use to analyze different scheduling algorithms.

Common Metrics

Which metrics are important to certain applications?

Aggregate Statistics

Generally in scheduling the goal is to maximize utilization and throughput while minimizing wait time, response time, and turnaround time. Sometimes though these goals can conflict and great difficulties in optimizing scheduling. Frequently we will have to sacrifice one metric in order to benefit the other.

Common Scheduling Algorithms

Example Process Set

For this example of each type of scheduling algorithm lets say we have 4 processes. Process A, B, C, and D will be attempting to get access to the CPU. The arrival times will 0, 1, 2, and 3 and the run times will be 5, 2, 9, and 4 respectively. We will now go through different algorithms and in what order they will be executed. A letter in the execution order will represent one time unit of execution. The letter Y will represent the time of a context switch between processes.

First Come First Serve
Execution Order: Y A A A A A Y B B Y C C C C C C C C C Y D D D D
Process A Wait Time: 0 + Y
Process B Wait Time: 4 + 2Y
Process C Wait Time: 5 + 3Y
Process D Wait Time: 13 + 4Y
Utilization: Almost 1
Average Wait Time: 5.5 + 2.5Y
Average Turnaround Time: 10.5 + 2.5Y

Shortest Job First
Execution Order: Y A A A A A Y B B Y D D D D Y C C C C C C C C C
Process A Wait Time: 0 + Y
Process B Wait Time: 4 + 2Y
Process C Wait Time: 9 + 4Y
Process D Wait Time: 4 + 3Y
Utilization: Almost 1
Average Wait Time: 4.25 + 2.5Y
Average Turnaround Time is the same as before.

SJF + Preemption
Execution Order: Y A Y B B Y D D D D Y A A A A Y C C C C C C C C C
Process A Wait Time: 0 + Y
Process B Wait Time: 1 + 2Y
Process C Wait Time: 9 + 5Y
Process D Wait Time: 3 + 3Y
Utilization: Almost 1 (but slightly lower with 1 more Y)
Average Wait Time: 3.25 + 2.75Y
Average Turnaround Time is higher.

Starvation

Starvation occurs when a process is caused to not get access to the CPU due to a schedueling algorithm that lets it constantly get cut of for other processes. When there is high demand of resources starvation can occur very easily. FCFS and Round-Robin algorithms will no cause starvation because they will either rotate in serving all processes or they will solve processes based on the order in which they came in, and no process will sit around without ever getting served. On the other hand SJF algorithms will interject shorter processes in front of longer processes without considering how long the other processes have been sitting around. This could cause some processes to sit around indefinitely if there is enough demand.

Realtime Scheduling

In realtime scheduling there are limitations that we do not normally have. In realtime scheduling there are time constraints that must be met or the there will be adverse reactions or the work will be wasted because it will no longer be usable.

Once big problem with priority scheduling is priority inversion. In priority inversion some high level process is waiting to get a lock on something where a low level process already has the lock. In the midst of waiting on the low level process to give up the lock a mid level process starts running. Now the high level process will keep giving up controll because it is waiting for the low level process to give up the lock, but the low level process never gets to run because the medium level process has priority. This is what caused the loss of the mars rover. How do we solve this problem? When a higher level process is waiting on a lower level process, we lend the priority level of a higher level process to the lower level process untill it gives up the lock. This prevents the problem of priority inversion.

Disk Scheduling

There are many differences between scheduling for the disk and scheduling for the CPU. The disk takes a lot longer for accesing so we want to attempt to limit the number of times we access it in any way possible. Also since there are physical arms that must position the head to read from physical locations the idea of scheduling for the disk must be much more complex and take into consideration how long it will take to position for the reads requested.

How do we solve this problem? Abstraction. The simplest and most common abstraction is stretching the entire disk into one long line of data in which the cost of access is just the distance from the read head to the location of the data.


Cloud Computing

Introduction

In cloud computing large amounts of high power computing technology can be packed into a certain remote area that can be accessed over the internet. In this manner the computer technology can be placed in a location where power is cheap and the cost of running these systems is very inexpensive. With fast internet connections now users don't actually have to own fast systems, they can just rent these systems from these technology headquarters. This has many advantages as opposed to simply buying your own computing systems. There are large shared resources with much less down time. In this system the economy can scale very well. The customers don't have to make a large time commitment, they can rent the systems for varying amounts of time and can grow as needed instantly.

Problems with Cloud Computing