Skip to content

Commit

Permalink
Added CS 162 lec 10
Browse files Browse the repository at this point in the history
  • Loading branch information
hrushikeshrv committed Dec 27, 2023
1 parent 78ca66f commit d78f1bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions CS162/lec10.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ This effect is called the convoy effect, where a short-running job is stuck behi
## Round Robin Scheduling
An improvement over FIFO or FCFS is Round Robin. Round Robin puts an upper limit on the amount of time any process can run, and if it exceeds that time limit, it is preempted and swapped out with another process. This is good, because now the thread that handles user input via the keyboard can still get to run if a long-running process is trying to hog the CPU.

This is a simple but effective solution for the convoy effect, but for it to work well in the real world, we need to tune time quantum that is given to each process. If the time quantum is too large, we effectively revert back to FCFS, and if it is too small, we spend so much time context switching that even the short-running jobs are swapped out multiple times, which ultimately _reduces_ the response time. In the lecture Kubi shows the effect of different choices of time quantum on the average completion time and the average waiting time for each job.
This is a simple but effective solution for the convoy effect, but for it to work well in the real world, we need to tune time quantum that is given to each process. If the time quantum is too large, we effectively revert back to FCFS, and if it is too small, we spend so much time context switching that even the short-running jobs are swapped out multiple times, which ultimately _reduces_ the response time. In the lecture, Kubi shows the effect of different choices of time quantum on the average completion time and the average waiting time for each job.

<img src="./media/lec10-2.png" alt="Effect of different choices of time quanta on average waiting time and completion time">
<img src="./media/lec10-2.png" alt="Effect of different choices of time quanta on average waiting time and completion time">

## Shortest Job First Scheduling
This is a hypothetical version of scheduling that puts the jobs with the shortest running time first. It is hypothetical because it requires us to know the future and know exactly how long each job is going to run. A preemptive variation of this scheduling policy is called Shortest Remaining Time First (SRTF), where if a new job comes along which has an even shorter time to completion that the currently running job, the currently running job is preempted and the new job starts running.

Although this policy is proven to be the best for improving response times, it has another problem (besides needing to know the future). If short jobs keep coming along, long jobs keep getting stuck behind short jobs and potentially never run. If the short jobs never stop coming, long jobs never run. This issue makes this scheduling policy extremely unfair.

In the real world, we use various heuristics to predict how long each job will take, along with trends observed from the previous runs of the job. So we can have an imperfect version of SRTF scheduling.

When writing a scheduler for a real world OS, you may have to come up with and test multiple scheduling policies to see which one works best for the type of workload you have.
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ This work is licensed under the Creative Commons license -
8. [MIT 6.890 - Algorithmic Lower Bounds](https://docs.google.com/document/d/1R45m9aDnBevrHaDSq0DdEzmRHZFV40cQ41g7GezPBK8/edit#heading=h.j62llohq37q3)
9. [MIT 6.851 - Advanced Data Structures](https://docs.google.com/document/d/1R45m9aDnBevrHaDSq0DdEzmRHZFV40cQ41g7GezPBK8/edit#heading=h.y6d0wld558lb)
10. [CMU 15-445 - Database Systems](./CMU15445/index.md)
11. [UCB CS 162 - Operating Systems](./CS162/index.md)

0 comments on commit d78f1bc

Please sign in to comment.