diff --git a/docs/zh-cn/source_code_guide/loadbalance.md b/docs/zh-cn/source_code_guide/loadbalance.md index d86f9bf4c178..658ea3e5da97 100644 --- a/docs/zh-cn/source_code_guide/loadbalance.md +++ b/docs/zh-cn/source_code_guide/loadbalance.md @@ -233,7 +233,7 @@ int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Con offsetWeight -= getWeight(invokers.get(leastIndex), invocation); ``` -问题出在服务预热阶段,第一行代码直接从 url 中去权重值,未被降权过。第二行代码获取到的是经过降权后的权重。第一行代码获取到的权重值最终会被累加到权重总和 totalWeight 中,这个时候会导致一个问题。offsetWeight 是一个在 [0, totalWeight) 范围内的随机数,而它所减去的是经过降权的权重。很有可能在经过 leastCount 次运算后,offsetWeight 仍然是大于0的,导致无法选中 Invoker。这个问题对应的 issue 为 [#904](https://github.com/apache/incubator-dubbo/issues/904),并在 pull request [#2172](https://github.com/apache/incubator-dubbo/pull/2172) 中被修复。具体的修复逻辑是将标注一处的代码修改为: +问题出在服务预热阶段,第一行代码直接从 url 中取权重值,未被降权过。第二行代码获取到的是经过降权后的权重。第一行代码获取到的权重值最终会被累加到权重总和 totalWeight 中,这个时候会导致一个问题。offsetWeight 是一个在 [0, totalWeight) 范围内的随机数,而它所减去的是经过降权的权重。很有可能在经过 leastCount 次运算后,offsetWeight 仍然是大于0的,导致无法选中 Invoker。这个问题对应的 issue 为 [#904](https://github.com/apache/incubator-dubbo/issues/904),并在 pull request [#2172](https://github.com/apache/incubator-dubbo/pull/2172) 中被修复。具体的修复逻辑是将标注一处的代码修改为: ```java // afterWarmup 等价于上面的 weight 变量,这样命名是为了强调该变量经过了 warmup 降权处理