<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5">
    <title>使用Dubbo中需要注意的事项 | 云图网</title>
    <meta name="keywords" content="aliyun">
<meta name="description" content="一、前言 Dubbo作为高性能RPC框架，已经进入Apache卵化器项目，虽然官方给出了dubbo使用的用户手册，但是大多是一概而过，使用dubbo时候要尽量了解源码，不然会很容易入坑。 二 、服务消费端ReferenceConfig需要自行缓存 ReferenceConfig实例是个很重的实例，每个Reference…">
<meta property="og:type" content="article">
<meta property="og:url" content="https://blog.ytso.com/tech/pnotes/68776.html">
<meta property="og:site_name" content="云图网">
<meta property="og:title" content="使用Dubbo中需要注意的事项">
<meta property="og:image" content="https://imgcdn.ytso.com/wp-content/uploads/2021/08/11/20210811_611368737517f.png">
<meta property="og:description" content="一、前言 Dubbo作为高性能RPC框架，已经进入Apache卵化器项目，虽然官方给出了dubbo使用的用户手册，但是大多是一概而过，使用dubbo时候要尽量了解源码，不然会很容易入坑。 二 、服务消费端ReferenceConfig需要自行缓存 ReferenceConfig实例是个很重的实例，每个Reference…">
<link rel="canonical" href="https://blog.ytso.com/tech/pnotes/68776.html">
<meta name="applicable-device" content="pc,mobile">
<meta http-equiv="Cache-Control" content="no-transform">
<link rel="shortcut icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg">
<link rel='dns-prefetch' href='//cdnjs.cloudflare.com' />
<style id='wp-img-auto-sizes-contain-inline-css' type='text/css'>
img:is([sizes=auto i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}
/*# sourceURL=wp-img-auto-sizes-contain-inline-css */
</style>
<link rel='stylesheet' id='stylesheet-css' href='https://blog.ytso.com/wp-content/themes/justnews/css/style.css?ver=6.21.5' type='text/css' media='all' />
<link rel='stylesheet' id='material-icons-css' href='https://blog.ytso.com/wp-content/themes/justnews/themer/assets/css/material-icons.css?ver=6.21.5' type='text/css' media='all' />
<link rel='stylesheet' id='remixicon-css' href='https://cdnjs.cloudflare.com/ajax/libs/remixicon/4.2.0/remixicon.min.css?ver=6.9.4' type='text/css' media='all' />
<link rel='stylesheet' id='font-awesome-css' href='https://blog.ytso.com/wp-content/themes/justnews/themer/assets/css/font-awesome.css?ver=6.21.5' type='text/css' media='all' />
<style id='wp-block-library-inline-css' type='text/css'>
:root{--wp-block-synced-color:#7a00df;--wp-block-synced-color--rgb:122,0,223;--wp-bound-block-color:var(--wp-block-synced-color);--wp-editor-canvas-background:#ddd;--wp-admin-theme-color:#007cba;--wp-admin-theme-color--rgb:0,124,186;--wp-admin-theme-color-darker-10:#006ba1;--wp-admin-theme-color-darker-10--rgb:0,107,160.5;--wp-admin-theme-color-darker-20:#005a87;--wp-admin-theme-color-darker-20--rgb:0,90,135;--wp-admin-border-width-focus:2px}@media (min-resolution:192dpi){:root{--wp-admin-border-width-focus:1.5px}}.wp-element-button{cursor:pointer}:root .has-very-light-gray-background-color{background-color:#eee}:root .has-very-dark-gray-background-color{background-color:#313131}:root .has-very-light-gray-color{color:#eee}:root .has-very-dark-gray-color{color:#313131}:root .has-vivid-green-cyan-to-vivid-cyan-blue-gradient-background{background:linear-gradient(135deg,#00d084,#0693e3)}:root .has-purple-crush-gradient-background{background:linear-gradient(135deg,#34e2e4,#4721fb 50%,#ab1dfe)}:root .has-hazy-dawn-gradient-background{background:linear-gradient(135deg,#faaca8,#dad0ec)}:root .has-subdued-olive-gradient-background{background:linear-gradient(135deg,#fafae1,#67a671)}:root .has-atomic-cream-gradient-background{background:linear-gradient(135deg,#fdd79a,#004a59)}:root .has-nightshade-gradient-background{background:linear-gradient(135deg,#330968,#31cdcf)}:root .has-midnight-gradient-background{background:linear-gradient(135deg,#020381,#2874fc)}:root{--wp--preset--font-size--normal:16px;--wp--preset--font-size--huge:42px}.has-regular-font-size{font-size:1em}.has-larger-font-size{font-size:2.625em}.has-normal-font-size{font-size:var(--wp--preset--font-size--normal)}.has-huge-font-size{font-size:var(--wp--preset--font-size--huge)}.has-text-align-center{text-align:center}.has-text-align-left{text-align:left}.has-text-align-right{text-align:right}.has-fit-text{white-space:nowrap!important}#end-resizable-editor-section{display:none}.aligncenter{clear:both}.items-justified-left{justify-content:flex-start}.items-justified-center{justify-content:center}.items-justified-right{justify-content:flex-end}.items-justified-space-between{justify-content:space-between}.screen-reader-text{border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-wrap:normal!important}.screen-reader-text:focus{background-color:#ddd;clip-path:none;color:#444;display:block;font-size:1em;height:auto;left:5px;line-height:normal;padding:15px 23px 14px;text-decoration:none;top:5px;width:auto;z-index:100000}html :where(.has-border-color){border-style:solid}html :where([style*=border-top-color]){border-top-style:solid}html :where([style*=border-right-color]){border-right-style:solid}html :where([style*=border-bottom-color]){border-bottom-style:solid}html :where([style*=border-left-color]){border-left-style:solid}html :where([style*=border-width]){border-style:solid}html :where([style*=border-top-width]){border-top-style:solid}html :where([style*=border-right-width]){border-right-style:solid}html :where([style*=border-bottom-width]){border-bottom-style:solid}html :where([style*=border-left-width]){border-left-style:solid}html :where(img[class*=wp-image-]){height:auto;max-width:100%}:where(figure){margin:0 0 1em}html :where(.is-position-sticky){--wp-admin--admin-bar--position-offset:var(--wp-admin--admin-bar--height,0px)}@media screen and (max-width:600px){html :where(.is-position-sticky){--wp-admin--admin-bar--position-offset:0px}}
/*wp_block_styles_on_demand_placeholder:69c80f77c74da*/
/*# sourceURL=wp-block-library-inline-css */
</style>
<style id='classic-theme-styles-inline-css' type='text/css'>
/*! This file is auto-generated */
.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
/*# sourceURL=/wp-includes/css/classic-themes.min.css */
</style>
<link rel='stylesheet' id='wpcom-member-css' href='https://blog.ytso.com/wp-content/plugins/wpcom-member/css/style.css?ver=1.7.19' type='text/css' media='all' />
<script type="text/javascript" src="https://blog.ytso.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.1" id="jquery-core-js"></script>
<script type="text/javascript" src="https://blog.ytso.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.1" id="jquery-migrate-js"></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://blog.ytso.com/xmlrpc.php?rsd" />
<meta name='description' content='一、前言 Dubbo作为高性能RPC框架，已经进入Apache卵化器项目，虽然官方给出了dubbo使用的用户手册，但是大多是一概而过，使用dubbo时候要尽量了解源码，不然会很容易入坑。 二 、服务消费端ReferenceConfig需要自…' />
<meta name='keywords' content='aliyun' />
<style>:root{--theme-color: #08c; --theme-hover: #07c; --logo-height: 32px; --logo-height-mobile: 26px; --menu-item-gap: 28px; --member-login-bg: url('https://blog.ytso.com/loginwall.jpg'); --header-bg-color: #fff; --header-bg-image: none; --theme-border-radius-s: 3px; --theme-border-radius-m: 5px; --theme-border-radius-l: 8px; --theme-border-radius-xl: 12px; --thumb-ratio-default: 480 / 300; --thumb-ratio-post: 480 / 300; --post-video-ratio: 860 / 482;}</style>
<link rel="icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" sizes="32x32" />
<link rel="icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" sizes="192x192" />
<link rel="apple-touch-icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" />
<meta name="msapplication-TileImage" content="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" />
    <!--[if lte IE 11]><script src="https://blog.ytso.com/wp-content/themes/justnews/js/update.js"></script><![endif]-->
</head>
<body class="wp-singular post-template-default single single-post postid-68776 single-format-standard wp-theme-justnews lang-cn el-boxed header-fixed">
<header class="header header-fluid">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse" aria-label="menu">
                <span class="icon-bar icon-bar-1"></span>
                <span class="icon-bar icon-bar-2"></span>
                <span class="icon-bar icon-bar-3"></span>
            </button>
                        <div class="logo">
                <a href="https://blog.ytso.com/" rel="home">
                    <img src="https://imgcdn.ytso.com/wp-content/uploads/2021/12/20211207181156143.png" alt="云图网">
                </a>
            </div>
        </div>
        <div class="collapse navbar-collapse mobile-style-0">
            <nav class="primary-menu"><ul id="menu-justnews-footer-menu" class="nav navbar-nav wpcom-adv-menu"><li class="menu-item"><a href="https://blog.ytso.com/category/industrynews">业界资讯</a></li>
<li class="menu-item current-post-ancestor active menu-item-style menu-item-style-1 dropdown"><a target="_blank" href="https://blog.ytso.com/category/tech" class="dropdown-toggle">技术专区</a>
<ul class="dropdown-menu menu-item-wrap menu-item-col-5">
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/cloud">云计算</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/ai">人工智能</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/safety">信息安全</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/bigdata">大数据</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/dev">研发管理</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/webdev">大前端</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/opensource">开源</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/aiops">智能运维</a></li>
	<li class="menu-item current-post-ancestor current-post-parent active"><a href="https://blog.ytso.com/category/tech/pnotes">编程笔记</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/wp">WordPress</a></li>
</ul>
</li>
<li class="menu-item"><a href="https://blog.ytso.com/category/enterprise-strategic-planning">企业战略规划</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/download">下载专区</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/it%e6%b1%9f%e6%b9%96%e5%8f%b2">江湖史</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/notes">随笔记录</a></li>
</ul></nav>            <div class="navbar-action">
                <div class="navbar-search-icon j-navbar-search"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></div><form class="navbar-search" action="https://blog.ytso.com/" method="get" role="search"><div class="navbar-search-inner"><i class="wpcom-icon wi navbar-search-close"><svg aria-hidden="true"><use xlink:href="#wi-close"></use></svg></i><input type="text" name="s" class="navbar-search-input" autocomplete="off" maxlength="100" placeholder="输入关键词搜索..." value=""><button class="navbar-search-btn" type="submit" aria-label="搜索"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></button></div></form>                    <div id="j-user-wrap">
                        <a class="login" href="https://blog.ytso.com/login">登录</a>
                        <a class="login register" href="https://blog.ytso.com/register">注册</a>
                    </div>
                                            <a class="wpcom-btn btn-primary btn-xs publish" href="https://blog.ytso.com/contribute">
                            <i class="fa fa-edit"></i> 投稿                        </a>
                                </div>
        </div>
    </div><!-- /.container -->
</header>

<div id="wrap">    <div class="wrap container">
        <ol class="breadcrumb" vocab="https://schema.org/" typeof="BreadcrumbList"><li class="home" property="itemListElement" typeof="ListItem"><a href="https://blog.ytso.com" property="item" typeof="WebPage"><span property="name" class="hide">云图网</span>首页</a><meta property="position" content="1"></li><li property="itemListElement" typeof="ListItem"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-3"></use></svg></i><a href="https://blog.ytso.com/category/tech" property="item" typeof="WebPage"><span property="name">技术专区</span></a><meta property="position" content="2"></li><li property="itemListElement" typeof="ListItem"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-3"></use></svg></i><a href="https://blog.ytso.com/category/tech/pnotes" property="item" typeof="WebPage"><span property="name">编程笔记</span></a><meta property="position" content="3"></li></ol>        <main class="main">
                            <article id="post-68776" class="post-68776 post type-post status-publish format-standard has-post-thumbnail hentry category-pnotes tag-aliyun entry">
                    <div class="entry-main">
                                                                        <div class="entry-head">
                            <h1 class="entry-title">使用Dubbo中需要注意的事项</h1>
                            <div class="entry-info">
                                                                <time class="entry-date published" datetime="2021-08-11T13:39:33+08:00" pubdate>
                                    2021年8月11日 13:39                                </time>
                                <span class="dot">•</span>
                                <a href="https://blog.ytso.com/category/tech/pnotes" rel="category tag">编程笔记</a>                                                            </div>
                        </div>
                        
                                                <div class="entry-content text-indent text-justify">
                            <div id="toc">
<p class="toc-title"><strong>文章目录</strong><span class="toc-controller toc-controller-show">[隐藏]</span></p>
<ul>
<li class="toc-level1"><a href="#toc_1">一、前言</a></li>
<li class="toc-level1"><a href="#toc_2">二 、服务消费端ReferenceConfig需要自行缓存</a></li>
<li class="toc-level1"><a href="#toc_3">三、 并发控制</a>
<ul>
<li class="toc-level2"><a href="#toc_4">3.1 服务消费方并发控制</a></li>
</ul>
</li>
<li class="toc-level1"><a href="#toc_5">四、 改进的广播策略</a>
<ul>
<li class="toc-level3"><a href="#toc_6"></a></li>
</ul>
</li>
</ul>
</div>
<h1 id="toc_1">一、前言</h1>
<p>Dubbo作为高性能RPC框架，已经进入Apache卵化器项目，虽然官方给出了dubbo使用的用户手册，但是大多是一概而过，使用dubbo时候要尽量了解源码，不然会很容易入坑。<span id="more-38400"></span></p>
<h1 id="toc_2">二 、服务消费端ReferenceConfig需要自行缓存</h1>
<p>ReferenceConfig实例是个很重的实例，每个ReferenceConfig实例里面都维护了与服务注册中心的一个长链，并且维护了与所有服务提供者的的长链。假设有一个服务注册中心和N个服务提供者，那么每个ReferenceConfig实例里面维护了N+1个长链，如果频繁的生成ReferenceConfig实例，可能会造成性能问题，甚至产生内存或者连接泄露的风险。特别是使用dubbo api编程时候容易忽略这个问题。</p>
<p>为了解决这个问题，之前都是自行缓存，但是自从dubbo2.4.0版本后，dubbo 提供了简单的工具类 ReferenceConfigCache 用于缓存ReferenceConfig 实例。使用如下：</p>
<pre class="hljs cpp"><code class="cpp"><span class="hljs-comment">//创建服务消费实例</span>
ReferenceConfig&lt;XxxService&gt; reference = <span class="hljs-keyword">new</span> ReferenceConfig&lt;XxxService&gt;();
reference.setInterface(XxxService.class);
reference.setVersion(<span class="hljs-string">"1.0.0"</span>);
......
<span class="hljs-comment">//获取dubbo提供的缓存</span>
ReferenceConfigCache cache = ReferenceConfigCache.getCache();
<span class="hljs-comment">// cache.get方法中会缓存 reference对象，并且调用reference.get方法启动ReferenceConfig，并返回经过代理后的服务接口的对象</span>
XxxService xxxService = cache.get(reference);

<span class="hljs-comment">// 使用xxxService对象</span>
xxxService.sayHello();
</code></pre>
<p>需要注意的是 Cache内持有ReferenceConfig对象的引用，不要在外部再调用ReferenceConfig的destroy方法了，这会导致Cache内的ReferenceConfig失效！</p>
<p>如果要销毁 Cache 中的 ReferenceConfig ，将销毁 ReferenceConfig 并释放对应的资源，具体使用下面方法来销毁：</p>
<pre class="hljs undefined"><code class="Java">ReferenceConfigCache cache = ReferenceConfigCache.getCache()；
cache.destroy(reference);
</code></pre>
<p>另外以服务 Group、接口、版本为缓存的 Key，ReferenceConfig实例为对应的value。如果你需要使用自定义的key，可以在创建cache时候调用ReferenceConfigCache cache = ReferenceConfigCache.getCache(keyGenerator );方法传递自定义的keyGenerator。</p>
<h1 id="toc_3">三、 并发控制</h1>
<h2 id="toc_4">3.1 服务消费方并发控制</h2>
<p>在服务消费方法进行并发控制需要设置actives参数，如下：</p>
<pre class="hljs java"><code class="java">&lt;dubbo:reference id=<span class="hljs-string">"userService"</span> <span class="hljs-class"><span class="hljs-keyword">interface</span></span>=<span class="hljs-string">"com.test.UserServiceBo"</span>
        group=<span class="hljs-string">"dubbo"</span> version=<span class="hljs-string">"1.0.0"</span> timeout=<span class="hljs-string">"3000"</span> actives=<span class="hljs-string">"10"</span>/&gt;
</code></pre>
<p>设置com.test.UserServiceBo接口中所有方法，每个方法最多同时并发请求10个请求。</p>
<p>也可以使用下面方法设置接口中的单个方法的并发请求个数，如下：</p>
<pre class="hljs java"><code class="java">
    &lt;dubbo:reference id=<span class="hljs-string">"userService"</span> <span class="hljs-class"><span class="hljs-keyword">interface</span></span>=<span class="hljs-string">"com.test.UserServiceBo"</span>
        group=<span class="hljs-string">"dubbo"</span> version=<span class="hljs-string">"1.0.0"</span> timeout=<span class="hljs-string">"3000"</span>&gt;
                &lt;dubbo:method name=<span class="hljs-string">"sayHello"</span> actives=<span class="hljs-string">"10"</span> /&gt;
    &lt;/dubbo:reference&gt;
</code></pre>
<p>如上设置sayHello方法的并发请求数量最大为10，如果客户端请求该方法并发超过了10则客户端会被阻塞，等客户端并发请求数量少于10的时候，该请求才会被发送到服务提供方服务器。在dubbo中客户端并发控制是使用ActiveLimitFilter过滤器来控制的，代码如下：</p>
<pre class="hljs java"><code class="java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ActiveLimitFilter</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Filter</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> Result <span class="hljs-title">invoke</span><span class="hljs-params">(Invoker&lt;?&gt; invoker, Invocation invocation)</span> <span class="hljs-keyword">throws</span> RpcException </span>{
        URL url = invoker.getUrl();
        String methodName = invocation.getMethodName();
        <span class="hljs-comment">//获取设置的acvites的值，默认为0</span>
        <span class="hljs-keyword">int</span> max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, <span class="hljs-number">0</span>);
        <span class="hljs-comment">//获取当前方法目前并发请求数量</span>
        RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName());
        <span class="hljs-keyword">if</span> (max &gt; <span class="hljs-number">0</span>) {<span class="hljs-comment">//说明设置了actives变量</span>
            <span class="hljs-keyword">long</span> timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, <span class="hljs-number">0</span>);
            <span class="hljs-keyword">long</span> start = System.currentTimeMillis();
            <span class="hljs-keyword">long</span> remain = timeout;
            <span class="hljs-keyword">int</span> active = count.getActive();
            <span class="hljs-comment">//如果该方法并发请求数量大于设置值，则挂起当前线程。</span>
            <span class="hljs-keyword">if</span> (active &gt;= max) {
                <span class="hljs-keyword">synchronized</span> (count) {
                    <span class="hljs-keyword">while</span> ((active = count.getActive()) &gt;= max) {
                        <span class="hljs-keyword">try</span> {
                            count.wait(remain);
                        } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                        }
                        <span class="hljs-comment">//如果等待时间超时，则抛出异常</span>
                        <span class="hljs-keyword">long</span> elapsed = System.currentTimeMillis() - start;
                        remain = timeout - elapsed;
                        <span class="hljs-keyword">if</span> (remain &lt;= <span class="hljs-number">0</span>) {
                            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> RpcException(<span class="hljs-string">"Waiting concurrent invoke timeout in client-side for service:  "</span>
                                    + invoker.getInterface().getName() + <span class="hljs-string">", method: "</span>
                                    + invocation.getMethodName() + <span class="hljs-string">", elapsed: "</span> + elapsed
                                    + <span class="hljs-string">", timeout: "</span> + timeout + <span class="hljs-string">". concurrent invokes: "</span> + active
                                    + <span class="hljs-string">". max concurrent invoke limit: "</span> + max);
                        }
                    }
                }
            }
        }
        <span class="hljs-comment">//没有限流时候，正常调用</span>
        <span class="hljs-keyword">try</span> {
            <span class="hljs-keyword">long</span> begin = System.currentTimeMillis();
            RpcStatus.beginCount(url, methodName);
            <span class="hljs-keyword">try</span> {
                Result result = invoker.invoke(invocation);
                RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, <span class="hljs-keyword">true</span>);
                <span class="hljs-keyword">return</span> result;
            } <span class="hljs-keyword">catch</span> (RuntimeException t) {
                RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, <span class="hljs-keyword">false</span>);
                <span class="hljs-keyword">throw</span> t;
            }
        } <span class="hljs-keyword">finally</span> {
            <span class="hljs-keyword">if</span> (max &gt; <span class="hljs-number">0</span>) {
                <span class="hljs-keyword">synchronized</span> (count) {
                    count.notify();
                }
            }
        }
    }

}
</code></pre>
<p>可知客户端并发控制，是如果当并发量达到指定值后，当前客户端请求线程会被挂起，如果在等待超时期间并发请求量少了，那么阻塞的线程会被激活，然后发送请求到服务提供方，如果等待超时了，则直接抛出异常，这时候服务根本都没有发送到服务提供方服务器。</p>
<h1 id="toc_5">四、 改进的广播策略</h1>
<p>前面我们讲解集群容错时候谈到有一个广播策略，该策略主要用于对所有服务提供者进行广播消息，那么有个问题需要思考，广播是是说你在客户端调用接口一次，内部就是轮询调用所有服务提供者的机器的服务，那么你调用一次该接口，返回值是什么那？比如内部轮询了10台机器，每个机器应该都有一个返回值，那么你调用的这一次返回值是10个返回值的组成？其实不是，返回的是轮询调用的最后一个机器结果，那么如果我们想把所有的机器返回的结果聚合起来如何做的？  使用dubbo中更多需要注意的事情 <a href="http://gitbook.cn/gitchat/column/5adda21279e8c577efc8fbdf">单击我查看文章</a> ， <a href="https://edu.csdn.net/course/detail/8009/164145?pre_view=1">单击我观看视频</a>即可知晓。</p>
<p><noscript><img decoding="async" class="aligncenter" src="http://ytso-blog-oss-img.oss-cn-beijing.aliyuncs.com/wp-content/uploads/2021/08/11/20210811_611368737517f.png" alt="image.png" /></noscript><img decoding="async" class="aligncenter j-lazy" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png" data-original="http://ytso-blog-oss-img.oss-cn-beijing.aliyuncs.com/wp-content/uploads/2021/08/11/20210811_611368737517f.png" alt="image.png" /></p>
</p>
<h3 id="toc_6"></h3>
<div class="entry-readmore"><div class="entry-readmore-btn"></div></div>                                                        <div class="entry-copyright"><p>原创文章，作者：ItWorker，如若转载，请注明出处：https://blog.ytso.com/tech/pnotes/68776.html</p></div>                        </div>

                        <div class="entry-tag"><a href="https://blog.ytso.com/tag/aliyun" rel="tag">aliyun</a></div>
                        <div class="entry-action">
                            <div class="btn-zan" data-id="68776"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-thumb-up-fill"></use></svg></i> 赞 <span class="entry-action-num">(0)</span></div>
                                                    </div>

                        <div class="entry-bar">
                            <div class="entry-bar-inner">
                                                                <div class="entry-bar-info entry-bar-info2">
                                    <div class="info-item meta">
                                                                                    <a class="meta-item j-heart" href="javascript:;" data-id="68776"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-star"></use></svg></i> <span class="data">0</span></a>                                        <a class="meta-item" href="#comments"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-comment"></use></svg></i> <span class="data">0</span></a>                                                                            </div>
                                    <div class="info-item share">
                                                                                    <a class="meta-item mobile j-mobile-share" href="javascript:;" data-id="68776" data-qrcode="https://blog.ytso.com/tech/pnotes/68776.html">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-share"></use></svg></i> 生成海报                                            </a>
                                                                                    <a class="meta-item wechat" data-share="wechat" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-wechat"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item weibo" data-share="weibo" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-weibo"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item qq" data-share="qq" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qq"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item qzone" data-share="qzone" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qzone"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item douban" data-share="douban" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-douban"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item linkedin" data-share="linkedin" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-linkedin"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item facebook" data-share="facebook" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-facebook"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item twitter" data-share="twitter" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-twitter"></use></svg></i>                                            </a>
                                                                            </div>
                                    <div class="info-item act">
                                        <a href="javascript:;" id="j-reading"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-article"></use></svg></i></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                                            <div class="entry-page">
                    <div class="entry-page-prev j-lazy" style="background-image: url('https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png');" data-original="https://imgcdn.ytso.com/wp-content/uploads/2021/08/11/20210811_611363a795a5a.jpg?x-oss-process=image/resize,m_fill,w_480,h_300,limit_0">
                <a href="https://blog.ytso.com/tech/pnotes/68720.html" title="如何设计一款基于ROS的移动机器人？ | 雷锋网公开课" rel="prev">
                    <span>如何设计一款基于ROS的移动机器人？ | 雷锋网公开课</span>
                </a>
                <div class="entry-page-info">
                    <span class="pull-left"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-left-double"></use></svg></i> 上一篇</span>
                    <span class="pull-right">2021年8月11日 12:51</span>
                </div>
            </div>
                            <div class="entry-page-next j-lazy" style="background-image: url('https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png');" data-original="https://imgcdn.ytso.com/wp-content/uploads/2021/08/11/20210811_6113687809941.png?x-oss-process=image/resize,m_fill,w_480,h_300,limit_0">
                <a href="https://blog.ytso.com/tech/pnotes/68778.html" title="Leader-Follower线程模型概述" rel="next">
                    <span>Leader-Follower线程模型概述</span>
                </a>
                <div class="entry-page-info">
                    <span class="pull-right">下一篇 <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-double"></use></svg></i></span>
                    <span class="pull-left">2021年8月11日 13:39</span>
                </div>
            </div>
            </div>
                                        <error>
    <code>wp_die</code>
    <title><![CDATA[WordPress &amp;rsaquo; Error]]></title>
    <message><![CDATA[&lt;h1&gt;Error establishing a Redis connection&lt;/h1&gt;
&lt;p&gt;To disable Redis, delete the &lt;code&gt;object-cache.php&lt;/code&gt; file in the &lt;code&gt;/wp-content/&lt;/code&gt; directory.&lt;/p&gt;
]]></message>
    <data>
        <status>500</status>
    </data>
</error>
<!--
Performance optimized by Redis Object Cache. Learn more: https://wprediscache.com

Retrieved 1750 objects (284 KB) from Redis using Predis (v2.4.0).
-->
