6

TL;DR

Does grpc-java's ManagedChannel have an implicit connection pool or is the pooling of ManagedChannel instances the responsibility of the user?


So, I am using java grpc 1.1.2 with protoc 3.2.0. It seems to me that there's no implicit support (as of now) for connection pooling that grpc provides for clients. It seems, however, that the abstraction of a connection in grpc, i.e. the ManagedChannel object does indeed work with multiple TCP connections. Is that correct? If so, does the ManagedChannel come with connection pooling along with it? If that is the case, I probably don't have to worry about the connection pooling, given that the channel is thread-safe and I can simply use a single ManagedChannel instance across my client. However, I might indeed have to pool these channel objects too for greater throughput if need be. Is there such an implementation (pooling of channels) that does this for me in grpc itself?

4

2 回答 2

12

是的,ManagedChannel 负责连接池,而您只需要一个。它将根据需要自动创建和销毁连接。

于 2017-02-21T22:57:35.300 回答
6

既然您说您想要池化以获得更大的吞吐量,我假设您想要为通道中的一个地址创建和池化多个连接。它不受支持,因为通道 impl 用于每个地址仅创建一个连接。使用即将取代旧版本的 LBv2,现在可以使用自定义LoadBalancer,您可以在其中为连接创建Subchannel任意数量的 s。

关于如何编写自己的 LoadBalancer,您可以参考选股优先循环LoadBalancer。

于 2017-02-22T18:58:04.173 回答