英文:
why the "loadBalancingPolicy“ must be used when "healthCheckConfig" in grpc
问题
可疑的代码:
var serviceConfig = `{
"loadBalancingPolicy": "round_robin",
"healthCheckConfig": {
"serviceName": ""
}
}`
测试步骤:
-
只运行一个服务器和一个客户端
-
当使用 "loadBalancingPolicy": "round_robin" 时,客户端可以检测到服务器的 "status=NOT_SERVING"
-
当删除 "loadBalancingPolicy": "round_robin",或者使用 "pick_first" 时,客户端无法检测到服务器端的 "status=NOT_SERVING"
英文:
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
答案1
得分: 3
健康检查在具有多个服务器地址时才有意义。如果只有一个地址,就没有必要检查健康状态。因此,负载均衡策略round_robin
与健康检查一起工作。
round_robin
会检查健康状态,因此它会依次向READY
地址发送请求。
pick_first
策略不支持健康检查,因此它将使用第一个成功连接的服务器。因此,对于任何请求,只会使用指定的地址。
您可以在LB Policies Can Disable Health Checking When Needed中阅读有关健康检查和负载均衡策略的文档。
为了调试客户端和服务器,您可以添加环境变量GRPC_GO_LOG_SEVERITY_LEVEL=info
和GRPC_GO_LOG_VERBOSITY_LEVEL=99
以获取更详细的传输和连接事件信息。
英文:
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.
答案2
得分: 0
当我仔细阅读源代码时,我理解了内部实现。
- pick_first
- 它通过自身实现了"balancer.Builder"和"balancer.Balancer"。
- "ResolverState.Addresses"只会创建一个SubConn,在SubConn中有一个addrConn,使用第一个addr创建ClientTransport。
- 每次调用Pick()时,返回一个固定的"balancer.PickResult"。
- round_robin
- 通过参数"HealthCheck: true"传入,并通过"base.NewBalancerBuilder()"将baseBuilder作为Builder返回。
- "ResolverState.Addresses"的每个addr都会创建一个相应的SubConn。
- 每次调用Pick()时,更改内部的next值,从"[]balancer.SubConn"中获取,并返回一个新的"balancer.PickResult"。
英文:
When I read the source code carefully, I understood the internal implementation.
- 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.
- 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".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论