Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling load with a round robin algorithm?

Tags:

c#

round-robin

I need to write a round robin algorithm to schedule load to n endpoints?

So if I have servers A, B and C

I wanted to make sure to round-robin through them for each request I get. How do I do this in C#?

like image 388
Nevin Mathai Avatar asked Apr 21 '10 15:04

Nevin Mathai


People also ask

What is scheduling in Round-robin scheduling?

Round Robin (RR) The simplest preemptive scheduling algorithm is round-robin, in which the processes are given turns at running, one after the other in a repeating sequence, and each one is preempted when it has used up its time slice.

What is round robin algorithm for load balancing?

What Is Round-Robin Load Balancing? Round‑robin load balancing is one of the simplest methods for distributing client requests across a group of servers. Going down the list of servers in the group, the round‑robin load balancer forwards a client request to each server in turn.

How is Round-robin scheduling algorithm calculated?

Average Turn Around time = (27 + 23 + 30 + 29 + 4 + 15) / 6 = 128 / 6 = 21.33 unit. Average waiting time = (22 + 17 + 23 + 20 + 2 + 12) / 6 = 96 / 6 = 16 unit.


1 Answers

Just for the record, definition of round robin:

http://en.wikipedia.org/wiki/Round-robin_scheduling

Just use a queue. Take one off of the top, use it and put it back. This ensures that the most recent one used will always be the last one to be picked up.

Queue<Server> q = new Queue<Server>();

//get the next one up
Server s = q.DeQueue();


//Use s;


//put s back for later use.
q.Enqueue(s);

Link to the queue class:

http://msdn.microsoft.com/en-us/library/7977ey2c.aspx

like image 145
kemiller2002 Avatar answered Oct 03 '22 14:10

kemiller2002