Shared Connection

264 views
Skip to first unread message

Asha Prabhakaran

unread,
May 14, 2021, 4:19:52 PM5/14/21
to grpc.io
Hi,
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

unread,
May 19, 2021, 1:50:01 PM5/19/21
to grpc.io
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

unread,
May 24, 2021, 12:51:34 PM5/24/21
to grpc.io
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.
Thanks.
-Asha

Reply all
Reply to author
Forward
0 new messages