Load planning with the round robin algorithm?

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

So, if I have servers A, B and C

I wanted to make sure that for every request I receive, I need to combine them. How to do it in C #?

+7
c # round-robin
source share
3 answers

For write-only definition of round robin:

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

Just use the queue. Take one top, use it and return. This ensures that the very last one will always be the last to be raised.

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

+18
source share

Same as ebpower, but focusing on the next item, not the index of the next item.

 public class RoundRobinList<T> { private readonly IList<T> _list; private readonly int _size; private int _position; public RoundRobinList(IList<T> list) { if (!list.Any()) throw new NullReferenceException("list"); _list = new List<T>(list); _size = _list.Count; } public T Next() { if (_size == 1) return _list[0]; Interlocked.Increment(ref _position); var mod = _position % _size; return _list[mod]; } } 
+6
source share

If your endpoints are accessible through a list or array, you only need to increase the index in a circle:

 public class RoundRobinIndex { volatile int index = 0; int count; public int Next { get { if (index == count) { index = 0; } return index++; } } public RoundRobinIndex(int countArg) { count = countArg; } } 
+1
source share

All Articles