AWS ECS 自动扩展导致临时 ALB 504 超时

问题描述 投票:0回答:1

我们有一项 ECS + EC2 设置的服务。在ECS上,我们配置了服务自动伸缩。我们注意到,当自动扩展策略尝试扩展更多任务时,我们有时会看到来自 ALB 的短暂 504 网关超时。

我检查过的事情:

  • 当新实例刚刚在 ALB 中注册时会发生这种情况,并且仅持续 1-2 分钟。
  • 有时,实例在ALB中显示健康,任务在ECS中显示运行且健康。有时,实例可能暂时不健康,但随后又恢复健康。正如 AWS 文档所示,ALB 仅在健康的情况下才会发送流量。
  • 并非所有请求都超时,只有很小一部分(< 1%).
  • 最大目标响应时间未超过(或接近)IDLE 超时(180 秒)。当时没有 TargetConnectionErrorCount。

下面是一个 ALB 访问日志示例,似乎表明 ALB 和目标连接之间存在一些问题? (因为 request_processing_time 为 -1)。

type: https
time: 2024-07-25T22:12:31.373696Z
elb: app/xxxx/b3e537e604573ca5
client:port: 52.26.185.88:13328
target:port: 10.0.228.223:8443
request_processing_time: -1
target_processing_time: -1
response_processing_time: -1
elb_status_code: 504
target_status_code: -
received_bytes: 2324
sent_bytes: 292
request: "POST https://xxxxx:443/ HTTP/1.1"
user_agent: "xxxxx"
ssl_cipher: ECDHE-RSA-AES128-GCM-SHA256
ssl_protocol: TLSv1.2
target_group_arn: xxxxxxxx
trace_id: "Root=1-xxxxx-xxxxxxx"
domain_name: "xxxxxx"
chosen_cert_arn: "session-reused"
matched_rule_priority: 0
request_creation_time: 2024-07-25T22:12:21.374000Z
actions_executed: "waf,forward"
redirect_url: "-"
error_reason: "-"
target:port_list: "10.0.228.223:8443"
target_status_code_list: "-"
classification: "-"
classification_reason: "-"
conn_trace_id: xxxxxx

504 和 runningTaskCount 的指标: enter image description here

我的猜测是,新注册的主机可能并不真正健康,但 ALB 仍以某种方式向其发送流量,但我不确定如何检查。想知道是否有人知道可能是什么原因以及如何解决该问题?

非常感谢!

amazon-web-services amazon-ec2 amazon-ecs aws-application-load-balancer
1个回答
0
投票

听起来您可能需要慢慢地为 ECS 服务的新实例提供流量,以便让您的应用程序有时间完全启动或执行其他操作。您可以使用负载均衡器目标组上的

slow_start.duration_seconds
设置进行管理。 记录在这里

负载均衡器向新注册的目标发送线性增加的流量份额到目标组的时间段(以秒为单位)。范围为 30–900 秒(15 分钟)。默认值为 0 秒(禁用)。

© www.soinside.com 2019 - 2024. All rights reserved.