dubbo3一致性负载均衡,请示服务提供者会变化,负载均衡没有生效

本文分析了Dubbo 3.0.5中ConsistentHashLoadBalance的实现变化,指出与2.7.10版本的不一致行为,并探讨可能的原因和场景影响。通过源码解读,揭示了请求分发策略的调整及其对一致性原则的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值