AWS Classroom Series – 13/Aug/2020

Vertical & Horizontal Scaling in EC2 instances

  • Vertical scaling is add more power to your existing machines (Scaling up)
  • Horizontal scaling is adding more machines which do the same job (Scaling out)
  • In AWS we can do both Vertical & Horizontal scaling.
  • Vertical scaling can be done by changing instance size of the vm, This requires ec2 instance to be stopped
  • Horizontal scaling can be done by adding more ec2 instances & this can be automated by certain metrics like cpu utilization, disk IO etc using Auto scaling groups
  • Lets do Vertical scaling of t2.micro instance in AWS to t2.large (Scale up) Preview Preview Preview Preview Preview Preview Preview
  • In the same we can also (Scale down) changing from larger instance size to smaller instance size
  • Consider a scenario where your company has food delivering app and you are using ec2 instance for hosting the application Preview
  • Now our application has become popular & lots of users are using it (of-course we have discounts)
  • As load increases and decreases we might want a solution which will automatically add and remove servers depending on some metric (Generally for web/mobile applications CPU Utilization is considered) Preview
  • In our case since this a food delivering app, we do have peak hours.
  • Amazon offers Auto Scaling Groups which can automatically add/remove ec2 instances depending on some metric (Cloud watch)
  • Now in the ec2 machines our applications should be running so we have two options
    • Create an AMI with your application
    • Create an os based AMI (ubuntu) & install your application after ec2 instance is up?
  • Having an AMI with application is better, so lets create an AMI to simulate the scenario. In this case since we don’t have users we will create artificial load on ec2 instance
  • Lets install lamp stack with one additional tool called as stress
sudo apt-get install stress -y
sudo apt-get update
sudo apt-get install apache2 -y
sudo apt install php libapache2-mod-php php-mysql -y
sudo apt install php-cli stress -y
sudo -i
echo "<?php phpinfo(); ?>" >> /var/www/html/info.php
sudo systemctl restart apache2

Preview

  • Auto scaling helps you ensure that you have correct number EC2 instances available for handling load of your application. Preview
  • Auto scaling components
    • Groups: Your ec2 instances will be organized as groups. In reality consider each application/service as a group
    • Configuration Template: In this we specify which AMI id, instance type, key pair etc
    • Scaling OPtions: What is minimum size , maximum size, conditions for scaling out (increasing ec2 instances) & scaling in (decreasing ec2 instances)
  • Autoscaling Lifecycle Preview
  • Lets create an autoscaling group with our ami Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview Preview

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin