The LoadBalancer tool, built in Golang, offers functionality for distributing loads across multiple servers using various strategies.
git clone https://github.com/maniSHarma7575/loadbalancer
# Change directory
cd loadbalancer
Note: Before building you have to make the required configuration file as defined in
You can manage the configuration for the loadbalancer by either json or yaml.
- Create the symlink from the
config.json.sample
orconfig.yaml.sample
cp internal/config/config.json.sample internal/config/config.json
cp internal/config/config.yaml.sample internal/config/config.yaml
# Build
go build
# Run Load balancer
go run main.go
- Change the configuration as per you requirement
Strategy
can have the following values:
round-robin
static
traditional-hash
consistent-hash
You can use loadbalancer utility by running command in your terminal:
- Run the test servers:
#change directory
cd test/httpserver
#build
go build
#run servers
./httpserver
- Build and run the loadbalancer
go run build && ./loadbalancer
- Configuring TLS
# update config.yaml or config.json and replace the cert file and key file
tls_enabled: true
tls_cert_file: "/path/on/container/cert.pem"
tls_key_file: "/path/on/container/key.pem"
- Configuring Content Based Routing (CBR)
# Append to config.yaml
routing:
rules:
- conditions:
- path_prefix: "/api/v1"
method: "GET"
headers:
actions:
route_to: "app2"
# OR
# Append to config.json
"routing": {
"rules": [
{
"conditions": [
{
"path_prefix": "/api/v1",
"method": "GET",
"headers": {
"header": "header_value"
}
}
],
"actions": {
"route_to": "app2"
}
}
]
}
Following Strategy are available:
- Round-Robin
- Static balancing strategy
- Traditional Hash
- Consistent Hash
Thank you for your interest in contributing to our project! We welcome your suggestions, improvements, or contributions. To get started, follow these steps:
Click the "Fork" button on the top-right corner of this repository to create your own copy of the project.
Once you've forked the project, it's a good practice to create a new branch for your changes. This keeps your changes isolated and makes it easier to manage multiple contributions.
git checkout -b your-new-branch