client side load balancing in grpc python

714 views
Skip to first unread message

animesh sharma

unread,
Jan 28, 2022, 7:52:10 AM1/28/22
to grpc.io

Hi Team,

I was trying to implement client side load balancing in gRPC. I know how to do it in Java but not able to find appropriate document describing how to do the same in python, below is my Java code.

```
NameResolver.Factory nameResolverFactory = new MultiAddressNameResolverFactory( new InetSocketAddress("localhost", 10000), new InetSocketAddress("localhost", 10001), new InetSocketAddress("localhost", 10002) ); ManagedChannel channel = ManagedChannelBuilder.forTarget("service") .nameResolverFactory(nameResolverFactory) .defaultLoadBalancingPolicy("round_robin") .usePlaintext() .build();

```

In python I know how to connect to one server but not a list of gRPC servers

channel = grpc.insecure_channel('localhost:10000')

can anyone kindly guide me or point me to a document on how to implement the same?

Thanks,

Animesh

Easwar Swaminathan

unread,
Feb 2, 2022, 1:40:44 PM2/2/22
to animesh sharma, Lidi Zheng, Richard Belleville, grpc.io
You can find gRPC Python documentation here: https://grpc.github.io/grpc/python/ and a basic tutorial here: https://grpc.io/docs/languages/python/.

[+Richard Belleville, +Lidi Zheng] for specific load balancing API in Python.

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/4ce5e1e3-46cb-482a-829c-6e5c518e6762n%40googlegroups.com.

Lidi Zheng

unread,
Feb 2, 2022, 2:36:52 PM2/2/22
to grpc.io
Hi,

You are using the custom resolver API for Java. This API is available only in limited gRPC languages, like Java/Go, but not Core-based languages, like C++/Python/Ruby/C#/ObjC/PHP.

You may need to inject the candidate addresses to DNS backends. Many DNS providers / cloud providers offer this feature.

Locally, depending on the OS, there should be ways to define name -> IP resolutions, like /etc/hosts.
Reply all
Reply to author
Forward
0 new messages