简体   繁体   English

更新 ECS 服务时 AWS ECS websocket 连接耗尽

[英]AWS ECS websocket connection draining while updating ECS service

I am using AWS ECS to run chat application written in nodejs with help of socket.io.我正在使用 AWS ECS 在 socket.io 的帮助下运行用 nodejs 编写的聊天应用程序。

I used AWS Application Load Balancer as front and created one target group, target group contains AWS ECS service.我使用 AWS Application Load Balancer 作为前端并创建了一个目标组,目标组包含 AWS ECS 服务。

Now, let say I create 1 service with my container(using task definition) and added in the target group and the user starts connecting to my AWS ECS service using websocket.现在,假设我使用我的容器(使用任务定义)创建了 1 个服务并添加到目标组中,并且用户开始使用 websocket 连接到我的 AWS ECS 服务。

My question is, If I update my service with new task definition, Will AWS ECS wait for older websocket connection to gracefully disconnect or it will forcefully disconnect older websocket connection with old service?我的问题是,如果我使用新的任务定义更新我的服务,AWS ECS 会等待旧的 websocket 连接正常断开连接还是会强制断开旧的 websocket 连接与旧服务的连接?

Your websocket connections would be out of bounds activity for ECS - it has no visibility into it.您的 websocket 连接将超出 ECS 的活动范围 - 它无法看到它。 So ECS won't help you here, but...所以ECS不会在这里帮助你,但是......

When you update the service, it would be equivalent to sending a docker stop command.当你更新服务时,就相当于发送了一个docker stop命令。 This means that a stop signal is sent.这意味着发送停止信号

According to the ECS docs : 根据 ECS 文档

When StopTask is called on a task, the equivalent of docker stop is issued to the containers running in the task.当在任务上调用 StopTask 时,会向任务中运行的容器发出相当于 docker stop 的命令。 This results in a SIGTERM and a default 30-second timeout, after which SIGKILL is sent and the containers are forcibly stopped.这会导致 SIGTERM 和默认的 30 秒超时,之后发送 SIGKILL 并强制停止容器。 If the container handles the SIGTERM gracefully and exits within 30 seconds from receiving it, no SIGKILL is sent.如果容器优雅地处理 SIGTERM 并在收到它后 30 秒内退出,则不会发送 SIGKILL。

You should be able to set a trap in your entrypoint script that could execute some sort of graceful handoff process.您应该能够在入口点脚本设置一个陷阱该陷阱可以执行某种优雅的切换过程。

So something along the lines of:所以类似的东西:

#!/bin/bash
... other code...
function handleShutdownFoo {
  # do something...
}
trap handleShutdownFoo SIGTERM
... more code ...

For more information on containerizing a nodejs app, review this guide from the Node team .有关容器化nodejs应用程序的更多信息,请查看 Node 团队的本指南

Multiple factors comes into picture here.这里有多种因素。

1 What is your minimum and maximum health percentage, if you have minimum health percentage 0, then while updating the service only your new task will be running and older task will be forcefully be stopped. 1 您的最小和最大健康百分比是多少,如果您的最小健康百分比为 0,那么在更新服务时,只会运行您的新任务,而旧任务将被强制停止。

  1. What is the timing of your inflight request timing in alb, this decides how much time your old request will be processed before expiration.你在 alb 中的飞行请求时间是什么时间,这决定了你的旧请求在到期前处理的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM