This project is designed to provide a simple, fast and easy to configure load balancer. It checks if a server is alive by a simple tcp dial. It forwards the request to the any server among the server list that is available. Since it aims for simplicity, it only supports load balancing based on the server availabilty. It locks the server that is being used to prevent multiple requests to the same server at the same time. It also supports request queuing and retries, using exponential backoff for each retry attempt.
Run the following command in the command line to install voidension
go get github.com/armaanleg3nd/voidensionImport voidension in your code by adding the following package to your imports:
import "github.com/armaanleg3nd/voidension"Create a YAML configuration file and define the following parameters under the app, incoming and outgoing sections:
app:
port: integer # Specify the port number for the application (integer).
dirPath: string # Specify the directory path for the application (string).
receivePath: string # Specify the path where the application will receive the POST requests (string).
checkAvailabilityTimeout: integer # Specify the timeout in milliseconds for checking if the servers are alive (integer).
maxRetries: integer # Specify the maximum number of request retries (integer).
baseBackoffTime: integer # Specify the base backoff time in milliseconds (integer).
largeBodyThreshold: integer # Specify the threshold for large request body size in bytes (integer).
incoming:
allowedIPs: []string # Specify the allowed host IPs in an array of strings. Can be left empty to allow all incoming request IPs.
outgoing:
serverPostURLs: []string # Specify the server POST URLs in an array of strings
One such example config.yaml file is as follows:
app:
port: 3030
dirPath: "./voidension"
receivePath: "/receive"
checkAvailabilityTimeout: 10000
maxRetries: 3
baseBackoffTime: 1000
largeBodyThreshold: 1048576
incoming:
allowedIPs: []
outgoing:
serverPostURLs: ["http://localhost:8080/receive"]Then, load the configuration and launch voidension:
package main
import (
"log"
"os"
"github.com/armaanleg3nd/voidension"
)
func main() {
configData, err := os.ReadFile("config.yaml")
if err != nil {
log.Fatal(err)
}
voidension.LoadConfig(configData) // Load the configuration from file
voidension.Launch()
}