- Newest
- Most votes
- Most comments
Hi suman
You want to implement a scaling strategy for your Auto Scaling Group (ASG) that:
- Scales up when CPU utilization reaches 50% for 120 seconds.
- Directs incoming requests to the existing EC2 instance while the new instance is being provisioned.
- Once the new instance is ready, directs traffic to the new instance.
Here's a step-by-step solution using AWS services:
Step 1: Configure Auto Scaling Group (ASG)
- Set Minimum capacity: 1
- Set Maximum capacity: desired maximum value
- Set Desired capacity: 1 (initially)
- Create a scaling policy using CloudWatch metric (CPUUtilization):
- Threshold: 50%
- Evaluation period: 120 seconds
- Scaling adjustment: +1 (add 1 instance)
Step 2: Configure Load Balancer (ELB/ALB/NLB)
- Create a load balancer with a target group pointing to your ASG
- Ensure the load balancer is configured for connection draining (to ensure existing connections are maintained)
Step 3: Implement Request Queueing
To queue incoming requests while the new instance is being provisioned, use Amazon SQS or Amazon Lambda:
Hello,
Based on your question, it seems that the issue you're facing is related to the handling of incoming requests during the process of scaling up (launching new EC2 instances) in your Auto Scaling group (ASG).
The problem you're describing is that when a new EC2 instance is being launched as part of the scale-out process, incoming requests are still being routed to the existing running instance(s) instead of waiting for the new instance to become ready and then directing the traffic to it.
To address this issue, you need to configure the following settings in your AWS environment:
- Health Check Grace Period:
- Set a health check grace period for your Auto Scaling group. This is the time that Auto Scaling will wait before checking the health status of a newly launched instance.
- During this grace period, the new instance will be considered unhealthy, and no traffic will be routed to it by the load balancer.
- You can set the health check grace period in the Auto Scaling group configuration. A typical value is 300 seconds (5 minutes).
- Deregistration Delay:
- Configure a deregistration delay for your Elastic Load Balancing (ELB) target group or Classic Load Balancer.
- This setting determines the time that the load balancer will wait before deregistering an instance that is being terminated or replaced.
- During this deregistration delay, the load balancer will continue routing traffic to the existing instance(s) while the new instance is being launched and warmed up.
- You can set the deregistration delay in the ELB target group or Classic Load Balancer configuration. A typical value is 300 seconds (5 minutes).
By configuring these settings correctly, you can ensure that incoming requests are not dropped or rejected during the instance launch process. Instead, they will be routed to the existing healthy instances until the new instances are ready to serve traffic.
Here's how the process will work with the correct configuration:
- When the CPU utilization of your Auto Scaling group reaches the scale-out threshold, a new instance will be launched.
- During the health check grace period (e.g., 300 seconds), the new instance will be considered unhealthy, and no traffic will be routed to it by the load balancer.
- After the health check grace period, if the new instance passes the health checks, it will be registered with the load balancer and start receiving traffic.
- If a request comes in while the new instance is being launched and warmed up, it will be routed to the existing healthy instance(s) due to the deregistration delay.
- When an existing instance needs to be terminated (e.g., during a scale-in event or instance replacement), the deregistration delay will ensure that the instance remains in service for a certain amount of time, allowing the load balancer to continue routing traffic to it while the new instance is being launched and warmed up.
By implementing these settings, you can ensure that incoming requests are not dropped or rejected during the instance launch or termination process, and traffic is seamlessly directed to the appropriate instances based on their health status.
Hello,
To address this issue, when scaling up an EC2 instance in your Auto Scaling Group (ASG), requests should not be immediately sent to the new instance while it's still being set up. Instead, you can handle this with two key steps:
-
Health Checks: Configure the Auto Scaling Group to add new EC2 instances to the load balancer only after they pass health checks. This way, the new instance won’t receive any traffic until it's fully ready.
-
Sticky Sessions: Enable sticky sessions on your load balancer to keep ongoing traffic on the original EC2 instance while the new one is coming online. This ensures the running instance handles the traffic during the scale-up process.
This setup allows your original instance to handle traffic until the new instance is fully available.
https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html
Relevant content
asked 3 years ago
