How locustio/locust works
Locust turns Python user scenarios into concurrent load, then reports request throughput, latency, and failures locally or across workers. The main route is scenario loading and configuration, user/task execution, protocol requests, aggregation, and live UI or exported results. Custom load shapes and non-HTTP clients extend that route. Source excerpts establish the core execution and request path; several UI, reporting, and integration links rely on README statements because their implementation was not sampled.
Main entry points: runners.py Runners · users.py User runtime · env.py Test environment · stats.py Statistics
Components 19
Scenario authoring
- Python scenarios
locust/util/load_locustfile.py - CLI options
locust/argument_parser.py
Load execution
- Tasks and users
locust/user/task.py - User runtime
locust/user/users.py - HTTP client
locust/clients.py
Runtime coordination
- Test environment
locust/env.py - Runners
locust/runners.py - User dispatcher
locust/dispatch.py - Load shapes
locust/shape.py - Worker RPC
locust/rpc/zmqrpc.py - Request events
locust/event.py
Reporting
- Statistics
locust/stats.py - Web backend
locust/web.py - Web interface
locust/webui/src/App.tsx - HTML report
locust/html.py
Protocol extensions
- Fast HTTP
locust/contrib/fasthttp.py - Other protocols
locust/contrib
Other components
- Test operator
- System under test
Connections 26
- Test operator → CLI options: configures run
- CLI options → Python scenarios: selects file
locust/main.py - Python scenarios → Test environment: defines classes
locust/main.py - CLI options → Test environment: configures
locust/main.py - Test environment → Runners: creates
locust/env.py - Runners → User runtime: spawns users
locust/runners.py - User runtime → Tasks and users: runs tasks
locust/user/users.py - User runtime → HTTP client: creates client
locust/user/users.py - Tasks and users → User runtime: defines behavior
locust/user/task.py - HTTP client → System under test: sends requests
- User runtime → Fast HTTP: uses protocol client
locust/contrib/fasthttp.py - Fast HTTP → System under test: sends requests
- Other protocols → System under test: tests protocols
- HTTP client → Request events: fires request events
locust/clients.py - Request events → Statistics: records requests
locust/stats.py - Runners → User dispatcher: distributes users
locust/runners.py - Test environment → Load shapes: attaches shape
locust/env.py - Load shapes → Runners: controls load
locust/shape.py - Runners → Worker RPC: coordinates workers
locust/runners.py - Runners → Statistics: aggregates reports
locust/stats.py - Test operator → Web interface: monitors run
- Web interface → Web backend: requests live data
- Web backend → Test environment: controls test
locust/env.py - Web backend → Statistics: serves statistics
- Statistics → HTML report: supplies results
locust/html.py - Runners → HTML report: writes report
locust/html.py