Custom implementation of a load balancer using Go.
Please see the Jupyter notebook for analysis and research.
-
Clone the repository:
git clone https://github.com/TresMichitos/custom-load-balancer.gitOr by downloading as a ZIP file
-
Enter the project directory:
cd custom-load-balancer/
The network is composed of Docker containers and can be spun up using:
docker compose up --build
Shut down containers with:
docker compose down
A script was developed to effectively simulate concurrent requests.
Usage:
go run demo/client/client.go
Flags:
url- Target URL (load balancer).clients- Number of concurrent clients.duration- Duration of test (can be specified using GOs time syntax).rate- Number of requests per second, per client.
Or:
curl http://localhost:8080
Run Unit Tests with:
go test ./internal/...
Run Integration Tests with:
- Start Docker Containers with:
sudo docker compose up - Run Integration Tests with:
go test ./integration/... - Stop Docker Containers with:
sudo docker compose down
- Use algorithm to route HTTP requests between multiple servers
- Make use of Go concurrency features (Goroutines, mutexes, channels etc)
- Host multiple web servers to be routed to via Docker Compose
- Record statistics on effect of load balancer on metrics such as latency, processing load etc
- Setup GitHub workflow testing
- Possibly do health checks on each server
- Possibly experiment with different load balancing algorithms
- A Tour of Go
- What is load balancing?
- Round Robin Load Balancing
- Example Go load balancer
- Docker Example
- How Docker Compose works
- Included in Go standard library:
- net/http
- sync
. # Root
├── .github
│ └── workflows
│ └── tests.yml # GitHub workflow to run unit and integration tests
├── cmd
│ └── custom-load-balancer
│ └── main.go # Entrypoint of custom load balancer
├── demo # Simulate usage of the LB
│ ├── multi-client # Utility for simulating a client making requests
│ │ ├── client # Send client packets
│ │ │ └── client.go
│ │ ├── ipgen # Return a random IP from TEST-NET-3 IPv4 range
│ │ │ └── main.go
│ │ └── main.go
│ └── server # Simple server template
│ └── main.go
├── docker # Contains all files retaining to the docker image and containers
│ ├── Dockerfile.loadbalancer # Builds binary image for main.go
│ └── Dockerfile.server # Builds binary image for server.go
├── integration # Integration tests for custom load balancer
│ └── integration_test.go
├── internal # Package imports
│ ├── config # Utilities to load configuration
│ │ └── config.go
│ ├── dockerstats # Utilities to monitor container stats
│ │ ├── sdk_client.go # Connect to Docker API
│ │ └── stats.go # Checks Dockers utilisation statistics
│ ├── lb-algorithms # Implementations of load balancing algorithms
│ │ ├── ip_hashing.go
│ │ ├── least_connections.go
│ │ ├── least_used_resources.go.go
│ │ ├── random.go
│ │ ├── round_robin.go
│ │ ├── round_robin_test.go
│ │ ├── weighted_round_robin.go
│ │ └── weighted_round_robin_test.go
│ └── server-pool
│ ├── health_check.go # Manage health checks for server pool
│ ├── pool.go # Implementation of server nodes and server pool
│ └── server.go # Implementation of load balancer server struct and definition of LbAlgorithm interface
├── notebooks # Jupyter notebooks
├── .dockerignore # Similar to .gitignore, outlines files for the docker container to ignore
├── .gitattributes
├── .gitignore
├── README.md
├── compose.yml # File used for building the docker containers and describing how they should interact with each other
├── config.yml # Main configuration file for load balancer
├── go.mod # Go module definition (tracks dependencies and package name)
├── go.sum # Go sum definition (logs dependencies downloaded)
└── servers.json # Server list