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

1

6

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?

Alexiaalexin answered 30/11, 2018 at 20:51 Comment(3)
Are you using gRPC C++? The standard way to "force" multiple connections is to create your channels with distinct ChannelArgs, which will circumvent the subchannel/connection sharing that otherwise takes place.Tuchun
C#, sorry, I only mentioned that in the tag. Is there a meaningless ChannelArg I can add that won't change anything but will break the sharing?Alexiaalexin
Calling this approach a "standard way" was an overstatement on my part; it will work, but is not an intended use and as such there is no truly meaningless ChannelArg to accomplish this purpose.Tuchun
T
4

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.

Tuchun answered 10/1, 2019 at 17:39 Comment(1)
Now merged. Use: ChannelArguments args; args.SetInt(GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL, 1); with grpc::CreateCustomChannel()Backed

© 2022 - 2024 — McMap. All rights reserved.