Search code examples
c#haproxygrpc

How do I force my gRPC client to open multiple connections to the server?


I have implemented a server and client with Google's gRPC toolkit. While testing, I noticed that there was never more than a single TCP connection from the client to the server, regardless of how many Channel instances I construct.

I am planning to use what Google calls "proxy load balancing" via HAProxy. Therefore, I need multiple connections from my clients (say, service A) to my servers (say, service B). If no more than one connection is created, then HAProxy chooses one service for that connection, and none of the other servers will ever see any load.

I have tried using ChannelOptions.MaxConcurrentStreams both on the client side and server side (and both sides simultaneously), but without any luck. As mentioned, I've created multiple Channel instances, to no avail. The only effective technique I've found is to create multiple processes, which isn't ideal for obvious reasons.

What can I do to fully enable Google's "proxy load balancing" scenario?


Solution

  • Currently, there is no direct way to force new connection creation with our existing API. As I mentioned in the comments, this can be done with our C-Core implementation (which is wrapped by gRPC C#) only by supplying different ChannelArgs, which represent parameters of the connection and, when present, ensure that separate connections are created for each set of distinct ChannelArgs. However, using different channel args solely to get new copies of the same connection is not an intended use case of the API, so there are no truly meaningless channel args that change nothing except ensuring a new connection is established.

    However, there is an in-progress PR that is adding a channel arg that explicitly forces subchannel (connection) sharing to only happen within a single channel instance. When set, this would avoid sharing connections between channel instances and allow you to ensure that each channel creates a new connection.