How does gRPC load balances?

4,849 views
Skip to first unread message

raut...@gmail.com

unread,
Aug 9, 2016, 1:51:53 PM8/9/16
to grpc.io
Hi

While going through gRPC goals on grpc.io I noticed it mentions Load balancing as one of its design principles or Goals.

But I did not find anything which suggests the same.

Saw one of the gRPC Demos by Sameer Ajmani on Youtube and he appears to be running some kind of a Server Proxy(some yaml file suggested this).I may be wrong.

So, my question is how is this Load Balancing goal achieved by gRPC if I have to use a TCP or HTTP Load balancer Proxy to achieve this?

As I understands gRPC server stubs need to run on each and every System providing the Service(s), but what does client need to do if Servers are not behind a Proxy?

As I understand gRPC does not have a Service Discovery mechanism, hence the confusion.

Could someone please point me to the right direction?

PS:- I am a newbie to gRPC, pardon my ignorance. Would appreciate if someone can CMIIW.

Thanks,

Louis Ryan

unread,
Aug 9, 2016, 8:33:34 PM8/9/16
to raut...@gmail.com, grpc.io
First take a look at


GRPC also supports the ability to plug-in your service discovery mechanism of choice which can then be used for client-side load-balancing.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/78cb7ddc-282a-4df2-8e0b-5d60cbd7df71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pradeep Singh

unread,
Aug 9, 2016, 8:53:32 PM8/9/16
to Louis Ryan, grpc.io
Thank you Louis.

Looks like Load Balancer is something we have to decide on and it is not part of gRPC inherently.

So, essentially the complete solution is Service(s), Server(s), Client(s) and Load Balancer.

Which Load Balancer would you guys recommend?

PS:- Most of our systems do not run in cloud.

Thanks,
--
Pradeep Singh

Pradeep Singh

unread,
Aug 9, 2016, 8:58:30 PM8/9/16
to Louis Ryan, grpc.io
If I take this example with any Service Discovery solution out there, this is what I understand.

1. I get list of IPs for a Service A via Service Discovery Agent.
2. I connect to all of them via  gRPC channels.
3. Who load balances now when I send a message??? Client?
Or do I connect to all IPs via same channel handle?(Just like zmq)

If I have to write my own client side load balancing on my own, it kind of makes it cumbersome I guess.

Thanks,
     --Pradeep


On Tue, Aug 9, 2016 at 5:33 PM, Louis Ryan <lr...@google.com> wrote:



--
Pradeep Singh

Louis Ryan

unread,
Aug 9, 2016, 9:19:54 PM8/9/16
to Pradeep Singh, grpc.io
On Tue, Aug 9, 2016 at 5:58 PM, Pradeep Singh <raut...@gmail.com> wrote:
If I take this example with any Service Discovery solution out there, this is what I understand.

1. I get list of IPs for a Service A via Service Discovery Agent.
2. I connect to all of them via  gRPC channels.
3. Who load balances now when I send a message??? Client?
Or do I connect to all IPs via same channel handle?(Just like zmq)

It varies a little by implementation but generally you just implement the name-resolution part. E.g. in Java


and GRPC channels will use the resolved IPs under the hood. I guess this is similar to what zmq does

Pradeep Singh

unread,
Aug 9, 2016, 9:36:46 PM8/9/16
to Louis Ryan, grpc.io
Thanks, I hope it is same for C/C++ implementations too.
--
Pradeep Singh

peter....@jumpcloud.com

unread,
May 22, 2017, 12:44:37 AM5/22/17
to grpc.io, raut...@gmail.com
Hi,

Sorry to resurrect a somewhat old thread but it seemed the most logical place to ask this question: are there samples of setting up a client to use LB in various languages, specifically node.js? I believe its supported, but I can't figure out where I'm supposed to even start out at. It'd be nice to see a client that uses a naming resolver and load balancer, and perhaps a sample of writing one's own naming resolver and load balancer.

Thanks,
\Peter
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/78cb7ddc-282a-4df2-8e0b-5d60cbd7df71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




--
Pradeep Singh

Nice Robot

unread,
Jun 8, 2017, 12:17:14 AM6/8/17
to grpc.io, raut...@gmail.com, peter....@jumpcloud.com

