GRPC ManagedChannel 是否使用 DNS-RR 进行负载平衡?
当创建这样的通道时
ManagedChannelBuilder.forAddress("mybackend", 6565)
,mybackend
是一个具有多个IP地址的DNS A记录。
GRPC 是否在记录之间进行循环,或者在通道的生命周期内只坚持一个记录?
如果没有的话,如果我这样做的话会有效吗?
ManagedChannelBuilder.forTarget("dns:///mybackend:6565")
或者这个功能根本不可用?
When creating a channel like this
ManagedChannelBuilder.forAddress("mybackend", 6565)
And mybackend
is a DNS A record with multiple IP addresses.
Does GRPC round-robin between the records or does it just stick to one for the lifetime of the channel?
If not, would it work if I do?
ManagedChannelBuilder.forTarget("dns:///mybackend:6565")
Or is this capability just not available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NettyChannelBuilder.forAddress(SocketAddress)
是一个只能访问单个 IP 的 API,因为 InetSocketAddress 的急切解析。forAddress(String, int)
进行了改进,以在内部使用forTarget(String)
。因此它很方便,可以转换为类似于 forTarget(host + ":" + port) 的内容,但有一些额外的逻辑来处理 IPv6 文字。当目标字符串无法解析时,将添加“dns:///”前缀。请参阅forTarget()
文档 了解这两个细节。因此它本质上相当于使用 forTarget("dns:///mybackend:6565") 。默认情况下,gRPC 不会在多个地址上进行循环。默认情况下,它会“选择优先”,停止在第一个工作地址上(重新连接时可能会选择不同的地址)。您可以通过服务配置或
defaultLoadBalancingPolicy("round_robin")
。NettyChannelBuilder.forAddress(SocketAddress)
is the API that can only access a single IP, due to InetSocketAddress's eager resolution.forAddress(String, int)
was retrofit to useforTarget(String)
internally. So it is a convenience and converts to something similar toforTarget(host + ":" + port)
, but with some extra logic to handle IPv6 literals. The "dns:///" prefix is added to target strings when they fail to parse. See theforTarget()
docs for both details. So it is essentially equivalent to usingforTarget("dns:///mybackend:6565")
.gRPC, by default, doesn't round-robin over multiple addresses. By default it does "pick-first" which stops on the first working address (potentially choosing a different address when reconnecting). You can change that via a service config or
defaultLoadBalancingPolicy("round_robin")
.