Just to train some skills in writing applications using Go.
This load balancer uses RoundRobin algorithm to send requests into set of backends. It supports attempts and retries.
It also performs active cleaning and passive recovery for unhealthy backends.
Usage:
-backends string
Load backends to balance wich, use commas to separate
-port int
Port to serve (default 3030)
Example:
To add followings as load balanced backends
We use
./lb --backends=http://localhost:3031,http://localhost:3032,http://localhost:3033,http://localhost:3034
strm/helloworld-http
- is a simple 'Hello world' in an HTTP server to be used to test load balancers. When receive an request (GET /) this image will return the current machine hostname.
- docker-compose up
- HTTP proxying
- Removing backends if they are down
- RoundRobin backend resolver
- "Tolerant policy" for non-200 return code
- Retries if backend didn't answer
- Attempts if another backend picked for current request
- HealthCheck for backends to check if they're alive and modify their statuses
- Showed using of goroutines (health check running in different Go thread), atomic package, mutexes, channels (used for timers, no too smart but anyway)
- Dockerized application (multi-stage build)
- more tests with more sense
- measure of performance
- Even cleaner code (if I got at least one code review)
- Grafana & Prometheus metrics