诊断 AWS Application Load Balancer 的缓慢响应时间

Diagnosing slow response times for AWS Application Load Balancers

我正在为使用 CloudFront、ALB 和 Fargate 的应用程序开发 POC。在开发应用程序时,我注意到 ALB 有时响应时间很慢。我在 AWS 论坛上遇到了以下主题。它是 8 年前的,但我认为它可以解释我所看到的一些行为:

https://forums.aws.amazon.com/thread.jspa?threadID=102879

The reason for the delay is because you have the ELB setup for multi-az without any application instances in the other 2 AZ's configured. Without instances in those AZ's requests will tend to fail because the ELb still returns IP addresses for those AZ's even if there are no active application instances. Please disable the other AZ's for now and continue your tests.

我有一个类似的设置。我的后端有 2 个可用区和一个 Fargate 任务 API Fargate 服务,负载均衡器将流量发送到该服务。

这是我针对 ALB DNSName(ALB DNSName 和 IP 地址已更改)得到的 运行 dig

dig my-alb-123.us-east-1.elb.amazonaws.com

; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> my-alb-123.us-east-1.elb.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52135
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;my-alb-123.us-east-1.elb.amazonaws.com. IN A

my-alb-123.us-east-1.elb.amazonaws.com. 60 IN A 51.4.143.123
my-alb-123.us-east-1.elb.amazonaws.com. 60 IN A 33.553.34.153

;; Query time: 3113 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue May 26
;; MSG SIZE  rcvd: 124

运行 同样,我得到了相同的结果,但是 Query time0msec。运行这几十次,我看到大多数结果 return 0msec,有些是 ~3000 毫秒。

对于暂存环境,我应该使用一个 AZ 吗?

Query time: 3113 msec

这太过分了。我 检查了我的 2-AZ ALB,我得到的时间大约是 60 毫秒,也在 us-east-1:

dig xxxxx.us-east-1.elb.amazonaws.com

; <<>> DiG 9.16.2 <<>> xxxxx.us-east-1.elb.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56978
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;xxxx.elb.amazonaws.com.    IN A

;; ANSWER SECTION:
xxxxx.us-east-1.elb.amazonaws.com.  60 IN A 52.0.195.xx
xxxxx.us-east-1.elb.amazonaws.com.  60 IN A 50.19.163.xx

;; Query time: 53 msec
;; SERVER: 10.1.1.1#53(10.1.1.1)
;; WHEN: Wed May 27 16:08:53 AWST 2020
;; MSG SIZE  rcvd: 123

dig报告的时间与ALB的DNS解析有关。显示的两个 IP 是 ALB 节点(每个 AZ 一个)。它们不取决于您是否拥有 Fargate 或 EC2 实例。

For a staging environment, should I use one AZ?

如果您的 Fargate 服务设置为只有一个 AZ,任何将到达第二个区域中的 ALB 节点的请求都必须路由到第一个区域。在两个 AZ 中使用 ALB 似乎没有太大好处,但 Fargate 服务仅限于一个 AZ。