Open garrettjonesgoogle opened 7 years ago
Channels are lazily connected. So creating a channel is cheap, but then the connection it has to make on first use is expensive. But creating many channels on startup shouldn't be too prohibitive by itself.
Channels support auto-IDLEness. You can configure a timeout where after no active RPCs the channel will auto-disconnect. We also have a connection state API (although it isn't yet plumbed) that can be notified when the channel goes IDLE. Thus, with auto-IDLE you could easily manage the cleanup of unused Channels by shutting them down after IDLE. There's races involved and details, but wanted to mention it.
@ejona86 I can see that this is added under the Next milestone. Till then, what would be the suggested way of pooling ManagedChannel
objects in a grpc client?
Also, is it right when I say that a single channel has multiple TCP connections to the server?
Also, is it right when I say that a single channel has multiple TCP connections to the server?
Yes, it is possible to have ManagedChannel
backed by multiple connections to one or many servers if you use ManagedChannel2
and RoundRobinLoadBalancer2
or have a custom LoadBalancer2
implementation, one which creates multiple subchannels (the 2
is a new next version with revamped API)
@sandeepd-bsb, I'd suggest rolling your own. It's unclear what you need in way of "pooling". For single-host use-cases I'd suggest to just have a static ManagedChannel with auto-idle enabled. If you are communicating with an unbound number of hosts, then you'll need to figure out something yourself.
The client libraries generated by https://github.com/googleapis/toolkit currently create a new channel for every API wrapper object, which is expensive and wasteful. For the benefit of users, we need channel pooling support so that startup time and resource usage is minimized, regardless of how many API wrapper objects are created. The alternatives require more work for users (which is undesirable) or implementing pooling support in the API wrapper layer, which doesn't make sense if grpc is a better place to implement it.