Nginx平滑的基于权重轮询算法描述为:
Algorithm is as follows: on each peer selection we increase current_weight of each eligible peer by its weight, select peer with greatest current_weight and reduce its current_weight by total number of weight points distributed among peers.
算法执行2步,选择出1个当前节点:
- 每个节点,用它们的当前值加上它们自己的权重。
- 选择当前值最大的节点为选中节点,并把它的当前值减去所有节点的权重总和。
例如{a:5, b:1, c:1}
三个节点,里面的{5,1,1}
分别代表abc节点的权重。一开始我们初始化三个节点的当前值为{0, 0, 0}
。 选择过程如下表:
轮数 | 选择前的当前权重 | 选择节点 | 选择后的当前权重 |
---|---|---|---|
1 | {5,1,1} | a | {-2,1,1} |
2 | {3,2,2} | a | {-4,2,2} |
3 | {1,3,3} | b | {1,-4,3} |
4 | {6,-3,4 |