1 Star 1 Fork 0

鸟窝 / rpcx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
smooth-weighted-round-robin.go 870 Bytes
一键复制 编辑 原始数据 按行查看 历史
鸟窝 提交于 2017-10-19 17:22 . implement all Selectors
package client
// Weighted is a wrapped server with weight
type Weighted struct {
Server string
Weight int
CurrentWeight int
EffectiveWeight int
}
// func (w *Weighted) fail() {
// w.EffectiveWeight -= w.Weight
// if w.EffectiveWeight < 0 {
// w.EffectiveWeight = 0
// }
// }
//https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35
func nextWeighted(servers []*Weighted) (best *Weighted) {
total := 0
for i := 0; i < len(servers); i++ {
w := servers[i]
if w == nil {
continue
}
//if w is down, continue
w.CurrentWeight += w.EffectiveWeight
total += w.EffectiveWeight
if w.EffectiveWeight < w.Weight {
w.EffectiveWeight++
}
if best == nil || w.CurrentWeight > best.CurrentWeight {
best = w
}
}
if best == nil {
return nil
}
best.CurrentWeight -= total
return best
}
Go
1
https://gitee.com/smallnest/rpcx.git
git@gitee.com:smallnest/rpcx.git
smallnest
rpcx
rpcx
7b90ccb33be5

搜索帮助