2

The code file is: client and server

Doubtful code:

var serviceConfig = `{
    "loadBalancingPolicy": "round_robin",
    "healthCheckConfig": {
        "serviceName": ""
    }
}`

Test steps:

1.Run only one server and one client

2.When using "loadBalancingPolicy": "round_robin", the client can detect the "status=NOT_SERVING" of the server

3.When "loadBalancingPolicy": "round_robin" is deleted, or "pick_first" is used, the "status=NOT_SERVING" of the server cannot be detected on the client side

null
  • 115
  • 1
  • 9

2 Answers2

3

The health check meaningful when has multiple server addresses. If only has one address, there is no need to check health status. So the load balance policy round_robin is work together with health check.

The round_robin will check health status, so it will send request to READY address one after another.

The pick_first policy not support health check, so it will use first success connectted server. So there will only use specify address for any request.

You can read the document of health check and load balance policy in LB Policies Can Disable Health Checking When Needed.

For debug the client and server, you can add environment variable GRPC_GO_LOG_SEVERITY_LEVEL=info and GRPC_GO_LOG_VERBOSITY_LEVEL=99 for more detail of transport and connection event.

HelloWood
  • 727
  • 4
  • 13
  • Thanks. What I want to focus on is the use of health checks. In the sample code, if the configuration code related to load balancing is removed, the client cannot normally perceive the non-service status of the server. I tried changing "round_robin" to pick_first", but it's the same as just deleting "loadBalancingPolicy". – null Mar 08 '22 at 01:41
  • Thank you for your answer, I will go to modify the code to verify – null Mar 08 '22 at 03:10
  • I modified the description of the problem, can you help me again? – null Mar 08 '22 at 06:51
  • @eBeginner FYI. – HelloWood Mar 08 '22 at 07:31
0

When I read the source code carefully, I understood the internal implementation.

  1. pick_first
  • It implements "balancer.Builder" and "balancer.Balancer" by itself.
  • "ResolverState.Addresses" will only create a SubConn, there is an addrConn in SubConn, create ClientTransport with the first addr.
  • Returns a fixed "balancer.PickResult" each time Pick() is called.
  1. round_robin
  • Pass in the parameter "HealthCheck: true" and return baseBuilder as Builder through "base.NewBalancerBuilder()".
  • Each addr of "ResolverState.Addresses" will create a corresponding SubConn.
  • Each time Pick() is called, change the internal next value, get it from "[]balancer.SubConn", and return a new "balancer.PickResult".
null
  • 115
  • 1
  • 9
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 22 '22 at 10:12