Installation
To install Locust, follow the instructions at Locust Installation
- Create a directory for the Locust project
- Create a subdirectory for the source code
- Create a new Anaconda virtual Python environment. ( At the time of writing Python version 3.10 is the latest. )
conda create -n locust python=3.10
- Activate the new virtual environment
conda activate locust
- Install Locust
pip3 install locust
- Check the success of the installation
locust -V
Troubleshooting
If the check fails with the error message
ValueError: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 152 from C header, got 40 from PyObject
Make sure you use the Anaconda virtual Python environment to avoid version conflicts between installed Python components.
Create your first test
See https://docs.locust.io/en/stable/quickstart.html for the Quick Start tutorial.
- Create the test file
locustfile.py
- Specify the actions to be taken
import time
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(1, 5)
@task(3)
def view_items(self):
# self.client.get(url + "/")
self.client.get("/")
@task
def hello_world(self):
# self.client.get(url + "/about")
self.client.get("/about")
def on_start(self):
a = 0 # Just a placeholder, as every def has to have at least one executable instruction
# No login is necessary for this site
# self.client.post("/login", json={"username":"foo", "password":"bar"})
Starting Locust
- Open a terminal in the directory where the
locustfile.py
is located. - Start Locust with
locust -f locustfile.py
- Open the web UI at http://localhost:8089/
- Specify the number of concurrent users and the span rate of the users. Enter the URL of the site to be tested. IMPORTANT: Make sure there is no slash at the end of the URL, otherwise the generated URL will contain double slashes!!!
- Click the Start swarming button.
Changing the load test script
To make sure, Locust will execute the updated script
- Stop the Locust process in the terminal with CTRL-C
- Modify and save the
locustfile.py
file - Start the Locust process with
locust -f locustfile.py