问题描述
dubbo版本3.0.5,两个服务提供者A、B
当消费者请示OrderService 服务时,A调用三次,然后B调用一次,然后A调用三次,然后B调用一次,不断循环,相同请示没有有只请示一个服务者。
java源代码
@DubboReference(version="b",loadbalance = "consistenthash")
public OrderService orderServiceB;
dubbo3.0.5的ConsistentHashLoadBalance.java 源代码
private Invoker<T> selectForKey(long hash) {
Map.Entry<Long, Invoker<T>> entry = virtualInvokers.ceilingEntry(hash);
if (entry == null) {
entry = virtualInvokers.firstEntry();
}
String serverAddress = entry.getValue().getUrl().getAddress();
/**
* The following part of codes aims to select suitable invoker.
* This part is not complete thread safety.
* However, in the scene of consumer-side load balance,
* thread race for this part of codes
* (execution time cost for this part of codes without any IO or
* network operation is very low) will rarely occur. And even in
* extreme case, a few requests are assigned to an invoker which
* is above OVERLOAD_RATIO_THREAD will not make a significant impact
* on the effect of this new algorithm.
* And make this part of codes synchronized will reduce ef