AWS EC2 contd…
Horizontal vs Vertical Scaling
- Differences

- Vertical scaling in AWS is possible by changing instance type.
- When we change the instance type the ec2 instance should be in stopped state
- Changing instance type in AWS. Shutdown the ec2 instance




- start the ec2 instance
-
Horizontal scaling:
- This can be done manually by adding ec2 instances with the same AMI.
- Consider the below architecture

- As number of parallel users increase, load on web, orders and catalog increases which might lead to performance bottleneck.
- During the peaks or when in need we need aws to automatically increase number of ec2 instances running the corresponding application.
- It is better to create an AMI for
- web
- orders
- catalog
- AWS has an option to perform auto scaling which is referred as Auto scaling group.
Auto Scaling Groups
-
AWS EC2 Auto Scaling Groups give us two broader options
- fixed scaling:
- In Fixed scaling the fixed count is maintained by AWS
- For eg: you have give fixed scaling count to 5, it creates 5 ec2 instances in chosen subnets (AZ’s). By any chance if the ec2 instance is down, aws will create one more to maintain count of 5
- auto scaling:
- In this case we specify
- min ec2 instances
- max ec2 instances
- desired count
- We also specify when the ec2 instance count should be increased (scaled out) and decrease (scaled in)
- desired count will be dynamic depending on situation.
- In this case we specify
- fixed scaling:
-
To Create Autoscaling group
- AMI: Create AMI with Applications pre installed
- Decide which metrics to use when your ec2 has to be scaled out or in
- Choose the AZ’s (subnets) where scaling has to happned
- Choose the scaling methodologies
Experiments
- Create an ec2 instance with phpinfo and stress
#!/bin/bash
apt update
apt install apache2 stress -y
apt install php libapache2-mod-php php-mysql -y
echo '<?php phpinfo(); ?>' > /var/www/html/info.php
systemctl restart apache2
- Navigate to monitoring on AWS Console

- ssh into ec2 and execute
stress --cpu 10 --io 40 --vm-bytes 256M --timeout 10m -v
- observe the metrics on the AWS Console for next 10 minutes

- Generally in servers like apache the load on cpu increases as number of requests to websit increases, so cpu utilization should be a decent metric to start scaling

