Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ductnn/tinylb
TinyLB is a simple Load Balancer written in Go
https://github.com/ductnn/tinylb
docker golang load-balancer round-robin simple
Last synced: 1 day ago
JSON representation
TinyLB is a simple Load Balancer written in Go
- Host: GitHub
- URL: https://github.com/ductnn/tinylb
- Owner: ductnn
- Created: 2022-10-02T09:14:23.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2022-10-02T17:31:48.000Z (over 2 years ago)
- Last Synced: 2024-06-20T06:39:07.355Z (8 months ago)
- Topics: docker, golang, load-balancer, round-robin, simple
- Language: Go
- Homepage:
- Size: 3.38 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TinyLB
[![Go Report Card](https://goreportcard.com/badge/github.com/ductnn/tinylb)](https://goreportcard.com/report/github.com/ductnn/tinylb)
**TinyLB** is a simple Load Balancer written in Go. Inspired by [simplelb](https://github.com/kasvith/simplelb)
- Use `RoundRobin` algorithm to send requests into set of backends and support retries too.
- `Healthcheck` to recovery for unhealthy servers in every 1 min.## Usage
First, create 3 servers test loadbalancing using [docker-compose-test.yml](docker-compose-test.yml):
```sh
➜ tinylb git:(develop) ✗ docker-compose -f docker-compose-test.yml up -d
Creating network "tinylb_default" with the default driver
Creating tinylb_web2_1 ... done
Creating tinylb_web1_1 ... done
Creating tinylb_web3_1 ... done# Check
➜ tinylb git:(develop) ✗ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
163112a3b548 strm/helloworld-http "/main.sh" 12 seconds ago Up 7 seconds 0.0.0.0:3002->80/tcp, :::3002->80/tcp tinylb_web3_1
d6d1ae94d714 strm/helloworld-http "/main.sh" 12 seconds ago Up 6 seconds 0.0.0.0:3001->80/tcp, :::3001->80/tcp tinylb_web2_1
f717cac76995 strm/helloworld-http "/main.sh" 12 seconds ago Up 5 seconds 0.0.0.0:3000->80/tcp, :::3000->80/tcp tinylb_web1_1
```To add followings as load balanced backends:
- [http://localhost:3000](http://localhost:3000)
- [http://localhost:3001](http://localhost:3001)
- [http://localhost:3002](http://localhost:3002)Then, usage:
```sh
➜ tinylb git:(develop) ✗ go run main.go --backends "http://localhost:3000,http://localhost:3001,http://localhost:3002"
2022/10/03 00:14:12 Configured server: http://localhost:3000
2022/10/03 00:14:12 Configured server: http://localhost:3001
2022/10/03 00:14:12 Configured server: http://localhost:3002
2022/10/03 00:14:12 Started listening on localhost:4000
...
# After 1 min
2022/10/03 00:15:12 Health check starting...
2022/10/03 00:15:12 Health check completed
```Checking on [localhost:4000](http://localhost:4000)
Flag:
```sh
Usage:
-backends string
Load balanced backends, use commas to separate
-port int
Port to serve (default 4000)
```