Headless
locust --headless -u <n> -r <rate> -t
<time>
Fixed run without UI
-t takes 90, 90s, 20m or 1h30m. The timer starts at the
beginning of the test, not after ramp-up.
-u / --users <n>
Peak number of simulated users
-r / --spawn-rate <n>
Users started per second
-t / --run-time <time>
Stop after this long
-s / --stop-timeout <time>
Let running tasks finish on shutdown
--exit-code-on-error <code>
Exit code when requests failed
By default Locust exits with 1 if any request failed.
--reset-stats
Clear stats after ramp-up ends
In distributed mode set it on master and workers.
--json
Print final stats as JSON
--json-file <prefix>
Write JSON stats to a file
Distributed
locust --master
Start the master (no users run on it)
locust --worker
Start a worker, master on localhost
locust --worker --master-host <host>
Point a worker at a remote master
--master-bind-port <port>
Port the master listens on (5557)
--expect-workers <n>
Headless master waits for n workers
locust --processes <n>
Fork master plus n workers locally
Uses fork(), so not on Windows. -1 means one per logical core.
locust --worker --processes <n>
Fork only n workers on this machine
Locustfile
Minimal HttpUser
from locust import HttpUser, task, betweenclass ShopUser(HttpUser): wait_time = between(1, 5) @task(3) def home(self): self.client.get("/") @task def item(self): self.client.get("/item/1")
@task(<weight>)
Pick this task proportionally more often
wait_time = between(<a>, <b>)
Random pause after each task
wait_time = constant(<s>)
Fixed pause after each task
wait_time = constant_pacing(<s>)
Run a task at most once per interval
def on_start(self):
Per-user setup such as login
self.client.get(<path>, name=<label>)
Group dynamic URLs in the stats
self.client.post(<path>, json=<obj>)
POST a JSON body
catch_response=True
Decide pass/fail from the response
@tag(<name>)
Label a task for --tags filtering
-T <tag> / -E <tag>
Include / exclude tagged tasks
Exclusion wins when both match.
class <Name>(FastHttpUser)
Faster HTTP client for heavy load
class <Name>(TaskSet)
Group tasks into a nested flow
abstract = True
Mark a base class that is not run
@events.test_start.add_listener
Hook code in at test start
class <Name>(LoadTestShape)
Script the user curve over time
tick() returns (users, spawn_rate), or None to stop.