VOOZH about

URL: https://www.geeksforgeeks.org/dsa/calculate-server-loads-using-round-robin-scheduling/

⇱ Calculate server loads using Round Robin Scheduling - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Calculate server loads using Round Robin Scheduling

Last Updated : 23 Jul, 2025

Given M servers that handle multiple requests having infinite computational capability and arrays arrivalTime[] and processTime[] of size N denoting the arrival time and load time of N requests in the following manner:

  • Each server is numbered from 0 to (M - 1) and the requests are given in strictly increasing order of time.
  • Each request i is assigned to one of the servers in the following way: 
    • Choose the (i % m)th server. If the chosen server is free, assign the request to the server.
    • Otherwise, choose the next available server. If no server is available, then the request is dropped.

Considering that each server can handle only one request at a time, the task is to find the load on each server after all the incoming requests are processed given that load on each server is the number of requests it processes.
 

Examples:


 

Input: N = 4, M = 3, arrivalTime[] = {1, 3, 6, 8}, processTime[] = {1, 2, 2, 1}
Output:
1st Server -> 2
2nd Server -> 1
3rd Server -> 1
Explanation:
The first and fourth requests are assigned to the first server.
The second request is assigned to the second server and the third request is assigned to the third server.
Below is the transition table:

Request NumberArrival TimeLoad TimeEnd TimeAvailable ServersDemanded ServerAssigned Server
01120, 1, 200
13250, 1, 211
26280, 1, 222
38190, 1, 211

Input: N = 4, M = 2, arrivalTime = {1, 2, 4, 6}, processTime = {7, 1, 4, 4}
Output:
1st Server -> 1
2nd Server -> 2
Explanation:
The first request is assigned to the first server and second request to the second server.
The third request is assigned to the second server. The demanded server for the third request is the first server but since, it is busy at the arrival time of the request,  
So, the second server is assigned to it.
The fourth request is dropped as both servers are busy at the time of its arrival.
Below is the transition table: 

Request NumberArrival TimeLoad TimeEnd TimeAvailable ServersDemanded ServerAssigned Server
01780, 100
1213111
2448101
36410-1-


 


 

Approach: The idea is to use a Minimum Priority Queue and a set. Priority queue keeps count of the busy servers and helps to release them as soon as they are free. Set is used to maintain the data of available servers to assign them to the incoming requests. Below are the steps:


 

  • Initialize an auxiliary array loadOnServer[] that will store the load on each server.
  • Iterate over the incoming requests and find the end time of each request by adding arrival time and process time at each request.
  • Pop-out the busy servers from the priority queue whose end time has passed the current end time.
  • If the set of available servers is empty, drop the current request.
  • Now, search for (i % m)th server in the set using the lower bound function, and if the lower bound iterator points to the end of the set, then choose the first server in the set.
  • Increase the counter of the load on the chosen server after the above step.
  • After the above steps, print all the load's stores in loadOnServer[].


 

Below is the implementation of the above approach:


 


Output: 
1st Server -> 1.
2st Server -> 2.

 

Time Complexity: O(N*log M)
Auxiliary Space: O(M)

Comment