By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Autoscaling PHP in EBT

0

I deploy my PHP scripts into ElasticBeanstalk. I want to configure autoscaling for my servers to be between 2 and 5 servers. I want to prevent a situation when the servers exhaust all memory and scripts start failing because of that. Therefore I want the ASG to start new servers when the used memory in any of the servers goes above a certain limit. I am using a network LB in my environment. Do I need to configure something special? When I start PHP script that allocates a lot of memory, it falls down with HTTP status 500 and nothing scales. How can I make it scale automatically? Is there a good article summarizing how to make it work? I somehow could not find the right one around.

asked 24 days ago27 views
2 Answers
0

To configure autoscaling for your PHP scripts in Elastic Beanstalk with the requirements you've described, you'll need to make some specific configurations to your environment. Here's how you can set this up:

  1. Set the Auto Scaling group size: You can configure your Auto Scaling group to have a minimum of 2 instances and a maximum of 5 instances. This can be done through the Elastic Beanstalk console under the "Capacity" section of your environment's configuration.

  2. Configure a custom CloudWatch metric for memory usage: By default, Elastic Beanstalk doesn't monitor memory usage. You'll need to set up a custom CloudWatch metric to track memory utilization. This typically involves installing and configuring the CloudWatch agent on your EC2 instances to report memory metrics.

  3. Create CloudWatch alarms: Once you have the memory metrics available, create CloudWatch alarms that trigger when memory usage exceeds your specified threshold.

  4. Set up scaling triggers: Configure your Auto Scaling group to use these CloudWatch alarms as scaling triggers. When the alarm state changes, it will initiate a scaling action.

  5. Adjust your application's error handling: Ensure your PHP application is configured to handle out-of-memory errors gracefully and return appropriate error responses.

  6. Configure your load balancer: Since you're using a Network Load Balancer, make sure it's configured to properly distribute traffic and perform health checks on your instances.

To implement these changes, you can use the Elastic Beanstalk console, the EB CLI, or configuration files in your application source bundle.

For the scaling triggers based on memory usage, you might need to use the AWS CLI or SDK to set up the custom CloudWatch metrics and alarms, as these are not directly configurable through Elastic Beanstalk's standard options.

If your PHP scripts are still failing with HTTP 500 errors and not triggering scaling actions, it's likely because the default configuration is not capturing these errors as indicators for scaling. You may need to adjust your application's error handling to ensure that memory-related issues are properly reported and logged.

Remember that scaling actions take some time to complete, so you may still experience some downtime or errors while new instances are being launched. Consider implementing caching strategies or optimizing your PHP scripts to reduce memory usage where possible.

While there isn't a single comprehensive article that covers all these aspects specifically for PHP in Elastic Beanstalk, you can refer to AWS documentation on Auto Scaling groups, CloudWatch metrics and alarms, and Elastic Beanstalk environment configuration for more detailed implementation steps.
Sources
Auto Scaling group configuration for your Elastic Beanstalk environment - AWS Elastic Beanstalk
Auto Scaling triggers - AWS Elastic Beanstalk
Auto Scaling group for your Elastic Beanstalk environment - AWS Elastic Beanstalk

profile picture
answered 24 days ago
0

Hello.

It's a bit old, but please install the CloudWatch Agent on ElasticBeanstalk's EC2 so that you can get memory usage with CloudWatch as shown in the Stackoverflow answer below.
Once you can obtain the memory usage rate, you can configure scaling using the memory usage rate in the AutoScaling group settings to scale out EC2 when the memory usage rate becomes high.
https://stackoverflow.com/questions/53670210/aws-elastic-beanstalk-and-auto-scaling-when-out-of-memory

The following documents may be helpful for configuring CloudWatch Agent.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-cw.html

I think the following document will be helpful for AutoScaling's scaling policy.
https://docs.aws.amazon.com/autoscaling/ec2/userguide/examples-scaling-policies.html

profile picture
EXPERT
answered 24 days 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.

Guidelines for Answering Questions