算法涉及的几个概念
- weight:约定权重,在配置文件 or 初始化时指定的每个节点的权重;
- effectiveWeight:有效权重,作用是节点异常,降低其权重,初始值为 weight
在通讯过程中发现节点异常,则-1;
之后再次选取本节点,调用成功一次则+1,直达恢复到weight;
- currentWeight:节点当前权重,初始化为 0;
算法逻辑
1. 计算总权重totalWeight = sum(各节点的effectiveWeight);
2. 计算每个节点的currentWeight = currentWeight + effectiveWeight;
选择所有节点中currentWeight最大的作为选中节点;
选中节点的currentWeight = currentWeight - totalWeight;
3. 再次选择时重复第2步;
注意:本文归作者所有,未经作者允许,不得转载