Round Robin

After reviewing it recently nginx, I saw that the default load balancing scheduling algorithm is round robin, that is, the round-robin scheduling algorithm.
The algorithm itself is very simple, one by one , very simple, efficient and fair scheduling algorithm.

Simple algorithm implementation:

int datas = [1, 2, 3, 4, 5];
int size = 5;
...
...
...
int GetNextData()
{
    
    
	static int curIdx = 0;
	int nextData = datas[curIdx];
	curIdx = (curIdx + 1) % size;
	return nextData;
}

Suddenly found a problem that has been ignored, why is it called round robin?

robinObviously it is a traveling thrush, also known as an American robin, and has nothing to do with polling. After searching the information, I found that the source of this word is quite interesting. Share it with everyone here.
round robinIt comes from French ruban rond(round ribbon)and means circular ribbon.

In the 17th and 18th centuries, when French farmers wanted to protest against the king by petition, the monarch’s response was usually to arrest and execute the first two or three persons in the petition. So naturally no one wanted their name to be listed. front. In order to deal with this kind of authoritarian retaliation, people signed their names in a circle (like a looped band) at the bottom of the petition, so that the leader could not be found, so all participants had to be punished in the same way. In 1731, the Royal Navy first used this term to sign petitions in a circular sequence, so that it would be impossible to find the leader.

It's very appropriate. The back-end server takes turns to process the request. Don't grab one by one. They must come out to accept the execution.

Guess you like

Origin blog.csdn.net/xp178171640/article/details/106007818