A web server receives several requests from across the globe. It processes different kinds of requests which take different amounts of time.
The server runs on a single-threaded process, and thus the requests cannot be processed parallelly. As a result, the clients must wait sometime before the requests are responded to. (The waiting time is the processing time, plus the extra waiting time the request incurs before the scheduler picks it.)
The management decides to minimize the average waiting time of the requests received per day.
Keeping in mind that the requests that will arrive in future cannot be predicted, the scheduler was so engineered as to pick the request waiting which requires the least time to process.
Is this the optimal strategy?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Let t 0 , t 1 , … , t n − 1 denote the n ∈ N + processes in the order of their processing. Request i therefore has to wait T i = prev. req. j < i ∑ t j + t i for it to be processed. The average waiting time is thus:
[ t ] r c l T = = = = = n 1 ∑ i < n T i n 1 ∑ i < n ∑ j ≤ i t j ∑ j < n n 1 ∑ j ≤ i < n t j ∑ j < n n n − j t j ∑ j < n ( 1 − n j ) t j
So for the average waiting time, the processing times are weighted and summed. The j -th request is weighted 1 − n j . Clearly to minimise this expression, it is necessary and sufficient that the weights decrease as the processing times increase. Since the weights ( 1 − n j ) j < n form a strict antitone sequence, it is necessary and sufficient that the times ( t j ) j < n form a monotone sequence. Hence it is necessary and sufficient to prioritise the requests from shortest to longest processing times.