Locust installation and setup


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


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 for the Quick Start tutorial.

  • Create the test file
  • Specify the actions to be taken
import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
  wait_time = between(1, 5)

  def view_items(self):
    # self.client.get(url + "/")

  def hello_world(self):
    # self.client.get(url + "/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
    #"/login", json={"username":"foo", "password":"bar"})

Starting Locust

  • Open a terminal in the directory where the is located.
  • Start Locust with
    locust -f
  • 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 file
  • Start the Locust process with
    locust -f

Leave a comment

Your email address will not be published. Required fields are marked *