Stub uses a single connection over the channel for multithreaded gRPC Client?

1.7k Views Asked by At

I'm new to gRPC, and from my understanding, Channels/Stubs are thread safe, but does stub use a single connection for all threads? If yes, wouldn't throughput be less, if no, do I need to create a pool of connections?

1

There are 1 best solutions below

0
On BEST ANSWER

Stubs are lightweight; the Channel holds the connection(s). A Channel is a virtual connection to an endpoint; it may have zero or many TCP connections.

At very high throughput using multiple connections can be beneficial. In the short-term you can accomplish that by using multiple Channels. However, ideally you'd use a single Channel and use a LoadBalancer that uses multiple connections to the same endpoint. That's not quite possible today; hopefully in 1.2 it will be supported and we'll provide a convenience implementation.