A demo project for load testing with locust
It consists of two parts:
- app001, a naive Flask app that is going to be tested
- The actual test-suite in implemented in locust
Create a virtual environment and activate it
python3 -m venv .venv
source .venv/bin/activate
Install the dependencies
pip3 install -r requirements.txt
In Terminal run this if you use Linux or adjust the commands according the Flask quickstart
cd app001
export FLASK_APP=hello
flask run
Go to localhost:5000
in your browser and see that it works.
While the Flask app is still running, open a new shell tab, activate the virtual environment and run the test:
source .venv/bin/activate
locust --host http://localhost:5000
If you want to dig deeper into how locustfile.py
is built, check the locust documentation
Go to localhost:8089
in your browser and start testing.
You can also start a headless test:
locust --host http://localhost:5000 --headless --users 10 --spawn-rate 0.5 --run-time 1m
Next, let's try it with a heavier load. This will use another endpoint that randomly waits from 1ms to 10s.
locust --locustfile locustfile-heavier.py --modern-ui --host http://localhost:5000 --users 10 --spawn-rate 1
What is the limit?
With 1000 users and 100 RPS it still works.
locust --locustfile locustfile-heavier.py --modern-ui --host http://localhost:5000 --users 1000 --spawn-rate 100