Skip to main content

Locust Load Testing

Locust is a Python load tester where user behavior is code, scaling via a master-worker model and showing live metrics. It is flexible but higher-overhead and closed-loop by default, so plan workers and tail-latency care.

Locust is an open-source load-testing tool that lets engineers describe user behavior in plain Python. Instead of GUI configuration, you write a script of tasks each simulated user performs. Its event-driven, greenlet-based concurrency model (via gevent) allows thousands of users per process, and its master-worker architecture scales horizontally across many machines, so teams comfortable with Python can express complex behavior without learning a new DSL.

What It Measures

Locust reports requests per second, response-time percentiles, failures per second, and the number of concurrent users. A live web UI shows these metrics updating in real time during a run, with charts for throughput, response times, and errors, which makes it easy to watch a system approach saturation interactively. Results can also be exported to CSV or streamed to monitoring backends. Because behavior is code, Locust can measure any protocol you can script in Python, not just HTTP, by writing a custom client.

Methodology

A Locustfile defines one or more user classes, each with tasks weighted by frequency and wait times between actions to model think time. When started, Locust spawns the requested number of users at a configurable spawn rate, and each user independently executes tasks against the target system. For large loads, a master node coordinates many worker nodes that generate traffic, aggregating their results centrally so the live UI reflects the whole fleet. Tests run interactively through the web UI or headless for CI integration, where exit codes and pass/fail criteria can gate a pipeline.

How to Interpret Results

Read percentile response times and failure rate at the target user count rather than averages. Ramp the user count to find where latency degrades or failures appear, marking system capacity. Verify that worker machines are not CPU-bound, which would cap generated load and silently understate the system under test. Because Locust is closed-model by default (each user waits for a response before continuing), be mindful that it can understate tail latency under saturation compared to open-model arrival-rate tools, so interpret tail numbers near saturation with caution.

Limitations

Locust's per-user overhead is higher than compiled tools like wrk or Gatling, so reaching very high request rates may require many worker machines and careful tuning. Its default closed-loop model can mask coordinated-omission effects on tail latency. It tests at the protocol level and does not render browser client-side code. Writing realistic, well-correlated scenarios takes Python skill and discipline. Use Locust when expressing complex behavior in Python is valuable and horizontal scaling across workers is available, and validate against production traffic patterns.