Scaling
- Scaling is of two types
- Horizontal: Increasing number of servers with same application to distribute the load
- Veritical Scaling: Increasing systems resources like cpu, ram etc. In Aws, you can do this changing instance size
- Why scaling ?
- Because you might need more performance, availiability, load increased etc
Scenario:
-
Our Organization (QT) has an ecommerce application with the folowing architecture
-
Due to offers on your ecommerce application load increased, when load increases it is better to increase virtual machine (ec2 instances)
-
How to do this in AWS?
- EC2 Auto Scaling
-
Autoscaling relys on
- AMI’s: To create a new instance with same software/application we would need AMI’s first
- Auto Scaling Group: Each Auto Scaling group represents an application component (webserver/appserver). Auto scaling group will have following information
- Minimum number of ec2
- Desired Capacity of ec2
- Maximum number of ec2 instances
- Cloudwatch metrics/alerts: These help in deciding when to scale.
Lets do this practically
- Creating an ubuntu image with lamp stack installed based out of steps from here.
- In this scenario i will be creating an artifical load and for that i will be using a tool called as stress
- commands executed after ssh into ec2 ubuntu instance
sudo apt-get update
sudo apt-get install apache2 -y
sudo apt install php libapache2-mod-php php-mysql -y
sudo systemctl restart apache2
sudo systemctl enable apache2
sudo apt install php-cli -y
sudo vi /var/www/html/info.php =>
<?php
phpinfo();
?>
sudo systemctl restart apache2
sudo apt-get install stress -y
-
Create an AMI of the Ec2 instance
-
Assume you need to increase your ec2 instances by 1 when the cpu utilization average is greater than 75% for atleast 5 mins and decrease your ec2 instances by 1 when the cpu utilization is less that 50% for atleast 5 mins
-
Now Navigate to the Autoscaling section
-
Autoscaling groups requires launch configuration or launch template
-
Click on Create Autoscaling group
-
Create a new launch configuration and select AMI
-
Choose the size which fits your application. (I use t2.micro for demo)
-
Create launch configuration and select storage, security group (create)
-
Create a Autoscaling group for a launch configuration
-
Select scaling policies
-
For this case we have decided "increase your ec2 instances by 1 when the cpu utilization average is greater than 75% for atleast 5 mins and decrease your ec2 instances by 1 when the cpu utilization is less that 50% for atleast 5 mins", so lets implement
-
Add Notificiations if required
-
Review the settings and create autoscaling group to see instances to be created (in action)
-
Now have a look at ec2 instance autoscaling group view
-
Wait till Desired (Expected) reaches the current count
-
Now find the instance id and navigate to it
-
Now find public ip and navigate to “`http://publicip/info.php“
-
If you want to do the same from cli refer here
Next topics
- How to scale and load balance