load-balancer
A Layer-4 load balancer where you can distribute your workload to different servers.
Run Executable
Download proper binaries according to your OS and architecture. You can download binaries from here. While running executables you need to pass configuration file as command line argument.
Run Project
- You need go v1.18 or higher to run this project. You can download Golang from here.
- Clone or download this repository.
- change directory to
load-balancer/src
- run
go mod tidy
- Create configuration file.
- run
go run main.go -config <config-file-path>
Command Line Arguments
-config <config-file-path>
For passing configuration file. This Argument is mandatory while running binaries/project.-log <log-dir-path>
will set log file directory. This argument is optional, by default it will store logs in current directory.
Configuration
Configuration file must be in JSON format. You can modify load-balancer’s configuration using these fields –
host
It will set load-balancers host. ex"host" : "localhost"
port
It will serve load balancer in this port. ex"port" : "8080"
protocol
It will load balance this protocol. Allowed values arewebsocket
andhttp
. ex"protocol" : "http"
networkType
Only tcp networkType is allowed. ex"networkType" : "tcp"
nodes
It will contain URLs for server which we want to load balance. ex"nodes" : ["localhost:7071"]
Example
config.json
{
"host": "localhost",
"port": "8080",
"protocol": "http",
"networkType": "tcp",
"nodes": [
"localhost:7071"
]
}