DEV Community

Cover image for Locust: An open source load testing tool.

Posted on

Locust: An open source load testing tool.


Locust is an easy-to-use, distributed, user load testing tool. It is intended for load-testing web sites (or other systems) and figuring out how many concurrent users a system can handle.

Define user behaviour with Python code, and swarm your system with millions of simultaneous users.


Open terminal (assuming you have python installed, pip is also installed)

pip install locustio

Hello world

Create a in your favorite text editor. This is our first test, request both home-page (/) and about-page (/about/).

from locust import HttpLocust, TaskSet, task, between

class WebsiteTasks(TaskSet):

    def index(self):

    def about(self):

class WebsiteUser(HttpLocust):
    task_set = WebsiteTasks
    wait_time = between(5, 15)
Enter fullscreen mode Exit fullscreen mode

Yeah. Our test is ready. But, where do test ?

Let's create a simple django project with few seconds (It depends on your typing/copy-paste speed 😄).

Create test application

Install django
pip install Django==2.2.10

Create Django project (if you care copy-pasting, Don't forget to copy dot [.] at end of the command)
mkdir djangotarget && cd djangotarget && django-admin startproject config .

Create a Django app
python startapp app1

Now, add following code to app1/

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def index(request):
    return HttpResponse('hi')

def about(request):
    return HttpResponse('about')
Enter fullscreen mode Exit fullscreen mode

Now add app1 into INSTALLED_APPS. So edit, config/ in your text editor. And replace INSTALLED_APPS variable like below.


    # You are adding this line only --->
    # You are adding this line only <---
Enter fullscreen mode Exit fullscreen mode

Now, add urls to app1. Create app1/ file and past the following content.

from django.urls import path
from app1 import views

app_label = 'app1'
urlpatterns = [
Enter fullscreen mode Exit fullscreen mode

Start the site to be tested (ie. run our django project). In the terminal, run following command

python runserver

Now you will be able to see, some thing like this.

Django version 2.2.10, using settings 'config.settings'
Starting development server at
Quit the server with CONTROL-C.
Enter fullscreen mode Exit fullscreen mode

You can browse the our dummy under test at any of the following urls:

Now let's load test it 🐍

Open another terminal, and run

locust -f

For above command, you will see an output like this.

[2020-03-16 22:59:11,146] your-username/INFO/locust.main: Starting web monitor at http://*:8089
[2020-03-16 22:59:11,146] your-username/INFO/locust.main: Starting Locust 0.14.5
Enter fullscreen mode Exit fullscreen mode

As you can see (from above output), it's available at port 8089 (ie. http://*:8089).


You will be shown a webpage with few inputs like below. Fill as I filled.

Number of total users to simulate: 5
Hatch rate (users spawned/second): 1
Host: http://localhost:8000
Enter fullscreen mode Exit fullscreen mode

Click that start button !!! Kidding, button is named Start Swamming.

You are always, welcome to tweak any values above. For that you can stop button, and start with new test link.


Locust is an easy-to-use load testing tool.

Want more ? Visit

Top comments (0)