Ribbon - WeightedResponseTimeRule原理

根据响应时间计算权重,响应越长,权重越低,权重越低的服务器,被选择的可能性就越低
//定时统计权重
serverWeightTimer.schedule(new DynamicServerWeightTask(), 0,
serverWeightTaskTimerInterval);
//权重数组(server存储的位置对应权重数组的位置)
//index处的权重为前面所有权重及index本身权重之和
private volatile List<Double> accumulatedWeights = new ArrayList<Double>();
//随机0-最大权重
double randomWeight = random.nextDouble() * maxTotalWeight;
// pick the server index based on the randomIndex
int n = 0;
for (Double d : currentWeights) {
if (d >= randomWeight) { //选出落在这个权重位置的index
serverIndex = n;
break;
} else {
n++;
}
} server = allList.get(serverIndex);
 
上一篇:SQLSERVER:计算数据库中各个表的数据量和每行记录所占用空间


下一篇:git diff 的用法