I use a VirtualBox VM running Debian 12 as my server machine. The machine is given 6 CPUs and 8GB of memory, along with 20GB of virtual disk space. The load balancer is written Python, using GUnicorn as the server handler. To increase throughput, I implemented a multi-process load balancer, with shared resources and IPC via redis. I use Locust as a load generator, and simulate a maximum of 100 users during the testing phase.
I implement two load balancing algorithms: a simple round robin one and one that looks for the lowest usage container.
This is a very simple algorithm, where requests are cycled through the containers. Generally, given
This algorithm measures the busy-ness of each container using the following busy-ness function:
In this simple algorithm, the scaler considers a sliding window of 50 requests, and starts a new container whenever the average is above a pre-decided maximum average. Once it starts a new container, it lets the system stabilize for 20 seconds before reconsidering starting a new container. This algorithm also shuts down one container for every 30 seconds of server idleness
This algorithm decides the number of containers to start based on the rate of requests received. The
number of containers running at any time is based on the following equation:
To build the container image, run the following command in the terminal
podman image build --tag=worker:latest worker
