GRPC客户端负载均衡:一个节点宕机
GRPC client side load balancing : One of node goes down
对于 Grpc 服务,使用客户端负载平衡。
频道创建
ManageChannelBuilder.forTarget("host1:port,host2:port,host3:port").nameResolverFactory(new CustomNameResolverProvider()).loadBalancerFactory(RoundRobinBalancerFactory.getInstance()).usePlaintText(true).build();
使用此频道创建存根。
问题
如果其中一个服务 [host1] 出现故障,那么存根是否会处理这种情况并且不再向服务 [host1] 发送任何进一步的请求?
根据 https://grpc.io/blog/loadbalancing
上的文档
A thick client approach means the load balancing smarts are
implemented in the client. The client is responsible for keeping track
of available servers, their workload, and the algorithms used for
choosing servers. The client typically integrates libraries that
communicate with other infrastructures such as service discovery, name
resolution, quota management, etc.
那么维护活动服务器列表是 ManagedChannel class 的责任还是应用程序代码需要维护活动服务器列表并每次使用活动服务器列表创建 ManagedChannel 实例?
测试结果
根据测试,如果其中一项服务出现故障,则不会影响负载平衡,并且所有请求都会得到正确处理。
那么是否可以假定存根或 ManagedChannel class 处理活动服务器列表?
非常感谢提供文档的回答。
负载平衡器通常处理节点宕机。即使由外部服务管理,节点也可能突然崩溃,负载均衡器希望避开这些节点。所以我知道 gRPC 的所有负载均衡器实现都避免在后端关闭时调用失败。
选择第一个(默认),遍历地址直到一个有效。 Round Robin 仅在工作连接上循环。所以你描述的应该没问题。
我会注意到您的方法确实有一个缺陷:您无法在进程 运行 期间更改服务器。删除损坏的后端是一回事,但添加新的工作后端是另一回事。如果您的负载过高,您可能无法通过添加更多工作人员来解决问题,因为即使您添加更多工作人员,您的客户端也不会连接到他们。
对于 Grpc 服务,使用客户端负载平衡。
频道创建
ManageChannelBuilder.forTarget("host1:port,host2:port,host3:port").nameResolverFactory(new CustomNameResolverProvider()).loadBalancerFactory(RoundRobinBalancerFactory.getInstance()).usePlaintText(true).build();
使用此频道创建存根。
问题
如果其中一个服务 [host1] 出现故障,那么存根是否会处理这种情况并且不再向服务 [host1] 发送任何进一步的请求?
根据 https://grpc.io/blog/loadbalancing
上的文档A thick client approach means the load balancing smarts are implemented in the client. The client is responsible for keeping track of available servers, their workload, and the algorithms used for choosing servers. The client typically integrates libraries that communicate with other infrastructures such as service discovery, name resolution, quota management, etc.
那么维护活动服务器列表是 ManagedChannel class 的责任还是应用程序代码需要维护活动服务器列表并每次使用活动服务器列表创建 ManagedChannel 实例?
测试结果
根据测试,如果其中一项服务出现故障,则不会影响负载平衡,并且所有请求都会得到正确处理。
那么是否可以假定存根或 ManagedChannel class 处理活动服务器列表?
非常感谢提供文档的回答。
负载平衡器通常处理节点宕机。即使由外部服务管理,节点也可能突然崩溃,负载均衡器希望避开这些节点。所以我知道 gRPC 的所有负载均衡器实现都避免在后端关闭时调用失败。
选择第一个(默认),遍历地址直到一个有效。 Round Robin 仅在工作连接上循环。所以你描述的应该没问题。
我会注意到您的方法确实有一个缺陷:您无法在进程 运行 期间更改服务器。删除损坏的后端是一回事,但添加新的工作后端是另一回事。如果您的负载过高,您可能无法通过添加更多工作人员来解决问题,因为即使您添加更多工作人员,您的客户端也不会连接到他们。