Yii2 Assets Bundle Configuration for Auto Scaled Elastic Beanstalk environment

Hello all,

Can you suggest me best configuration that can handle great amount of requests (such as 5000 users)

Entire application and its components is on AWS.

Application Background: Application is all about providing LMS with additional ability to our clients.

Production Server: we have deployed application directly on ec2 (t2.medium) instance.
Using RDS for MySQL database
Using Redis for session and cache
Load balancer with No auto scaling
The system is currently serves 500 users but with some outage with sudden spike in CPU.

So we have decided to migrate entire application with good infrastructure.

So now we are using (staging as we are finalising)
New Infrastructure

  • AWS CICD Pipeline with Source, Build and Deploy
  • ElasticBeanstalk with Auto Scaling Group, Load Balancer
  • Ec2 Instance type: m5.xlarge
  • RDS for MySQL database
  • ElastiCache with Redis for Cache and Session Management
  • S3 for file storage

How deployment is working? And Problem.
When our developer push the code to git, the CICD will trigger and start with Build Process.
Build Process includes

  • Composer Library Installation
  • Assets Generation (backend/web/assets/staticfiles/*) We use hashcallback and return staticfiles instead of random hash

Once the build process is done we are using that artifact to deploy it on ec2 instances using elasticbeanstalk

The problem: Load Testing

  • when putting 50 request load the system CPU spiked up and hit 100%, resulting auto scalling trigger
  • the new instance as soon as get ready again hit 100% CPU
  • When checking with SSH into Ec2 instance it seems PHP-FPM is using extensive amount of CPU.

Problem: HTTPD Configuration (apache)

  • what is the best configuration I should use to handle such amount of requests?
  • currently using mpm-worker so is it good?
  • what configuration I should set for MPM?

Same as above PHP-FPM
What configuration I should use for PHP FPM?

Problem Assets Bundle

  • Instead of serving assets bundle from EC2 Instance how can I use CDN approach? If you are suggesting S3 With CloudFront, how can I upload assets including vendor folder on S3
  • What if there is a request that may required to generate new assets bundle if not included in building stage.

How to debug which process/requests are using high CPU?

What are the other recommendations you would have to make our application robust, highly available and reliable?

The concerning part in this case is we are using xLarge instance type even though the application is not performing well while app on outdated t2.medium working great :grinning:

Your help would greatly benefit to a lot of users I believe as mid level of experience developer.

You are the hope: @samdark, @evstevemd, @cebe @terabytesoftw @BartQ76