Locust
  • Why Load Testing ?
  • Locust Installation
  • Understanding Locust Wait Times with Complete Examples
  • Simulating Multiple User Types in Locust
  • Why on_start and on_stop are Essential for Locust Users
  • How to use test_start and test_stop Events in Locust
  • @task decorator
  • task attribute
  • Sequential Task Set
  • HTTP Load Testing with Locust's HttpUser
  • Load Testing with HTTP POST Requests in Locust
  • Using catch_response in Locust for Custom Response Validation
  • Iterative Load Testing with Step Size in Locust
  • Enhancing Your Locust Tests with Custom Logging
  • Running Locust in Distributed Mode with Master and Workers
Powered by GitBook
On this page
  • Prerequisites
  • Step 1: Install Python (If Not Already Installed)
  • Step 2: Create a Virtual Environment (Recommended)
  • Step 3: Install Locust
  • Step 4: Set up a Simple Locust Test

Locust Installation

Locust is a powerful and flexible open-source load testing tool that allows you to test the performance of your web applications and APIs. It's written in Python, making it highly customizable and easy to use.

In this blog, we’ll guide you through the Locust installation process on different operating systems.

Prerequisites

Before we begin, ensure the following:

  • Python: Locust requires Python 3.7 or newer.

  • Pip: Python's package manager, typically bundled with Python installations.

You can verify your Python and pip versions by running

python --version
pip --version

Step 1: Install Python (If Not Already Installed)

For Linux

  • On Ubuntu/Debian:

sudo apt update
sudo apt install python3 python3-pip

For Windows

  1. Run the installer and check the box Add Python to PATH.

  2. Complete the installation.

For macOS

  1. Install Homebrew (if not already installed):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install Python using Homebrew:

brew install python

Step 2: Create a Virtual Environment (Recommended)

Creating a virtual environment helps you manage project dependencies independently

python -m venv locust-env
source locust-env/bin/activate  # On Windows, use `locust-env\Scripts\activate`

Step 3: Install Locust

With pip, installing Locust is straightforward

pip install locust

Verify the installation by checking the version

locust --version

You should see the installed version of Locust.

Step 4: Set up a Simple Locust Test

To confirm Locust is working correctly, create a simple test script (save the below script to a locustfile.py),

# locustfile.py
from locust import User, task, between


class MyUser(User):

    wait_time = between(1, 5)

    @task
    def login_url(self):
        print("I am logging in to the url")

Run Locust,

locust -f locustfile.py

Open your browser and navigate to http://localhost:8089. You’ll see the Locust web interface.

PreviousWhy Load Testing ?NextUnderstanding Locust Wait Times with Complete Examples

Last updated 6 months ago

Download Python from .

python.org