- Newest
- Most votes
- Most comments
Hello.
Basically, if it takes a long time to start a container, I think it is a good idea to increase the interval at which health checks are ignored by increasing the "healthCheckGracePeriodSeconds" parameter in the service definition.
This parameter should also be covered by the ELB health check.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_definition_parameters.html#:~:text=%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82-,healthCheckGracePeriodSeconds,-%E3%82%BF%E3%82%A4%E3%83%97%3A%20%E6%95%B4%E6%95%B0
The period of time, in seconds, that the Amazon ECS service scheduler should ignore unhealthy Elastic Load Balancing target health checks, container health checks, VPC Lattice health checks, and Route 53 health checks after a task enters a RUNNING state. This is only valid if your service is configured to use a load balancer. If your service has a load balancer defined and you do not specify a health check grace period value, the default value of 0 is used.
To determine the appropriate target group health check settings for your Application Load Balancer (ALB) and ECS Fargate setup, it's important to understand how these settings interact and affect your application's deployment process. Let's address your questions and provide guidance on optimizing these settings.
First, regarding the Health Check Grace Period: This setting is specific to Amazon ECS and does not directly influence the ALB target group health checks. The Health Check Grace Period gives your ECS tasks time to start up and initialize before they're subject to ECS health checks. It does not affect the ALB's health checks on the target group. For auto scaling groups, there is a separate grace period setting that affects when newly launched instances are considered for health checks and scaling activities.
Now, let's focus on optimizing your ALB target group health check settings:
-
Healthy threshold: This is the number of consecutive successful health checks required before considering an instance healthy. Lowering this value can indeed help new tasks pass health checks faster, but be cautious not to set it too low, as it might lead to premature health declarations.
-
Unhealthy threshold: This is the number of consecutive failed health checks before marking an instance as unhealthy. Balance this with your healthy threshold to avoid frequent flapping between healthy and unhealthy states.
-
Timeout: This is how long the ALB waits for a response to the health check. Set this value based on your application's expected response time under normal conditions.
-
Interval: This is the time between health checks. Shorter intervals can detect issues faster but may increase the load on your application.
To determine optimal values for these settings:
-
Analyze your application's startup time: Monitor how long it takes for your backend to fully initialize and be ready to serve requests.
-
Consider your application's normal response time: Use this as a baseline for setting the timeout value.
-
Balance speed and stability: Faster health checks (shorter intervals, lower thresholds) can speed up deployments but may lead to false positives/negatives if set too aggressively.
-
Test and iterate: Start with conservative values and gradually adjust based on your application's behavior during deployments.
A good starting point might be:
- Healthy threshold: 2
- Unhealthy threshold: 3
- Timeout: 5 seconds (adjust based on your app's response time)
- Interval: 10 seconds
These settings would require two consecutive successful checks to mark a target as healthy, while allowing three failures before considering it unhealthy. The 10-second interval provides a balance between responsiveness and avoiding excessive load.
Remember to monitor your application's behavior during deployments and adjust these settings as needed. The goal is to find a balance that allows for quick detection of truly unhealthy instances while giving new instances enough time to start up and stabilize.
Additionally, ensure that your application's health check endpoint is properly implemented and responds quickly. A well-designed health check endpoint can significantly improve the reliability of your deployments and the overall health management of your application.
Sources
Update the target group health settings for your Network Load Balancer - Elastic Load Balancing
Update health settings for your Application Load Balancer target group - Elastic Load Balancing
Update the health check settings of an Application Load Balancer target group - Elastic Load Balancing
Update the health check settings of a Network Load Balancer target group - Elastic Load Balancing
Optimize load balancer health check parameters for Amazon ECS - Amazon Elastic Container Service
Dear Experts:
Thank you very much for your reply.
We have tried to update "healthCheckGracePeriodSeconds", however we observe some strange outcome.
After we start our DevOps process (change old image to new ECR image), ECS start two new backend task (consider high availability, we set two backend in different availability zone), they went into RUNNING state in about ten seconds. And then, in target group health check page, we could see that two new targets didn't pass health check, and went into unhealthy state.
We thought it might because that the tasks are already went into running state, so even though we already set "healthCheckGracePeriodSeconds" to 300 (seconds), the setting could not help us with the situation.
So I think our problem is, although backend tasks are in running state, it seems not able to pass target group health check.
Here are our health check settings :
- healthy threshold: 5
- unhealthy threshold: 2
- timeout: 5
- interval: 60 (almost as the same as default)
If we change healthy threshold from 5 to 2, then the process could go well.
Could I consider that, our tasks did go into running state, but it is still busy doing something (like communicate with RDS), at this moment they are not able to pass health check, because our health check rule is too strict?
Or is there any else tests we could do to understand what happened?
Thanks for your kind reply.
answered 2 years ago
Relevant content
asked 3 years ago
asked 3 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated a year ago
