【问题标题】:AWS ECS Spring Boot Task killed and restarted on background workAWS ECS Spring Boot 任务在后台工作中被杀死并重新启动
【发布时间】:2020-04-12 01:43:15
【问题描述】:

我有一个 Spring Boot Web 应用程序在 Fargate 上的 AWS ECS 服务上运行,所需计数为 1。它在前面配置了一个 LB,用于 SSL 终止和运行状况检查。

每天晚上通过@scheduled 我运行一个批处理作业,它会进行一些重新计算。在该作业运行期间或之后不久的各个时间点,我的任务被终止并启动了一个新任务。在任务运行期间,我注意到一些事情:

  • 服务上的 CPU(通过 Cloud Watch)飙升至 60% 以上
  • 来自负载平衡器的运行状况检查仍然会在很长一段时间内做出响应
  • 我的 Spring Boot 日志中没有错误
  • 在 ECS 服务事件中我看到service sname-app-lb deregistered 1 targets in target-group ecs-sname-app-lb

我正试图弄清楚如何准确地判断任务被终止的原因。任何有关如何调试/修复此问题的提示将不胜感激。

【问题讨论】:

  • 您提到您正在运行计划任务?但您期待服务健康检查?
  • 这不是ECS意义上的计划任务,它只是spring boot中的@scheduled方法。
  • @gunygoogoo 当任务被杀死时,你去 ECS 上停止的容器,你看到任务被杀死的任何原因吗?

标签: amazon-web-services spring-boot amazon-ecs aws-fargate


【解决方案1】:

所以,我过去也有过类似的经历。这是你需要做的:

1. Make sure you are streaming the application logs to the cloudwatch using the awslogs driver in the task definition (if you are not doing it already).
2. Put a delay in the app as a catch/handler wherever it can fail. This delay will make sure that the application logs are sent to cw logs the event of an exception, and thus prevent an abrupt exit of the task.

我最初认为是一个 Fargate 问题,但以上内容确实有助于理解潜在问题。一切顺利。

【讨论】:

    【解决方案2】:

    如果您在 AWS Fargate 中的 Docker 内运行 Spring 应用程序,如果它达到内存限制,您的应用程序可能会被终止。

    更多信息:https://developers.redhat.com/blog/2017/03/14/java-inside-docker/

    【讨论】:

      最近更新 更多