---
title: Parallel and Distributed Systems Lab 6
---
<h1 style='border: none'><center>Parallel and Distributed Systems Lab 6</center></h1>
<h2 style='border: none'><center>Amazon Web Service(AWS)<br>Load Balancing and Auto Scaling Groups</center></h2>
<h5><center>The Islamic University of Gaza<br>Engineering Faculty<br>Department of Computer Engineering</center></h5>
<h6>Authors: Abdullah Abu Ajwa and Usama R. Al Zayan<span style="float:right">2022/11/18</span></h6>
---
## Scalability & High Availability
**Scalability** means that an application / system can handle greater loadsby adapting.
There are two kinds of scalability: Vertical Scalability, Horizontal Scalability.
### Vertical Scalability (= scale up / down)
Vertically scalability means increasing the size of the instance.
For example, your application runs on a t2.micro, to scale that application vertically means running it on a m5.large.
### Horizontal Scalability (= scale out / in)
Horizontal Scalability means increasing the number of instances / systems for your application.
</br>
<center>

</center>
### High Availability
**High availability** means running your application / system in at least 2 data centers (== Availability Zones).
The goal of high availability is to survive a data center loss.
## Load balancing
**Load Balances** are servers that forward traffic to multiple servers.
The default routing algorithm is Round Robin.
<center>

</center>
### Why use a load balancer?
* Spread load across multiple instances.
* High availability across zones.
* Seamlessly handle failures of instances.
* Do regular health checks to your instances.
* Separate public traffic from private traffic.
### Elastic Load Balancer
* An Elastic Load Balancer is a managed load balancer.
* AWS guarantees that it will be working.
* AWS takes care of upgrades, maintenance, and high availability.
* It is integrated with many AWS offerings / services, like EC2, EC2 Auto Scaling Groups and others.
### Health Checks
* It enables the load balancer to know if instances it forwards traffic to are available to reply to requests.
* If the response is not 200 (OK), then the instance is unhealthy.
### Types of load balancer on AWS:
Classic Load Balancer, Application Load Balancer, Network Load Balancer, Gateway Load Balancer.
### Load Balancer Security Groups

### Application Load Balancer (ALB)
**Application load balancers** function at the application layer, the seventh layer (HTTP).
**Target group**: Application Load Balancer routes requests to one or more registered targets (e.g. EC2 instances).
**Listener**: A listener checks for connection requests from clients per rules that determine how ALB routes requests to registered targets.(If someone is accessing our load balancer on, from the protocol HTTP on port 80, then forward to the target group.)
**Routing tables to different target groups:**
* Routing based on path in URL `example.com/users` & `example.com/posts`)
* Routing based on hostname in URL (`one.example.com` & `other.example.com`)
* Routing based on Query String, Headers (`example.com/users?id=123&order=false`).
#### Target Groups may be:
EC2 instances, ECS tasks, Lambda functions, IP Addresses.
#### ALB Support for WebSocket.
ALB is a great fit for micro services.


### How to create ALB
1. Open EC2 service

2. Choose Load Balancers

3. Choose Application Load Balancer

4. Type name of ALB, detect if ALB internet-facing or internal

5. Select Availabilty Zones

6. Select security group for ALB

7. This mean that if someone is accessing our load balancer on, from the protocol HTTP on port 80, then forward to the target group.
Select "Create target group"

8. choose a target type, we will use instances

9. Exapnd "Advanced health check settings" and configure the Health Check, then press next.

10. Select the instances then press "Include as pending below"

11. Press "Create target group"

12. Now we will back to load balancer, select our target group

13. Review the summary and press "Create load balancer"

14. Go to Load Balancers and select your ALB

15. Select Listeners, then select view/edit rules

16. Press insert rule, then add condition, and select your condition



## Auto Scaling Group
* Scale out (add EC2 instances) to match an increased load
* Scale in (remove EC2 instances) to match a decreased load
* Ensure we have a minimum and a maximum number of EC2 instances running
* Automatically register new instances to a load balancer
* Re-create an EC2 instance in case a previous one is terminated (ex: if unhealthy)

### Auto Scaling Group Attributes:
* Min Size / Max Size / Initial Capacity
* Scaling Policies
* Launch Template
### Launch Template:
AMI + Instance Type, EC2 User Data, EBS Volumes, Security Groups, SSH Key Pair, IAM Roles for your EC2 Instances, Network + Subnets Information.
### Auto Scaling - CloudWatch Alarms & Scaling
• It is possible to scale an ASG based on CloudWatch alarms.
• An alarm monitors a metric (such as Average CPU)
• Metrics such as Average CPU are computed for the overall ASG instances
Based on the alarm:
• We can create scale-out policies (increase the number of instances)
• We can create scale-in policies (decrease the number of instances)
### Auto Scaling Groups – Scaling Policies
#### Target Tracking Scaling:
* Most simple and easy to set-up.
* Example: I want the average ASG CPU to stay at around 40%.
#### Simple / Step Scaling
* When a CloudWatch alarm is triggered (example CPU > 70%), then add 2 units.
* When a CloudWatch alarm is triggered (example CPU < 30%), then remove 1.
#### Scheduled Actions
* Anticipate a scaling based on known usage patterns.
* Example: increase the min capacity to 10 at 5 pm on Fridays.
### ِHow to create Auto-scaling group
1. Go to EC2 and select Auto Scaling Group, and press "Create Auto Scaling group"

2. Write Auto scaling group name, then press "Create a launch template"

3. Configure your lanch template, like Ec2 configuration

4. Back to Auto Scaling group, and select your launch template, then press next

5. Select AZs and press next

6. Configure the load balancer, you can attach existing load balancer, or attach a new load balancer, then press next

7. Specify the size of desired, minimum and maximum capacity, then press next

8. skip step 5 and 6. and create the Auto scaling group

9. Scheduled actions Example

10. Target Tracking Scaling Example

###### tags: `Parallel and Distributed Systems` `Cloud computing` `IUG` `Computer Engineering`
<center>End Of Lab 6</center>