ConfigsApr 12, 2026·1 min read

Locust — Scalable Load Testing in Pure Python

Locust is an open-source load testing tool where you define user behavior in plain Python code. Distributed, scalable, and with a real-time web UI for monitoring. No DSL to learn — just write Python.

AI
AI Open Source · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

pip install locust
# locustfile.py
from locust import HttpUser, task, between

class TokrepoUser(HttpUser):
    wait_time = between(1, 3)
    host = "https://api.tokrepo.com"

    @task(3)
    def list_assets(self):
        self.client.get("/api/assets")

    @task(1)
    def view_asset(self):
        self.client.get("/api/assets/1")

    def on_start(self):
        # Login or setup
        pass
locust                       # Web UI at http://localhost:8089
locust --headless -u 100 -r 10 -t 5m --csv=results
locust --master              # Distributed: master
locust --worker --master-host=master-ip  # Workers
Intro

Locust is an open-source load testing tool where you define user behavior in plain Python code. No XML, no DSL — just Python classes and decorators. Features a real-time web UI, distributed testing across multiple machines, and easy CI/CD integration.

What Locust Does

  • Python test scripts — define user behavior as classes
  • Web UI — real-time charts, start/stop, user count control
  • Distributed — master + workers for massive scale
  • Headless mode — for CI/CD
  • CSV/JSON output — export results
  • Custom clients — test gRPC, WebSocket, MQTT, databases
  • Events — hook into test lifecycle
  • Task weighting@task(weight) for traffic distribution

Comparison

Tool Language UI Distributed
Locust Python Web UI Master/worker
k6 JavaScript CLI k6-operator
JMeter Java/GUI Desktop Servers
Vegeta Go CLI No
wrk C CLI No

常见问题 FAQ

Q: 能测多少并发? A: 单机几千用户(gevent 协程),分布式可以轻松到数万。不如 k6 单机效率但 Python 写脚本更灵活。

Q: 和 k6 比? A: Locust 写 Python(更灵活、可以直接调用任何 Python 库),k6 写 JS(Go 运行时更高效)。看团队语言偏好。

来源与致谢 Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets