Skip to content

How to determine target group health check settings ?

0

Dear Experts:

We have an application load balancer and two target groups: application frontend and backend. The applications are running on ECS fargate, and load balancer use path to determine which target to route traffic to.

We found that when we update our backend application (by build an new ECR image and replace the old image), we got and error message like: Task failed ELB health checks in target-group... (There are no error code, and if we look at cloudwatch backend log, there are no error message either)

According to the article, we could set Health Check Grace Period, which could give tasks more time when they first start, but we still face the same problem: Task failed ELB health checks in target-group...

So our first question is: Dose the parameter Health Check Grace Period only effect health check in ECS, but will not influence other health check in our structure, for instance load balancer target group? (We would also like to know that, if we set an auto scaling group, cloud Health Check Grace Period also effect auto scaling group ?)

Since change Health Check Grace Period setting seems can't help us with our problem, we tried to change target group advanced health check settings, and we found that if we set the healthy threshold lower, when the new tasks start, they will be able to pass health check, and our DevOps process ( update task image to new ECR image) works fine.

However, we could not found document or guide to tell us, how to determine what values should set to advanced health check settings.

Is there any related document, guide, or best practices suggestions which could told us how to set target group health check settings ? (parameters include: healthy threshold, unhealthy threshold, timeout and interval)

Thanks very much.

asked 2 years ago1.1K views

3 Answers
1

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.

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

0

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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:

  1. Analyze your application's startup time: Monitor how long it takes for your backend to fully initialize and be ready to serve requests.

  2. Consider your application's normal response time: Use this as a baseline for setting the timeout value.

  3. 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.

  4. 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

answered 2 years ago

EXPERT

reviewed 2 years ago

0

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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.