Delayed connections are used to reduce the number of long connections. Create a 
long connection when a call is initiated. <dubbo:protocol name="dubbo" 
lazy="true" />Note: This configuration only works for dubbo protocols that use 
long connections.
Later I read the code about the delayed connection and found that 
LazyConnectExchangeClient has two purposes:
1. Create a connection like the delay mentioned earlier, minimizing unnecessary 
long connection overhead.
2. A kind of protection when closing the connection resource. When the 
ReferenceCountExchangeClient is closed (multiple URLs refer to the same 
ReferenceCountExchangeClient, the last URL that will reference the counter to 0 
can actually close the ReferenceCountExchangeClient) will be replaced with 
LazyConnectExchangeClient. When used again, the warn log will be printed. The 
put operation of ghostClientMap is only available here.

So, no matter how many ExchangeClients a URL corresponds to, it only needs a 
ghost connection in the ghostClientMap, which is a LazyConnectExchangeClient.

Also, only the shared ExchangeClient will use the ReferenceCountExchangeClient, 
so the default client used to share a TCP connection is the 
ReferenceCountExchangeClient, and the separate TCP connection set by 
connections does not need or use the ReferenceCountExchangeClient.

延迟连接用于减少长连接数。当有调用发起时,再创建长连接。<dubbo:protocol name="dubbo" lazy="true" 
/>注意:该配置只对使用长连接的 dubbo 协议生效。 
后面我有仔细阅读了关于延迟连接的代码,发现LazyConnectExchangeClient有两个用途:
1. 像前面提到的延迟创建连接,尽可能的减少不必要的长连接开销。
2. 
关闭连接资源时的一种保护,当ReferenceCountExchangeClient被关闭时(多个URL引用同一个ReferenceCountExchangeClient时,最后那个将引用计数器变为0的URL可以真正关闭该ReferenceCountExchangeClient),会被替换成LazyConnectExchangeClient,一旦再被使用,会打印warn日志。而ghostClientMap的put操作,只有在这里才有。

所以,不管一个URL对应多少个ExchangeClient,它在ghostClientMap中最多只需要一个幽灵连接,即一个LazyConnectExchangeClient。

并且,只有共享的ExchangeClient才会用到ReferenceCountExchangeClient,所以默认的共享1条TCP连接所使用的client就是ReferenceCountExchangeClient,而通过connections设置的单独TCP连接不需要也没有使用ReferenceCountExchangeClient。

[ Full content available at: 
https://github.com/apache/incubator-dubbo/pull/2457 ]
This message was relayed via gitbox.apache.org for 
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to