Developed a distributed load balancer using a Flask web application integrated with Redis on WSL, facilitating dynamic task scheduling across multiple server controllers.
- Overview
- Features
- Prerequisites
- Installation and Setup
- Monitoring and Logs
- Project Structure
- Troubleshooting
- License
This project implements a distributed load balancer that dynamically schedules tasks across three server controllers. The system leverages:
- Flask Web Application: Offers a real-time Windows dashboard that displays up to 50 logs stored in Redis and provides start/stop controls for individual backend servers.
- Redis for Centralized Logging: Stores all logs and facilitates real-time monitoring.
- Round-Robin Queue: Distributes operations (prime checking, palindrome validation, reverse computation, Fibonacci calculation, and word count) evenly across servers.
- Automated Health Checks: Every second, the system checks server performance to ensure high availability and resilience.
- Distributed Scheduling: Dynamically assigns tasks among multiple backend servers.
- Real-Time Monitoring: Visualizes the latest 50 log entries from Redis in the Windows dashboard.
- Dynamic Control: Start or stop individual backend servers through the dashboard UI.
- Periodic Health Checks: Continuously monitors server performance with automated checks.
- Centralized Logging: Uses Redis to manage logs for streamlined real-time data tracking.
- Windows 10/11 with WSL
- Visual Studio Code (VS Code)
- Docker (installed on WSL)
- Python 3.x
- Install WSL:
Follow the Microsoft WSL installation guide to enable and configure WSL. - Install VS Code:
Download and install Visual Studio Code.
- Open your WSL terminal.
- Follow the official Docker installation guide for Ubuntu:
Install Docker on Ubuntu.
- In your WSL terminal, run:
This downloads the latest Redis Docker image.
docker pull redis
- Open (or create) the
/etc/wsl.conffile in your WSL environment and add:[network] generateResolvConf = false - Save the file and restart WSL:
Then launch WSL again.
wsl --shutdown
- In your WSL terminal or Windows Command Prompt, run:
This clones the project repository to your machine.
git init git pull https://github.com/Harsh971/Distributed-Load-Balancer.git
- Open VS Code and navigate to your project folder.
- Open the integrated terminal in VS Code and run:
These commands install the required libraries.
pip install flask pip install redis pip install psutil
- In your WSL terminal, start Redis:
sudo service redis-server start
- Verify the status:
sudo service redis-server status
- In VS Code's terminal, run:
python dashboard.py
- This starts the Flask dashboard on
http://127.0.0.1:5000/.
- Open a new terminal in VS Code or another instance and run:
python load_balancer_async.py
- The load balancer listens on port
12000and distributes tasks to the backend servers.
- Open your browser and navigate to:
http://127.0.0.1:5000/
- Use the dashboard to:
- View server statuses
- Start/stop individual servers
- Submit operations for distributed processing
- Monitor the latest 50 log entries from Redis
- Viewing Logs via Redis CLI:
- Open your WSL terminal and run:
redis-cli
- In the Redis CLI, view logs by executing:
LRANGE lb_logs 0 49
- Open your WSL terminal and run:
- Dashboard Logs:
The dashboard UI displays the latest 50 log entries in real time.
- dashboard.py:
Implements the Flask dashboard for monitoring and controlling servers. - server.py:
Contains backend server logic for executing operations. - load_balancer_async.py:
Manages task distribution to backend servers with a round-robin algorithm. - client.py:
A simple client to test the load balancer's operation.
- Port Binding Issues:
If you see permission errors or port conflicts, run your terminal as an Administrator and verify with netstat:netstat -ano | findstr :<port>
- WSL Networking:
Ensure your WSL IP remains current. Update any port proxy settings if the WSL IP changes. - Dependency Issues:
Confirm all Python dependencies are installed with:pip install flask redis psutil
- Service Startup:
Run Redis, the dashboard, and the load balancer in separate terminals to ensure they start correctly.
This project is licensed under the MIT License. See the LICENSE file for more information.
Your feedback is valuable! If you have suggestions for improving existing content or ideas for new additions, please open an issue or reach out to the repository maintainers. If you have any other feedbacks, you can reach out to us at harsh.thakkar0369@gmail.com

