LinuxCommandLibrary

locust

Load test websites and other systems

TLDR

Load-test "example.com" with web interface using locustfile.py

$ locust --host=[http://example.com]
copy

Use a different test file
$ locust --locustfile=[test_file.py] --host=[http://example.com]
copy

Run test without web interface, spawning 1 user a second until there are 100 users
$ locust --no-web --clients=[100] --hatch-rate=[1] --host=[http://example.com]
copy

Start Locust in master mode
$ locust --master --host=[http://example.com]
copy

Connect Locust slave to master
$ locust --slave --host=[http://example.com]
copy

Connect Locust slave to master on a different machine
$ locust --slave --master-host=[master_hostname] --host=[http://example.com]
copy

SYNOPSIS

locust [options]

PARAMETERS

-f <locustfile>, --locustfile=<locustfile>
    Path to the locustfile containing the test definitions.

--host=<URL>
    Host to load test (e.g., http://www.example.com).

-u <number>, --users=<number>
    Number of concurrent users to simulate.

-r <number>, --hatch-rate=<number>
    Rate at which to spawn users (users per second).

-t <time>, --run-time=<time>
    Stop after the specified amount of time (e.g., 300s, 10m, 1h).

--headless
    Start locust in headless mode (no web UI).

--web-host=<ip address>
    The hostname/IP address to bind the web interface to (default: *).

--web-port=<port>
    The port on which to bind the web interface (default: 8089).

--csv=<prefix>
    Store running stats to CSV files with given prefix.

--version
    Show program's version number and exit.

-h, --help
    Show help message and exit.

DESCRIPTION

Locust is an open-source load testing tool written in Python.

It allows you to define user behavior using Python code, which makes it highly flexible and customizable. Locust simulates multiple users accessing your system concurrently, allowing you to identify performance bottlenecks and measure the scalability of your application or website. It is designed to be distributed, meaning that you can run a single Locust test across multiple machines to simulate a very large number of users. Locust is event-driven, and it uses gevent to simulate concurrent users within a single process. This makes it very efficient, allowing a single machine to simulate thousands of users.

CAVEATS

Locust relies on the availability of the target system. Ensure that the target system is properly configured to handle the simulated load.

WRITING A LOCUSTFILE

The locustfile contains the user classes (subclasses of HttpUser) which define the user behavior. Each user class defines the tasks to be executed by the simulated users.

Example:

from locust import HttpUser, task

class MyUser(HttpUser):
    @task
    def my_task(self):
        self.client.get("/")

HISTORY

Locust was created by Jonatan Heyman and released as open-source software. It was conceived out of the need for a more flexible and scalable load testing tool than those available at the time. The development was driven by the principles of ease of use, Pythonic code, and the ability to simulate a large number of users efficiently. It gained popularity due to its ability to define user behavior using Python code and its distributed capabilities.

SEE ALSO

hey(1), wrk(1)

Copied to clipboard