Load Distrix is a simple HTTP load balancer written in Go. It distributes incoming HTTP requests across multiple backend servers, ensuring high availability and fault tolerance. The load balancer uses a weighted round-robin algorithm to cycle through the available backend servers, automatically retrying requests on failure and marking unresponsive servers as down.
- Round-Robin (weighted) Load Balancing: Distributes requests evenly across backend servers.
- Health Checks: Continuously monitors the status of backend servers.
- Automatic Retry: Retries requests up to three times in case of failure.
- Dynamic Server Pool: Automatically adjusts to backend server availability.
- Go 1.16 or higher
- A configured JSON file named
LoadDistrix.config.json
with backend server details.
-
Clone the repository:
git clone https://github.com/muruga21/LoadDistrix.git cd loaddistrix
-
Prepare the configuration file:
write loadbalancer config file in the root directory with the following structure:
{ "backend": [ { "host": "server1", "url": "http://127.0.0.1:8081" }, { "host": "server2", "url": "http://127.0.0.1:8082" } ] ...continue with your backend configuration }
[backend] host="server1" url="http://127.0.0.1:8081" [backend] host="server2" url="http://127.0.0.1:8082" ... continue with your backend configuration
backend:
-
host: "server1" url: "http://127.0.0.1:8081"
-
host: "server2" url: "http://127.0.0.1:8082"
...continue with your backend configuration
3. Build and run the load balancer:
```sh
go build -o loaddistrix main.go
./loaddistrix <config-file>
- The load balancer will start on port 8000. You can now send HTTP requests to
http://localhost:8000
, and they will be distributed across your configured backend servers.
To configure loadbalancer, write a configuration file with your choice of file extension. Each backend server should be specified with its host
and url
.
Example:
{
"backend": [
{
"host": "server1",
"url": "http://127.0.0.1:8081"
},
{
"host": "server2",
"url": "http://127.0.0.1:8082"
}
]
...continue with your backend configuration
}
[backend]
host="server1"
url="http://127.0.0.1:8081"
[backend]
host="server2"
url="http://127.0.0.1:8082"
... continue with your backend configuration
backend:
- host: "server1"
url: "http://127.0.0.1:8081"
- host: "server2"
url: "http://127.0.0.1:8082"
...continue with your backend configuration