seegongsik
Saved words
Operating systems

Deciding who goes first

One seat, many waiting. The calling order changes the wait.

01

Who gets called first

There is one counter but several people waiting.
Since only one can be called at a time, you have to decide who goes first. The one who arrived first? The one whose errand finishes fast? The urgent one?
Deciding this calling order is scheduling. Tasks line up in front of a CPU too, and someone has to decide which one is handled first.

Counterwaitingcalled now

One seat, many waiting. You decide the calling order.

Scheduling is deciding which of the waiting tasks gets handled first.

02

Change the order, change the wait

There are the same three guests. One has a long task, two have short ones.
The top row calls them in arrival order. If the long one is first, the two short ones behind it wait a long while until it finishes. The bottom row calls the short ones first. The two short ones finish quickly, leaving just the long one.
Same guests, same tasks, yet changing only the order changed the average time everyone waited.

Arrival order411Avg wait 3.0Short first114Avg wait 1.0

Even the same three wait differently depending on the calling order.

Even with the same amount of work, changing the order changes the average wait.

03

Set the order yourself

Four guests are waiting. Each has a task of a different length.
As you change who gets called first, the average time everyone waited shows up right below.
Put short tasks up front and the average drops. Put long ones up front and it rises. Try moving them around and find which order shrinks the average the most.

Guest 1
4
Guest 2
1
Guest 3
3
Guest 4
2
Average wait4.25
The more you move short tasks to the front, the lower the average. Move them around and find the lowest value.

Reorder them and watch how the average wait changes.

Putting short tasks first lowers the average wait, but that is not always the right call.

04

Faster is not always better

If you always call short tasks first, the average drops. But a guest with a very long task can keep getting pushed back and wait forever.
So there is another way. Instead of giving it all to one, you give everyone a little turn, back and forth. No one gets stuck at the end forever.
The catch is that switching often costs time to change seats. Choose speed or choose fairness, but there is no free choice.

All to oneFast, but someone keeps waitingSpeedFairnessTake turnsFair, but switching costs

Short-first is fast, but a long task can keep getting pushed back.

The speed that lowers the average and the fairness where no one is stuck are traded against each other.

05

Put it on one page

Just remember three things.
First, scheduling is deciding the calling order, because there is one seat and many waiting tasks.
Second, changing the order changes the average wait. Putting short tasks first lowers the average. Third, even so there is no single right answer. Speed and fairness trade against each other, and switching often costs time too.

One
Scheduling is deciding the calling order. One seat, many waiting tasks.
Two
Changing the order changes the average wait. Short tasks first lowers it.
Three
There is no single answer. Speed and fairness trade off, and frequent switching costs time.

Order changes the average, and speed trades against fairness.

In one lineScheduling is shaping the wait by setting the order, and it needs a choice that fits the situation.
Was this helpful? Support seegongsik
Operating systems