Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Robin for gRPC (nodejs) on kubernetes with headless service

I have a a 3 nodejs grpc server pods and a headless kubernetes service for the grpc service (returns all 3 pod ips with dns tested with getent hosts from within the pod). However all grpc client request always end up at a single server.

According to https://stackoverflow.com/a/39756233/2952128 (last paragraph) round robin per call should be possible Q1 2017. I am using grpc 1.1.2

I tried to give {"loadBalancingPolicy": "round-robin"} as options for new Client(address, credentials, options) and use dns:///service:port as address. If I understand documentation/code correctly this should be handed down to the c-core and use the newly implemented round robin channel creation. (https://github.com/grpc/grpc/blob/master/doc/service_config.md)

Is this how round-robin load balancer is supposed to work now? Is it already released with grpc 1.1.2?

like image 744
FibHeap Avatar asked Apr 13 '17 13:04

FibHeap


2 Answers

After diving deep into Grpc-c core code and the nodejs adapter I found that it works by using the option key "grpc.lb_policy_name". Therefore, constructing the gRPC client with

new Client(address, credentials, {"grpc.lb_policy_name": "round_robin"})

works. Note that in my original question I also used round-robin instead of the correct round_robin

I am still not completely sure how to set the serviceConfig from the service side with nodejs instead of using client (channel) option override.

like image 92
FibHeap Avatar answered Oct 20 '22 05:10

FibHeap


I'm not sure if this helps, but this discussion shows how to implement load balancing strategies via grpc.service_config.

const options = {
    'grpc.ssl_target_name_override': ...,
    'grpc.lb_policy_name': 'round_robin', // <--- has no effect in grpc-js
    'grpc.service_config': JSON.stringify({ loadBalancingConfig: [{ round_robin: {} }] }),  // <--- but this still works
};
like image 2
Jonny Jesperson Avatar answered Oct 20 '22 07:10

Jonny Jesperson