Logo
OpenScaler

Load Balancer Sample App

Load Balancer Sample App is a simple application that helps you test your load balancer, it can be simply deployed on OpenScaler Platform in just a few steps.

Load Balancer Demo

Quickstart

Create Computer with Boot Script

Create a new computer and use the following script as boot script (under "advanced options").

#!/bin/bash
apt update && apt install python3-flask python3-psutil tmux unzip -y
cd /root/
# git clone --depth 1 https://github.com/OpenScalerEngineeringTeam/load-balancer-demo.git
wget https://github.com/OpenScalerEngineeringTeam/load-balancer-demo/archive/refs/tags/v0.0.1.zip -O load-balancer-demo.zip
unzip load-balancer-demo.zip && rm load-balancer-demo.zip
cd load-balancer-demo-0.0.1
tmux new-session -d 'export FLASK_APP=load-balancer-demo.py; flask run --host=0.0.0.0 --port=8080'

This script will install a simple Flask application on the computer, and make it available on port 8080.

Load Balancer Demo - Computer Script

Note

If you want to install it on an existing computer, follow this guide instead.

Create Load Balancer

Create a new Load Balancer

Add Backend

Add a new backend to the Load Balancer and link it to the computers you created previously.

  • use port 8080 for your backend
Optional

You can configure health check for your backend

  • use the /health endpoint (and keep everything else default; e.g. status code 200 etc.)
  • this is optional, but it's a good practice to ensure your backend is healthy
  • you can also test sticky session and check that it always routes to the same server

Configure Frontend

Create a new frontend and select the backend created previously as "default backend"

Add a bind to any port you want (e.g. 80), then click "Submit" (or "Apply Changes" if in edit mode).

Test Your App

Click on the address next to your port and you should see the demo app running.

Load Balancer Demo - Click on the address

Tip

Try refreshing the page a few times to see the load balancer in action.

Test Application Locally

To test the application locally

  • On Linux:
#!/bin/bash
git clone --depth 1 https://github.com/OpenScalerEngineeringTeam/load-balancer-demo.git
cd load-balancer-demo
apt install python3-flask python3-psutil -y
export FLASK_APP=load-balancer-demo.py
flask run --host=0.0.0.0 --port=8080

You can now access your application at http://localhost:8080

On this page