GateKeeper icon indicating copy to clipboard operation
GateKeeper copied to clipboard

WeightRoundRobin算法 讨论一个问题

Open zhaoshoucheng opened this issue 4 years ago • 0 comments

在看负载均衡算法 关于权重引入三个变量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
}

zhaoshoucheng avatar Feb 28 '22 15:02 zhaoshoucheng