GateKeeper
GateKeeper copied to clipboard
WeightRoundRobin算法 讨论一个问题
在看负载均衡算法 关于权重引入三个变量weight,currentWeight,effectiveWeight 这里请问effectiveWeight的作用是什么。其值与weight是完全相同,且不会更改的。 这个值是一个预留值吗?可以通过其他元素影响这个wrr算法?
func (r *WeightRoundRobinStrategy) Next() string {
total := 0
var best *WeightNode
for i := 0; i < len(r.rss); i++ {
w := r.rss[i]
total += w.effectiveWeight
w.currentWeight += w.effectiveWeight
if w.effectiveWeight < w.weight {
w.effectiveWeight++
}
if best == nil || w.currentWeight > best.currentWeight {
best = w
}
}
if best == nil {
return ""
}
best.currentWeight -= total
return best.addr
}