THANOS is a powerful, feature-rich load balancer built with Golang that uses the five infinity stones (metrics) to deliver optimal and dynamic traffic distribution. Inspired by the balance of the universe, THANOS ensures fairness, reliability, and resilience in your distributed systems.
-
Weighted Round Robin Load Balancing:
- Dynamically distributes traffic based on server health and custom metrics.
-
Infinity Stone Metrics:
- CPU Utilization (Power Stone)
- Memory Usage (Reality Stone)
- Response Time (Time Stone)
- Error Rate (Soul Stone)
- Ping Status (Space Stone)
-
Sticky Sessions:
- Ensures session affinity for consistent user experience.
-
IP Hashing:
- Maps clients to servers based on their IP addresses for predictable routing.
-
Health Checks:
- Periodically assesses server health using the five metrics.
-
Circuit Breaker:
- Protects servers by dynamically routing traffic away from unhealthy ones.
-
Metrics Dashboard:
- Visualize server health, weights, and statuses in real time.
- Go: Version 1.18 or higher
- Git: Version 2.25 or higher
git clone https://github.com/Distributed-Systems-KP/Dynamic_Load_Balancer.git
cd thanos-load-balancer
-
Build the project:
go build -o thanos cmd/loadbalancer/main.go
-
Run the load balancer:
./thanos
-
Configure your servers:
- Edit the configuration file
internal/config/config.go
to include your backend servers.
- Edit the configuration file
Modify the config.go
file to set up your environment:
LBPort: 8080, // Load balancer port
HealthCheckInterval: 5 * time.Second, // Health check interval
UseIPHash: true, // Enable IP hashing
UseStickySessions: true, // Enable sticky sessions
CircuitBreaker: {
FailureThreshold: 3,
CooldownPeriod: 10 * time.Second,
TrialRequests: 2,
},
Servers: [
{ID: "server-1", Address: "localhost", Port: 9001},
{ID: "server-2", Address: "localhost", Port: 9002},
]
./thanos
-
Forward Traffic:
- Send client requests to the load balancer:
curl http://localhost:8080/
- Send client requests to the load balancer:
-
Metrics Dashboard:
- Access real-time server metrics:
http://localhost:8080/metrics
- Access real-time server metrics:
The dashboard visualizes the health of servers based on the infinity stone metrics. It displays:
- Server Health Scores
- Current Weights
- Circuit Breaker Status (Closed/Open/Half-Open)
- CPU and Memory Usage
- Response Times and Error Rates
- Power Stone (CPU Utilization): Measures server processing power usage.
- Reality Stone (Memory Usage): Tracks server memory consumption.
- Time Stone (Response Time): Ensures servers respond within acceptable limits.
- Soul Stone (Error Rate): Monitors failure rates for server reliability.
- Space Stone (Ping Status): Verifies server reachability.
- Weighted Round Robin:
- Dynamically assigns traffic based on the combined weights of all five metrics.
- Circuit Breaker:
- Routes traffic away from unhealthy servers.
- Sticky Sessions & IP Hashing:
- Ensures consistent routing for repeat users or sessions.
-
Start mock servers (9001 and 9002).
-
Send continuous requests to the load balancer:
while true; do curl -s http://localhost:8080/ -o /dev/null & done
-
Simulate failures by introducing delays or increasing CPU/memory usage on servers.
- Use
/metrics
or the dashboard to monitor server health and load balancing in action.
Thanos is Yet to find the mind stone, since we are trying to integrate ML algorithms to forward load smartly.
Contributions are welcome! Here's how you can get involved:
- Fork the repository.
- Create a new branch:
git checkout -b feature/my-feature
- Commit your changes:
git commit -m "Add new feature"
- Push to the branch:
git push origin feature/my-feature
- Submit a pull request.
This project is licensed under the MIT License.
Have ideas or suggestions? Open an issue or reach out to us at [email protected] & [email protected].
Ensure your applications are served with fairness, reliability, and efficiency with THANOS, the load balancer that wields the power of the five infinity stones.