You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/04/22 09:02:28 UTC

[GitHub] [dubbo-go] hxmhlt commented on a change in pull request #482: [WIP]Ftr: client对相同ip和端口发起请求,请共享连接

hxmhlt commented on a change in pull request #482:
URL: https://github.com/apache/dubbo-go/pull/482#discussion_r412801332



##########
File path: protocol/dubbo/pool.go
##########
@@ -50,9 +50,20 @@ type gettyRPCClient struct {
 
 var (
 	errClientPoolClosed = perrors.New("client pool closed")
+	// for shared tcp connection for same ip and port
+	gettyRPCClients sync.Map
 )
 
 func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string) (*gettyRPCClient, error) {
+
+	if client, ok := gettyRPCClients.Load(addr); ok {
+		cl := client.(*gettyRPCClient)
+		if cl.isAvailable() {
+			return cl, nil
+		}
+		cl.gettyClient.Close()
+	}

Review comment:
       Close directly maybe dangerous. May be need lazy close.

##########
File path: protocol/dubbo/pool.go
##########
@@ -63,6 +74,8 @@ func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string) (*ge
 			getty.WithReconnectInterval(pool.rpcClient.conf.ReconnectInterval),
 		),
 	}
+	gettyRPCClients.Store(addr, c)
+

Review comment:
       Load and Store maybe an atomic operating? So I suggest a double `Load` check here.




----------------------------------------------------------------
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.

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