A multi-threaded TCP-based HTTP load balancer implemented in C++ for distributing client requests across backend servers with automatic health monitoring and real-time statistics.
1. Weighted Least Connections Algorithm — Intelligent traffic distribution based on current server load
2. Automatic Health Monitoring — Continuous health checks with failover capabilities
3. Real-time Statistics — Live monitoring of connections, requests, and server status
4. Multi-threaded Architecture — High-performance concurrent connection handling
Diagram created using StarUML 7.0.0
- C++14 compatible compiler (g++)
- Python 3.x (for test backend servers)
- Linux/Unix environment
# Clone the repository
git clone https://github.com/psychomita/load-balancer.git
cd load-balancer
# Build the project
make# Equal Weight Distribution (as shown in the diagram)
./bin/load_balancer 8080 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003
# Weighted Distribution
./bin/load_balancer 8080 127.0.0.1:9001:2 127.0.0.1:9002:1 127.0.0.1:9003:1
# With Connection Limits
./bin/load_balancer 8080 127.0.0.1:9001:2:500 127.0.0.1:9002:1:200# Terminal 1
python3 test_server.py 9001 9002 9003# Terminal 2
./bin/load_balancer 8080 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003# Terminal 3
# Single request
curl http://localhost:8080
# Multiple requests to see load balancing
for i in {1..1000}; do curl -s http://localhost:8080 > /dev/null & done
wait
Test servers run on ports 9001, 9002 and 9003, serving content about Bjarne Stroustrup
- When all backend servers are running, they are marked as HEALTHY.
- When all servers are stopped, the load balancer reports no healthy servers available.
- Metrics tracked are
Total requests processed,Number of healthy serversandServer-wise statistics.
The load balancer uses a Weighted Least Connections algorithm:
- Health Check: Only healthy servers are considered
- Weight Calculation:
effective_load = active_connections / weight
Requests from port 8080 are routed to backend servers 9001, 9002 and 9003
- Operating Systems: Process Management, Memory Management, Inter-Process Communication
- Computer Networks: Socket Programming, HTTP Protocol, Network Architecture
- Data Structures & Algorithms: Vector Containers, Load Balancing Algorithm, Concurrency Control
For visual reference, watch the Demo Video