peter....@jumpcloud.com

unread,
Jun 8, 2017, 7:05:46 PM6/8/17
to grpc.io, raut...@gmail.com, peter....@jumpcloud.com
The golang code is straightforward and somewhat documented so I actually have that part working just fine. I'm specifically looking for how to do that with node.js (or at least C++ as node.js is using that under the covers); I can't find any examples and the docs are about broad concepts but no information on how to actually pass those around to the node.js classes.

Thanks,
\Peter

Makarand Dharmapurikar

unread,
Jun 12, 2017, 12:36:57 PM6/12/17
to peter....@jumpcloud.com, grpc.io, raut...@gmail.com
Hi - Another simpler load balancing example is here - https://github.com/makdharma/grpc-zookeeper-lb

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.

peter....@jumpcloud.com

unread,
Jun 12, 2017, 6:16:31 PM6/12/17
to grpc.io, peter....@jumpcloud.com, raut...@gmail.com
The java one is interesting, but its also a separate repo from the main grpc one that has the C++ and subsequently node.js LB stuff that I can't figure out. For example maybe I'm missing it, but while this Java code makes sense to me:

public HelloWorldClient(String zkAddr) {
this(ManagedChannelBuilder.forTarget(zkAddr)
.loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
.nameResolverFactory(new ZkNameResolverProvider())
.usePlaintext(true));
}
It doesn't help me reconcile how to inject an LB into this node.js code:

new example.RouteGuide('localhost:50051', grpc.credentials.createInsecure());

I.e. there's no managed channel builder in node.js (that I can find) and the arguments to that constructor are the addr, ssl, and options, of which there is no definitively list of things I can send that I can tell.

Thanks,
\Peter

maju...@gmail.com

unread,
Feb 6, 2018, 12:55:03 AM2/6/18
to grpc.io
Envoy is what you want, which is written in C++ and could also handle logging, tracing, and etc. as sidecar.

peter....@jumpcloud.com

unread,
Feb 10, 2018, 10:36:19 AM2/10/18
to grpc.io
Envoy is interesting, although I found it hard to configure; a proxy alternative is https://nghttp2.org/documentation/index.html which is less frills but much easier to setup imo.

However, those are both proxy solutions whereas grpc is supposed to have client-side LB mechanism built in (https://grpc.io/blog/loadbalancing), which is what the Java example earlier about is; it'd be pretty useful to have a node.js example of how to use consul, or zookeeper or something akin and how to hook into it. 

Duncan Mole

unread,
Feb 14, 2018, 10:03:48 AM2/14/18
to grpc.io
Hi.

I am new at this too, but I will attempt an answer. gRPC exists primarily as a protocol. There are 3 main implementations, C/C++, Go and Java. Each of these has its own repo. API's are somewhat close but also vary by language so they are idiomatic - and to be honest, the APIs aren't the grpc 'contract' - the protocol is. 

The C/C++ repo serves as the 'core' by which ancillary languages can call down into, for example Node & C#. Even within the C/C++ repo, things can depend on your platform of choice - right now Linux can provide client-side balancing by virtue of the fact that it uses C-ARES for DNS resolution. On Windows, the core currently only supports the platform DNS resolver. 

So - if you are running Node on Linux, I think you are in luck. You can use: 'dns://youdnsserver/yourservice' when you create the channel. If your DNS sever returns a SRV record with multiple IP address, the channel will take care of balancing across them. This also means that if you are using something like Consul to be your DNS server you may do some form of "service discovery" using the 'yourservice' portion of the address you pass - which may be used to do some form of querying against the pool of services it knows about.

Myself, I am on Windows and very much waiting in anticipation for the C-ARES resolver to make it to the Windows platform so I can do just as I described above. Last I heard it was due 'early Q1 2018' and I havent been able to get this verified this year.

Its also worth mentioning that you can write native plugins for the C/C++ library to load to write your own logic to do these things. Again, I am not sure where this is, I have a feeling its still a TODO.

Bear in mind this answer is "to the best of my knowledge" and might well be way off :-)
Reply all
Reply to author
Forward
0 new messages