Search code examples
javanettygrpchttp2

Grpc-java multiple channel management


I am using grpc-java (netty) for my client-server communication. Currently, I am using NettyChannelBuilder to create a single channel (which is backed by a single http2 connection i believe) and I use the channel to create all my GRPC stubs. Since the RPS is quite high, I see the a saturation of the grpc channel and requests are starting to queue up. I would like to create more channel (hence naturally more connections). Is there a way to achieve that?

In addition is my assumption that a grpc channel is backed by a single http2 connection?


Solution

  • I think you should make client channel's thread pool more bigger.

    The channel can have many subchannel, and a subchannel has one or many transport, a transport represent a connection. And a server address usually has one connection.

     ManagedChannelBuilder.forAddress("127.0.0.1", 9091)
                          .executor(Executors.newCachedThreadPool())
                          .usePlaintext()
                          .build()