码迷,mamicode.com
首页 > 编程语言 > 详细

加权轮询算法

时间:2019-12-19 23:39:47      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:个数   this   range   serve   dex   data-   title   edit   start   

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
}




加权轮询算法

标签:个数   this   range   serve   dex   data-   title   edit   start   

原文地址:https://www.cnblogs.com/hualou/p/12070688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!