dubbo负载均衡策略

≡放荡痞女 提交于 2019-11-29 22:53:07

客户端调用服务端时,如何选择调用服务端的哪台机器上的服务呢。这就设计到负载均衡策略了。

在这里插入图片描述
默认使用的是RoundRobinLoadBalance,轮训策略,或者说是加权轮训策略
除此之外,还有随机策略,加权随机策略
最不活跃策略
以及一致性hash策略

还有在DubboInvoker里面我们可以看到,我们与服务端的某台机器建立的是多个连接(默认是两个),那么需要从连接里面选一个出来。

    @Override
    protected Result doInvoke(final Invocation invocation) throws Throwable {
        RpcInvocation inv = (RpcInvocation) invocation;
        final String methodName = RpcUtils.getMethodName(invocation);
        inv.setAttachment(Constants.PATH_KEY, getUrl().getPath());
        inv.setAttachment(Constants.VERSION_KEY, version);
        
        ExchangeClient currentClient;
        if (clients.length == 1) {
            currentClient = clients[0];
        } else {
            currentClient = clients[index.getAndIncrement() % clients.length];
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!