【公有云】AWS 网络弹性负载均衡 NLB PortAllocationErrorCount 报错

7 篇文章 0 订阅
4 篇文章 0 订阅

定义

The total number of ephemeral port allocation errors during a client IP translation operation. A non-zero value indicates dropped client connections.

ephemeral port allocation:OS给TCP链接分配临时端口的过程。
client IP translation operation: 在NLB的场景下,将请求的client 源IP转换为NLB的IP,并分配一个临时(outbound)端口,再将请求转发给后端服务的过程。

背景

某个业务访问后端服务收到大量5xx,查看报错时间和PortAllocationErrorCount指标增长时间吻合。该后端服务使用的NLB Preserve client IP address 处于 Off 状态。

分析

首先,PortAllocationErrorCount是一个发生在NLB侧的事件。因为客户端地址转换是在NLB上发生的,根据上面的定义我们知道无法分配临时端口也是在NLB上发生的。

为什么会有临时端口无法分配?
在不打开Preserve client IP的条件下,给定一组NLB和后端服务建连的Socket Pair:
{10.0.0.1, 34454, 10.0.0.8, 443}
10.0.0.1,34454 分别是NLB的private IP 和临时端口;
10.0.0.8,443 是服务端的IP和端口。

对于一个Linux实例,其可分配的端口数是有限的(https://www.baeldung.com/linux/tcp-ip-connections-limit)。也就是说在上面的四元组{src_ip, src_port, dest_ip, dest_port} 中的src_port 和 dest_port 的值是有固定范围的,通常情况下取值范围在1024-65535。

当NLB IP固定10.0.0.1,只有一个后端IP10.0.0.8,此时任意一个Socket Pair为 {10.0.0.1, src_port, 10.0.0.8, 443}​,理想情况下我们最多可以有55000(AWS肯定有预留端口,所以不是64511)个Socket Pair,当客户端链接激增或者持续增长到55000,就会发生临时端口无法分配的问题。

如何解决

如果我们有两个后端IP 10.0.0.8 & 10.0.0.9 那么对于一个 (src_ip, src_port) 组合,可能的Socket Pair就翻倍:[{10.0.0.1, 34454, 10.0.0.8, 443}, {10.0.0.1, 34454, 10.0.0.9, 443}]​。此时变量是src_port & dest_ip [{10.0.0.1, src_port, dest_ip, 443}]​。NLB给定的src_port范围是固定不变的(一个子网中最多3个NLB IP),因此我们可以通过扩增dest_ip(添加targets)来缓解TCP连接数突增时NLB的压力。

附录

Preserve client IP

NLB 在路由请求至后端目标服务时保留客户端源IP地址。如果为Off,NLB的private IP成为所有(后端目标服务视角)incoming 请求的源IP。

https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html#client-ip-preservation

Proxy protocol

NLB使用proxy protocol v2 以添加客户端信息,解决了lb或proxy对服务端隐藏客户端ip的问题。如果没有proxy protocol,所有过nlb的请求都会表现为从nlb的IP发起。

https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html#proxy-protocol

Sockets

A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.

An endpoint is a combination of an IP address and a port number. Every TCP connection can be uniquely identified by its two endpoints. That way you can have multiple connections between your host and the server.

https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html
https://www.ibm.com/docs/en/zos/2.3.0?topic=services-what-is-socket
https://www.digitalocean.com/community/tutorials/what-is-a-socket

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值