---
# System prepended metadata

title: Parallel and Distributed Systems Lab 6
tags: [Computer Engineering, IUG, Parallel and Distributed Systems, Cloud computing]

---

---
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>

![](https://i.imgur.com/SXiLisc.png)

</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>

![](https://i.imgur.com/LYRN7AB.png)
</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

![](https://i.imgur.com/BUZMdx9.png)

### 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.


![](https://i.imgur.com/ydHkPrN.png)

![](https://i.imgur.com/h9uBEzM.png)


### How to create ALB

1. Open EC2 service

![](https://i.imgur.com/stbTsMP.png)


2. Choose Load Balancers

![](https://i.imgur.com/XMd9ZbS.png)

3. Choose Application Load Balancer

![](https://i.imgur.com/MRo2YtE.png)

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

![](https://i.imgur.com/We0Jvt9.png)


5. Select Availabilty Zones

![](https://i.imgur.com/oq2QhRW.png)


6. Select security group for ALB

![](https://i.imgur.com/d4zgdKU.png)


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"

![](https://i.imgur.com/WTwLAtA.png)

8. choose a target type, we will use instances

![](https://i.imgur.com/KbHMXyO.png)


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

![](https://i.imgur.com/fPYv2kL.png)


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

![](https://i.imgur.com/baZgoGY.png)

11. Press "Create target group"

![](https://i.imgur.com/KdjOFD0.png)

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

![](https://i.imgur.com/pWPZW7J.png)

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

![](https://i.imgur.com/0Xh9MOw.png)

14. Go to Load Balancers and select your ALB

![](https://i.imgur.com/obYV4BC.png)


15. Select Listeners, then select view/edit rules

![](https://i.imgur.com/wuztpl4.png)

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


![](https://i.imgur.com/H3B1Rdq.png)


![](https://i.imgur.com/LJ4jWbf.png)



![](https://i.imgur.com/7HnHuSB.png)


## 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)

![](https://i.imgur.com/zSoiXX8.png)


### 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"

![](https://i.imgur.com/7bOYNOh.png)


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

![](https://i.imgur.com/qg6d40G.png)

3. Configure your lanch template, like Ec2 configuration

![](https://i.imgur.com/QDh6bCf.png)

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

![](https://i.imgur.com/LOCDr91.png)

5. Select AZs and press next

![](https://i.imgur.com/DFpet87.png)


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

![](https://i.imgur.com/2dxoD68.png)


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

![](https://i.imgur.com/sn8vqmo.png)

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

![](https://i.imgur.com/uIxr5Bg.png)

9. Scheduled actions Example


![](https://i.imgur.com/350p6nZ.png)


10. Target Tracking Scaling Example

![](https://i.imgur.com/vVMOo0p.png)


###### tags: `Parallel and Distributed Systems` `Cloud computing` `IUG` `Computer Engineering`

<center>End Of Lab 6</center>