Shared Connection

Skip to first unread message

Asha Prabhakaran

May 14, 2021, 4:19:52 PMMay 14
I have a golang GRPC client and a C++ GRPC server providing a synchronous service.
We have been using a new connection for every RPC call.
When I attempt to use the same connection for multiple concurrent RPC calls, only one of them succeeds whereas the others keep waiting.
Is it possible to use the same connection for concurrent RPC calls?

Connection creation:
conn, err := grpc.Dial(url, c.opts...)

For each RPC:
client := pb.NewXXServer(conn) 
stream, err := client.GetXX(lctx, req)

Easwar Swaminathan

May 19, 2021, 1:50:01 PMMay 19
You should not have to use a separate connection for every RPC call. The `grpc.ClientConn` returned from a call to `grpc.Dial` manages connections to multiple backends under the covers. And even if there are not multiple servers to connect to, each RPC is only a stream, and streams can be multiplexed on a single connection.

Are you sure you are not blocking the main server thread in someway that is not allowing you to serve more than one RPC at a time?

Asha Prabhakaran

May 24, 2021, 12:51:34 PMMay 24
Hi Easwar,
Thank you for responding - it turned out to be an issue with the client forwarding the server responses. The stream from the server was read correctly by the 2 concurrent threads on the client, but they were not forwarding it to a downstream process correctly.

Reply all
Reply to author
0 new messages