You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/20 05:47:24 UTC

[GitHub] [dubbo] zhangyz-hd commented on issue #8010: Write/Delete configurators cause unnecessary reregister and netty connections

zhangyz-hd commented on issue #8010:
URL: https://github.com/apache/dubbo/issues/8010#issuecomment-883083120


   # 进一步分析
   
   ## 场景:
   
   - zookeeper注册中心,按接口服务发现模式
   - 注册中心1个提供者,1个override://weight=200
   
   ## 过程:
   
   ### 1,消费者启动
   
   收到如下notify
   
   1. **空的routers,正常**:
   
      ```
      empty://192.168.3.198/org.apache.dubbo.demo.DemoService?application=dubbo-demo-annotation-consumer&category=routers&dubbo=2.0.2&init=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello&pid=4366&qos.enable=false&side=consumer&sticky=false&timestamp=1626748727511
      ```
   
      
   
   2. **一条override,正常**:
   
      ```
      override://0.0.0.0/org.apache.dubbo.demo.DemoService?category=configurators&dynamic=false&weight=200
      ```
   
      
   
   3. 附带weight=200权重的**提供者url**,姑且算正常(因为注册中心写入override后,提供者会reExport):
   
      ```
      dubbo://192.168.3.198:20881/org.apache.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-annotation-provider&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello&pid=3865&release=release&service.name=ServiceBean:/org.apache.dubbo.demo.DemoService&side=provider&timestamp=1626744024684&weight=200
      ```
   
   4. 连接服务提供方
   
      ```
      [20/07/21 11:17:13:195 CST] NettyClientWorker-1-1  INFO netty4.NettyClientHandler:  [DUBBO] The connection of /192.168.3.198:56588 -> /192.168.3.198:20881 is established., dubbo version: , current host: 192.168.3.198
      [20/07/21 11:17:13:202 CST] main  INFO transport.AbstractClient:  [DUBBO] Successed connect to server /192.168.3.198:20881 from NettyClient 192.168.3.198 using dubbo version , channel is NettyChannel [channel=[id: 0x5678db4a, L:/192.168.3.198:56588 - R:/192.168.3.198:20881]], dubbo version: , current host: 192.168.3.198
      [20/07/21 11:17:13:203 CST] main  INFO transport.AbstractClient:  [DUBBO] Start NettyClient /192.168.3.198 connect to the server /192.168.3.198:20881, dubbo version: , current host: 192.168.3.198
      ```
   
      ReferenceCountExchangeClient计数器=1
   
   ### 2,服务调用
   
   正常
   
   ### 3,删除注册中心的override
   
   1. 消费者收到因为监听configurators而收到空的configurator,this.configurators清空:
   
      ```
      empty://192.168.3.198/org.apache.dubbo.demo.DemoService?application=dubbo-demo-annotation-consumer&category=configurators&dubbo=2.0.2&init=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello&pid=4366&qos.enable=false&side=consumer&sticky=false&timestamp=1626748727511
      ```
   
      因为cachedInvokerUrls中附带着weight=200,因此下一步oldUrlInvokerMap和newUrlInvokerMap相同,没有invoker被destroy。
   
   2. 提供者reExport,消费者收到空提供购买者列表,
   
      ```
      empty://192.168.3.198/org.apache.dubbo.demo.DemoService?application=dubbo-demo-annotation-consumer&category=providers&dubbo=2.0.2&init=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello&pid=4366&qos.enable=false&side=consumer&sticky=false&timestamp=1626748727511
      ```
   
      ReferenceCountExchangeClient计数器减到0,变成LazyConnectExchangeClient
   
   3. 提供者完成Export,消费者收到新的提供者列表,
   
      ```
      dubbo://192.168.3.198:20881/org.apache.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-annotation-consumer&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello&pid=4366&qos.enable=false&register.ip=192.168.3.198&release=release&remote.application=dubbo-demo-annotation-provider&service.name=ServiceBean:/org.apache.dubbo.demo.DemoService&side=consumer&sticky=false&timestamp=1626744024684
      ```
   
      ReferenceCountExchangeClient计数器+1。之后的服务调用,LazyConnectExchangeClient去和提供者建立连接
   
      ```
      [20/07/21 11:17:43:789 CST] main  INFO dubbo.LazyConnectExchangeClient:  [DUBBO] Lazy connect to dubbo://192.168.3.198:20881/org.apache.dubbo.demo.DemoService?anyhost=true&application=dubbo-demo-annotation-consumer&check=false&codec=dubbo&connect.lazy.initial.state=true&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&heartbeat=60000&init=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello&pid=4812&qos.enable=false&register.ip=192.168.3.198&release=release&remote.application=dubbo-demo-annotation-provider&send.reconnect=true&service.name=ServiceBean:/org.apache.dubbo.demo.DemoService&side=consumer&sticky=false&timestamp=1626744024684&weight=200, dubbo version: , current host: 192.168.3.198
      [20/07/21 11:17:43:792 CST] main  INFO transport.AbstractClient:  [DUBBO] Successed connect to server /192.168.3.198:20881 from NettyClient 192.168.3.198 using dubbo version , channel is NettyChannel [channel=[id: 0x0d0a3f3a, L:/192.168.3.198:56601 - R:/192.168.3.198:20881]], dubbo version: , current host: 192.168.3.198
      [20/07/21 11:17:43:792 CST] NettyClientWorker-1-2  INFO netty4.NettyClientHandler:  [DUBBO] The connection of /192.168.3.198:56601 -> /192.168.3.198:20881 is established., dubbo version: , current host: 192.168.3.198
      [20/07/21 11:17:43:792 CST] main  INFO transport.AbstractClient:  [DUBBO] Start NettyClient /192.168.3.198 connect to the server /192.168.3.198:20881, dubbo version: , current host: 192.168.3.198
      ```
   
      此时,消费者就存在2个和提供者之间的连接
   
      ```
      The connection of /192.168.3.198:56588 -> /192.168.3.198:20881The connection of /192.168.3.198:56601 -> /192.168.3.198:20881
      ```
   
   
   ### 4,重复写入override,删除override步骤
   
   后续每次写入override,删除override,提供者和消费者之间就多一个连接,过程基本同3,都是因为每次产生了额外的LazyConnectExchangeClient
   
   ## 补充:
   
   1. 将提供者reExport行为去除,不会出现上述现象,因为消费者端ReferenceCountExchangeClient计数器不会归0;
   2. 将提供者reExport行为中先处理reExportRegister,再处理reExportUnregister,也不会出现上述现象,因为消费者端ReferenceCountExchangeClient计数器是先加再减,也不会归0。
   
   ## 怀疑:
   
   当ReferenceCountExchangeClient计数器变成0,转为LazyConnectExchangeClient后,如果这个连接还需要被继续使用,着出现连接无法回收的情况。
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org