Simulating real browser behaviour in performance testing with Locust.io

Shawn Wong
4 min readFeb 5, 2023

Locust is an easy to use, scriptable and scalable performance testing tool. We define the behaviour of the users in regular Python code, instead of being stuck in a UI or restrictive domain specific language. This makes Locust expandable and very developer friendly.

A Locust test is essentially just a Python program making requests to the system you want to test. This makes it very flexible and particularly good at implementing complex user flows.

The very first test

Simply install Python(3.7 or later) then install the package:

pip3 install locust
locust -V

Create a file named as locustfile.py:

from locust import HttpUser, task

class ProfilePageUser(HttpUser):

def on_start(self):
self.client.verify = False

@task
def profile_page(self):
self.client.get("/profilepage")

The methods decorated with @task are the core of our locust file. For every running user, Locust creates a micro-thread that will call those methods.

In the sample code above, the ProfilePageUser will make HTTP requests to /profilepage again and again.

In the same directory run ‘locust’ to start the testing tool. The web interface will be started at http://0.0.0.0:8089 by default.

--

--

Shawn Wong
Shawn Wong

Written by Shawn Wong

Ruby on Rails developer, AWS cloud practitioner, GeoBlacklight, Omeka practitioner.

Responses (2)