An AI-driven load balancing system that uses machine learning to optimize request routing based on server health, request complexity, and predicted response times.
- Go 1.18+
- Python 3.8+ (for ML components)
- ONNX Runtime 1.21.0 (specifically onnxruntime-win-x64-1.21.0 for Windows)
- Docker and Docker Compose (optional for containerized setup)
- Kubernetes (optional for K8s deployment)
- PowerShell (for Windows users running task commands)
Create or modify .env file in the root directory with the following configuration:
# Application Port
PORT=8080
# PostgreSQL Database Credentials
DB_HOST=localhost
DB_SSLMODE=disable
DB_CONTAINER_NAME=neura_db
DB_NAME=neura_balancer
DB_USER=myuser
DB_PASSWORD=mypassword
DB_PORT=5433
# General Backend Config
APP_ENV=development
LOG_LEVEL=info
# Load Balancing Strategy Selection
# Options: least_connections, round_robin, weighted_round_robin, random, ml
LB_STRATEGY=ml
# Server List
SERVERS=http://localhost:5000,http://localhost:5001,http://localhost:5002
# Weights for Weighted Round Robin Strategy
SERVER_5000_WEIGHT=2
SERVER_5001_WEIGHT=1
SERVER_5002_WEIGHT=3
# ML Model Endpoint (used if LB_STRATEGY=ml)
ML_MODEL_ENDPOINT=http://ml-service:8000
go mod downloadpip install -r ml/training/requirements.txt
pip install onnxruntime-win-x64==1.21.0 # For Windows
# For other platforms, use the appropriate ONNX runtime package# Start the entire system (backend servers + load balancer)
task start-all# Start everything including ML components
task start-ml-alltask start-serverstask ml-serve-localtask run-balancer-mltask test-ml-flowThis task will:
- Kill any processes using the required ports
- Start the backend servers
- Start the ML model server
- Run the load balancer with ML strategy
- Test the health endpoints
- Generate load with 100 requests
- Check metrics
All logs are stored in the logs/ directory:
balancer.log- Main load balancer logsbalancer-run.log- Runtime logs for the load balancerbalancer-ml.log- ML-specific logsserver5000.log,server5001.log,server5002.log- Individual server logscleanup.log- Port cleanup logs
- Grafana Dashboard:
http://localhost:3000 - Prometheus Metrics:
http://localhost:9090/targets - Load Balancer Metrics:
http://localhost:8080/metrics
# Build Docker image
task docker-build
# Run in Docker
task docker-run
# Clean up Docker containers
task docker-clean# Deploy to Kubernetes
task k8s-deploy
# Check status
task k8s-status
# View logs
task k8s-logs# Run database migrations
task db-migrate
# Reset database (delete & recreate tables)
task db-reset# Kill all running servers
task kill-servers
# Clean up ports
task kill-ports
# Remove binaries and artifacts
task cleanFor in-depth information about system architecture, component details, and theory behind the ML-based load balancing, please see DOCUMENTATION.md.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/health |
Health check for load balancer |
POST |
/api/route |
Routes request to best server |
GET |
/api/metrics |
Fetches current server stats |
POST |
/api/predict |
Predicts best server based on metrics |
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
Important: Please keep your pull requests small and focused. This will make it easier to review and merge.
If you have a feature request, please open an issue and make sure it is tagged with enhancement.
