IIWAB NGINX平滑加权轮询算法 - IIWAB

NGINX平滑加权轮询算法

IIWAB 8月前 ⋅ 270 阅读

算法涉及的几个概念

  1. weight:约定权重,在配置文件 or 初始化时指定的每个节点的权重;
  2. effectiveWeight:有效权重,作用是节点异常,降低其权重,初始值为 weight

在通讯过程中发现节点异常,则-1;

之后再次选取本节点,调用成功一次则+1,直达恢复到weight;

  1. currentWeight:节点当前权重,初始化为 0;

算法逻辑

1.  计算总权重totalWeight = sum(各节点的effectiveWeight);

2. 计算每个节点的currentWeight = currentWeight + effectiveWeight;

选择所有节点中currentWeight最大的作为选中节点;

选中节点的currentWeight = currentWeight - totalWeight;

3. 再次选择时重复第2步;

全部评论: 0

    我有话说: