High Memory Usage (96%) in AWS Elastic Beanstalk – How to Optimize Auto Scaling Policy?

0

High Memory Usage (96%) in AWS Elastic Beanstalk – How to Optimize Auto Scaling Policy? I am running an AWS Elastic Beanstalk environment with the following Auto Scaling configuration:

Current Auto Scaling Policy Min Instances: 3

Max Instances: 5

Instance Type: t3a.micro

Metric: TargetResponseTime (Average, Seconds)

Upper Threshold: 1 (Scale up)

Lower Threshold: 0.6 (Scale down)

Scale Up Increment: +1

Scale Down Increment: -1

Scaling Cooldown: 360s

Fleet Composition: On-Demand (Base: 0, Above Base: 0)

Capacity Rebalancing: Deactivated

Load Balancer: Application Load Balancer (Public)

Problem My application is experiencing very high memory usage (96%), while CPU utilization remains normal. Despite this, the Auto Scaling policy is not scaling up instances efficiently. This results in performance issues.

Questions Should I change the scaling metric from TargetResponseTime to MemoryUtilization?

What is the best threshold for scaling up and down based on memory usage?

Would enabling Capacity Rebalancing improve stability?

Are there other best practices for managing memory-heavy workloads on Elastic Beanstalk?

I want to keep using t3a.micro instances and avoid changing instance types. Any guidance on improving the Auto Scaling policy would be greatly appreciated!

asked a month ago58 views
1 Answer
1
Accepted Answer

To address your high memory usage issue in AWS Elastic Beanstalk while maintaining your current instance type, you should consider the following adjustments to your Auto Scaling policy:

  1. Changing the scaling metric: Yes, changing the scaling metric from TargetResponseTime to MemoryUtilization would be beneficial in your case. Since your application is experiencing high memory usage while CPU utilization remains normal, using MemoryUtilization as the scaling metric will more accurately reflect your application's resource needs.

  2. Thresholds for scaling based on memory usage: For memory-based scaling, consider setting the upper threshold to around 80-85% and the lower threshold to about 60-65%. This allows for some buffer before reaching critical memory levels. For example:

  • Upper Threshold: 80% (Scale up)
  • Lower Threshold: 65% (Scale down)
  1. Capacity Rebalancing: Enabling Capacity Rebalancing is not likely to significantly improve stability in this case, as it's primarily designed to help maintain capacity during Spot Instance interruptions. Since you're using On-Demand instances, this feature won't have a major impact on your current setup.

  2. Best practices for memory-heavy workloads:

a. Implement custom CloudWatch metrics to monitor memory usage more closely. This can help you set more precise alarms and scaling triggers.

b. Consider using Step Scaling instead of Simple Scaling. Step Scaling allows for more granular control over scaling actions based on the severity of the memory utilization.

c. Reduce the scaling cooldown period. Your current 360-second cooldown might be too long for memory-intensive applications. Try reducing it to 180-240 seconds to allow for faster scaling responses.

d. Implement a custom scaling solution using AWS Lambda functions and CloudWatch alarms to handle more complex scaling scenarios that take into account multiple metrics (e.g., both memory and CPU usage).

e. Regularly review and adjust your scaling configuration to ensure it aligns with your application's evolving needs and usage patterns.

f. Monitor your application closely using additional CloudWatch metrics and set up separate alarms for memory usage. While these won't automatically trigger scaling, they can alert you to potential issues.

g. Optimize your application code to improve memory management if possible.

By implementing these changes, particularly switching to MemoryUtilization as your scaling metric and adjusting your thresholds, you should see improved performance and more efficient scaling for your memory-intensive application while continuing to use t3a.micro instances.

Sources
beanstalk scaling set on CPU, what happens when RAM get eaten up? | AWS re:Post
Elastic Beanstalk is not scaling as expected on Request Count metric | AWS re:Post
ECS Service auto scaling policy conflict the one to other policy | AWS re:Post

profile picture
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • Thank you for your valuable suggestions regarding the scaling policy adjustments for memory utilization. I appreciate your guidance on changing the scaling metric to MemoryUtilization and adjusting the thresholds. However, I have a key concern regarding the CloudWatch agent setup. As I am using AWS Elastic Beanstalk with auto-scaling enabled, I would like a permanent solution where I do not have to manually configure the CloudWatch agent each time the auto-scaling process spins up a new instance. Currently, I understand that CloudWatch memory metrics require the installation of the CloudWatch agent on each EC2 instance. However, manually installing and configuring the CloudWatch agent on new instances every time they are launched isn't ideal for my use case. Is there a way to automatically install and configure the CloudWatch agent on new EC2 instances that are part of my Elastic Beanstalk environment (especially for memory utilization monitoring)? I want to avoid having to manually configure this each time an instance is added or replaced. Can this be achieved using an automated setup such as User Data scripts during instance launch to install the CloudWatch agent automatically? Elastic Beanstalk configurations or environment settings that ensure CloudWatch agent installation for every new instance? create a Custom AMI that already has the CloudWatch agent installed and configured, so every new instance launched from this AMI automatically has the agent pre-installed

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.

Guidelines for Answering Questions