Weighted Round Robin

func (this *LoadBalance) RoundRobinByWeight() *HttpServer {
    server := this.Servers[ServerIndices[this.CurIndex]]
    this.CurIndex = (this.CurIndex + 1) % len(ServerIndices) //ServersIndices存放的是按照权重排放的索引,如3,1,2 则ServerIndices=[0,0,0,1,2,2] 然后遍历ServerIndices可以拿到按照权重得到的索引,在每一次遍历中用索引得到[3,1,2]对应的index,一个数的余数只能是0到他自己
    return server
}




Guess you like

Origin www.cnblogs.com/hualou/p/12070688.html