Coder Social home page Coder Social logo

distributedsystem's Introduction

Asynchronous Load Balancer

This project implements a load balancer in Python using asynchronous programming techniques and Docker containers to distribute incoming requests from multiple clients evenly among several servers. The load balancer helps in distributing the load across servers efficiently, ensuring optimal resource utilization and preventing any single server from becoming overwhelmed.

Coding Environment

  • OS: Ubuntu 20.04 LTS or above
  • Docker: Version 20.10.23 or above
  • Languages: Python (preferred), C++, Java, or your choice

Installation

  1. Install Docker:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL [https://download.docker.com/linux/ubuntu/gpg](https://download.docker.com/linux/ubuntu/gpg) | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] [https://download.docker.com/linux/ubuntu](https://download.docker.com/linux/ubuntu) $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io ...
  1. Install Docker-Compose:
sudo curl -SL https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

How to Use

  1. Running the Project:
  • Clone the repository: git clone cd
  1. Build and start containers:
docker-compose up --build
  1. Interacting with the Load Balancer:
  • Check replica status: curl -X GET http://localhost:5000/rep

  • Add new server instances:

bash
curl -X POST -H "Content-Type: application/json" -d '{"n": 2, "hostnames": ["S4", "S5"]}' http://localhost:5000/add
  • Remove server instances: curl -X DELETE -H "Content-Type: application/json" -d '{"n": 2, "hostnames": ["S4", "S5"]}' http://localhost:5000/rm

  • Route requests through the load balancer:

bash
curl -X GET http://localhost:5000/home

Dependancies

  • Docker -Docker-Compose

Design Choices and Assumptions

  • Consistent Hashing: Ensures even load distribution and handles dynamic server changes with minimal disruption.
  • Docker: Provides an isolated and reproducible environment.
  • HTTP Endpoints: Simplifies communication between clients, the load balancer, and server replicas.

Testing and Performance Analysis

Experiment 1: Load Distribution

  • Launch 10,000 asynchronous requests on 3 server containers.
  • Record the number of requests handled by each server and plot a bar chart.
  • Expected Outcome: Even distribution of load among server instances.

Experiment 2: Scalability

  • Increment the number of server containers from 2 to 6 (launching 10,000 requests each time).
  • Plot a line chart showing the average load of the servers at each run.
  • Expected Outcome: Efficient scaling with even load distribution as server instances increase.

Experiment 3: Failure Recovery

  • Test load balancer endpoints and simulate server failures.
  • Ensure the load balancer spawns new instances to handle the load and maintain the specified number of replicas.

Experiment 4: Hash Function Modification

  • Modify the hash functions H(i) and Φ(i,j).
  • Repeat experiments 1 and 2, analyzing the impact on load distribution and scalability.

distributedsystem's People

Contributors

rajan-okita avatar steve-oparr avatar sydney-nyanchoga avatar muchaimwitia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.