1.本地开发
<dubbo:registry address="10.20.153.10:9090" register="false" />
<dubbo:reference id="xxxService" interface="com.alibaba.xxx.XxxService" url="dubbo://localhost:20890" />
2.可调优选项
结果缓存 ,⽤于加速热⻔数据的访问速度,Dubbo 提供声明式缓存,以减少⽤户加缓存的⼯作量 。
<dubbo:reference interface="com.foo.BarService" cache="lru" />
<dubbo:reference interface="com.foo.BarService">
<dubbo:method name="findBar" cache="lru" />
并发限制:
服务端
限制 com.foo.BarService 的每个⽅法,服务器端并发执⾏(或占⽤线程池线程数)不能超过 10 个:
<dubbo:service interface="com.foo.BarService" executes="10" />
<dubbo:service interface="com.foo.BarService">
<dubbo:method name="sayHello" executes="10" />
</dubbo:service>
消费端
限制 com.foo.BarService 的每个⽅法,每客户端并发执⾏(或占⽤连接的请求数)不能超过 10 个:
<dubbo:service interface="com.foo.BarService" actives="10" />
<dubbo:reference interface="com.foo.BarService" actives="10" />
<dubbo:service interface="com.foo.BarService">
<dubbo:method name="sayHello" actives="10" />
</dubbo:service>
<dubbo:reference interface="com.foo.BarService">
<dubbo:method name="sayHello" actives="10" />
</dubbo:service>
如果 <dubbo:service> 和 <dubbo:reference> 都配了actives, <dubbo:reference> 优先
配置服务的客户端的 loadbalance 属性为 leastactive ,此 Loadbalance 会调⽤并发数最⼩的 Provider(Consumer
端并发数)。
<dubbo:reference interface="com.foo.BarService" loadbalance="leastactive" />
限制服务器端接受的连接不能超过 10 个
<dubbo:service interface="com.foo.BarService" loadbalance="leastactive" />
<dubbo:protocol name="dubbo" accepts="10" />
限制客户端服务使⽤连接不能超过 10 个
<dubbo:reference interface="com.foo.BarService" connections="10" />
<dubbo:service interface="com.foo.BarService" connections="10" />
如果 <dubbo:service> 和 <dubbo:reference> 都配了 connections, <dubbo:reference> 优先
优雅停机
Dubbo 是通过 JDK 的 ShutdownHook 来完成优雅停机的,所以如果⽤户使⽤ kill -9 PID 等强制关闭指令,是不会
执⾏优雅停机的,只有通过 kill PID 时,才会执⾏。
在 Provider 上尽量多配置 Consumer 端属性
原因如下:
作服务的提供者,⽐服务使⽤⽅更清楚服务性能参数,如调⽤的超时时间,合理的重试次数,等等
在 Provider 配置后,Consumer 不配置则会使⽤ Provider 的配置值,即 Provider 配置可以作为 Consumer 的缺省
值 。否则,Consumer 会使⽤ Consumer 端的全局设置,这对于 Provider 不可控的,并且往往是不合理的
Provider 上尽量多配置 Consumer 端的属性,让 Provider 实现者⼀开始就思考 Provider 服务特点、服务质量的问题。
示例:
<dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService"
timeout="300" retry="2" loadbalance="random" actives="0"
/>
<dubbo:service interface="com.alibaba.hello.api.WorldService" version="1.0.0" ref="helloService"
timeout="300" retry="2" loadbalance="random" actives="0" >
<dubbo:method name="findAllPerson" timeout="10000" retries="9" loadbalance="leastactive" actives="5" />
<dubbo:service/>
在 Provider 上可以配置的 Consumer 端属性有:
1. timeout ⽅法调⽤超时
2. retries 失败重试次数,缺省是 2
3. loadbalance 负载均衡算法 ,缺省是随机 random 。还可以有轮询 roundrobin 、最不活跃优先 leastactive
4. actives 消费者端,最⼤并发调⽤限制,即当 Consumer 对⼀个服务的并发调⽤到上限后,新调⽤会 Wait 直到超
时 在⽅法上配置 dubbo:method 则并发限制针对⽅法,在接⼝上配置 dubbo:service ,则并发限制针对服务
Provider 上配置合理的 Provider 端属性
<dubbo:protocol threads="200" />
<dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService"
executes="200" >
<dubbo:method name="findAllPerson" executes="50" />
</dubbo:service>
Provider 上可以配置的 Provider 端属性有:
1. threads 服务线程池⼤⼩
2. executes ⼀个服务提供者并⾏执⾏请求上限,即当 Provider 对⼀个服务的并发调⽤到上限后,新调⽤会 Wait,
这个时候 Consumer可能会超时。在⽅法上配置 dubbo:method 则并发限制针对⽅法,在接⼝上配置
dubbo:service ,则并发限制针对服务
-server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m -Xss256k -
XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -
XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -
XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -
XX:+UseCMSInitiatingOccupancyOnly -
XX:CMSInitiatingOccupancyFraction=70