muruga21 / LoadDistrix

🌐 A lightweight, efficient HTTP load balancer developed in Go
7 stars 7 forks source link
go golang hacktoberfest load-balancer mutex proxy reverse-proxy round-robin semaphore

Load Distrix

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 round-robin algorithm to cycle through the available backend servers, automatically retrying requests on failure and marking unresponsive servers as down.


Features :crystal_ball:

Requirements

Usage

  1. Clone the repository:

    git clone https://github.com/muruga21/LoadDistrix.git
    cd loaddistrix
  2. 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>
  1. 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.

Configuration :mailbox_with_mail:

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: ```json { "backend": [ { "host": "server1", "url": "http://127.0.0.1:8081" }, { "host": "server2", "url": "http://127.0.0.1:8082" } ] ...continue with your backend configuration } ``` ```toml [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 ``` ```yaml backend: - host: "server1" url: "http://127.0.0.1:8081" - host: "server2" url: "http://127.0.0.1:8082" ...continue with your backend configuration ```

:zap: Featured In:

Open Source Programs

Event Logo Event Name Event Description
GSSoC 24 GirlScript Summer of Code 2024 GirlScript Summer of Code is a three-month-long Open Source Program conducted every summer by GirlScript Foundation. It is an initiative to bring more beginners to Open-Source Software Development.

Our Contributors ❤️


Support

Don't forget to leave a star for this project!

Go to Top