voidension

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 16 Imported by: 0

README


voidension

A fast, simple and easy to configure Load Balancer


About Voidension

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.

Instructions for Setup

1. Install

Run the following command in the command line to install voidension

go get github.com/armaanleg3nd/voidension

2. Import voidension

Import voidension in your code by adding the following package to your imports:

import "github.com/armaanleg3nd/voidension"

3. Configure and Launch

Create a YAML configuration file and define the following parameters under the app, incoming and outgoing sections:

app Parameters
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 Parameters
incoming:
  allowedIPs: []string               # Specify the allowed host IPs in an array of strings. Can be left empty to allow all incoming request IPs.

outgoing Parameters
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()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Launch

func Launch()

Launch initializes and starts the Voidension load balancer with the given configuration. It configures the directory, loggers, server pool, and starts the HTTP server. It also starts a goroutine to periodically check the availability of the servers and logs statistics about the load balancer every 10 seconds.

func LoadConfig

func LoadConfig(configData []byte)

takes a YAML byte slice and loads it into the configStruct, and it is then stored in the package global variable configInstance.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL