The Locust is an alternate tool to the JMeter. Locust allow you to write load tests in python, this tutorial describes how from scratch make a simple load testing and see results. Let’s do the following steps:
- Install python on your system.
- Install Pip (package manager).
- Install Locust: pip install locust.
- Simple locust script.
- The simple script as the Hello World I’ve added to Github and you can utilize it.
- Download the scripts and put is to any folder, let’s say under the C:\LocustScript
- You should see the next files:
- locust.py (required file).
- loadtesting.sh (this one is optional).
- Run script: you can already execute the loadttesting.sh and see the next console window:

Please pay attention to the output url: http://0.0.0.0:8089, please adjust the address to the next: http://localhost:8089, (as the IP-format may not work) and paste to the browser, you should see the next:

The UI shows the next properties:
- Number of total users to simulate.
- Spawn rate (users spawned per second).
- Host – the website which you going to stress under load testing.
The properties already filled because the loadtesting.sh already have these predefined data:
locust -f locust.py --host https://google.com --users 100 --spawn-rate 20
Let’s change the host to your own, in my case I’ll use the https://ivanbrygar.com and press the Start swarming button.

If you click to the Charts button, you’ll see a few detailed charts:



Eventually it doesn’t have any failures or exceptions:
Based on the result the performance for this example is good.
You may be curious how to do the load testing not only to the front page, but also for another ones, that’s the main thing actually, all the core logic is in the locust.py file:
import time
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
# random time between 1 and 3 seconds
waitTime = between(1, 3)
@task
def index_page(self):
self.client.get(url='/#home')
@task
def index_page(self):
self.client.get(url='/#about')
You can add one or another @task, which on the python will have some specific logic, here is the simplest implementation where defined different relative paths, adjust the script by your needs. To learn more you can reference to the official documentation: https://docs.locust.io/en/stable/quickstart.html


One thought on “Locust as a modern load testing framework”