grpc / grpc-java

The Java gRPC implementation. HTTP/2 based RPC
https://grpc.io/docs/languages/java/
Apache License 2.0
11.46k stars 3.85k forks source link

Load balancing with ManagedChannel and name resolver #8143

Closed pantinor closed 3 years ago

pantinor commented 3 years ago

We have been using the LinkerD proxy in a kubernetes cluster to do gRPC load balancing over a cluster IP replica set of pods. And am seeing that we already have the ManagedChannel class has the functionality to load balance provided the same cluster IP host name. Are there APIs usable on the ManagedChannel class to indicate more advanced tweaking around using round robin or weight based load balancing not only for the connection management but for request level load balancing as well? I was trying to explore if possible to do away with using LinkerD and use the Managed Channel by itself. Thanks for feedback.

pantinor commented 3 years ago

I confirmed that round robin load balancing is supported already via builder API on Managed Channel and is solely based on name resolver with dns. So the remaining question is at higher level, if anyone has compared the load balancing and failover between this and LinkerD for k8s deployment use case? LinkerD is supposed to be rather advanced in terms of request level load balancing as well as connection level load balancing for HTTP2. Is this comparable and what may be lacking? The use in the k8s example is with a cluster IP where replicas may be stopped and started and routing can be to any node.

dapengzhang0 commented 3 years ago

We have xDS API based proxyless service mesh solution that's working with google traffic director as control plane. It is using xds name resolver and has advanced load balancing features. We currently don't have native support for LinkerD. gRPC NameResolverProvider and LoadBalancerProvider API is pluggable, so third party can implement there own plugins to have advanced request level load balancing. These APIs might be what you are asking for, although the APIs are mostly @ExperimentalAPI as of now.

pantinor commented 3 years ago

We wanted LinkerD because simple round robin balancing is not adequate when using a stateful service with a cluster IP and relicas. We need not only the connection and request level load balancing, but also the ability to know any new addresses in the cluster IP that spin up, and old ones that removed. I was thinking ManagedChannel combined with NameResolver and LoadBalancer using the k8s dns service might work, because LinkerD is probably using the same way to know what is in the Cluster.

dapengzhang0 commented 3 years ago

but also the ability to know any new addresses in the cluster IP that spin up, and old ones that removed.

The gRPC load balancing API provides the ability to handle address update LoadBalancer.handleResolvedAddresses(), so in principal, a custom NameResolver and LoadBalancer plugin implementation can serve your purpose.

dapengzhang0 commented 3 years ago

No new update so closing. More information can be provided and then we can reopen.