Locust Load Testing vs a Recorded Flow

Locust load testing compared on scripting, scale and CI, plus when a recorded API flow replaces a locustfile and when it does not.

Mustafa BayramogluMustafa BayramogluMany parallel paths converging on one highlighted route

Pick Locust when the team writes Python and wants load tests that behave like application code, with loops, conditions and calculations, kept under version control like regular code. Pick k6 when the team writes JavaScript. A third case applies when the load you need is a real user flow against an HTTP API: a flow recorded from real use can also run as a load test. The sections below compare Locust with k6, cost out a locustfile and mark where a recorded flow stops being enough.

What Locust is and how a test is written

Load testing puts simulated users on a system and watches latency and errors; the practical guide to load testing APIs covers the vocabulary used below. A Locust test is essentially just a Python program making requests to the system you want to test. You put the code in a file named locustfile.py and run locust.

Because the scenario is plain Python, the usual constructs apply. If you want users to loop, perform conditional behavior or do calculations, you use the regular programming constructs provided by Python. The Locust documentation adds that you can use your regular IDE and version control your tests as regular code. Inside a task, code is executed sequentially, as ordinary Python.

Where Locust is the better choice

Locust’s first strength is custom behavior. A test is a program, so a scenario can loop, branch on a condition and compute values. The quickstart says this makes Locust very flexible and particularly good at implementing complex user flows.

The second strength is reach. Locust only comes with built-in support for HTTP/HTTPS, but it can be extended to test almost any system, usually by wrapping the protocol library and triggering a request event after each call. Locust also allows pytest syntax to define its users, and for AI services the documentation suggests the OpenAI SDK as a convenient client.

The third strength is scale. Locust is event-based (using gevent), which makes it possible for a single process to handle many thousands of concurrent users. For a simple test plan and small payloads, one process can make more than a thousand requests per second, possibly over ten thousand with FastHttpUser. Beyond one process, per the distributed mode docs, you start one instance with the --master flag and workers with --worker: the master runs the web interface and tells the workers when to spawn and stop users, and the workers run the users and send statistics back.

The documentation is candid about the limit. Other tools may be capable of more requests per second on a given piece of hardware, while the low overhead of each Locust user makes it very suitable for highly concurrent workloads. For a team that already writes Python, none of this requires a new language.

Locust and k6 side by side

Both tools treat tests as code. DevOpsBoys describes Locust as Python-scripted and code-first like k6, with a simple built-in distributed mode, and a BRF blog post says the real difference between the two is not speed but the concurrency model, distributed execution and CI integration. The table sticks to what each tool’s own documentation states.

Criterion Locust k6
How a test is written A Python program A JavaScript file
Scaling out Master and workers k6 Operator runs distributed tests in a Kubernetes cluster
Pass or fail in CI Exit code 1 on failed samples, scriptable Thresholds fail the run
Running in CI Headless flag Integrates with CI/CD and automation tools
License MIT Open source

The table leaves out speed and memory on purpose. The sources used here give no figures that can be compared fairly, so none are repeated. The k6 vs JMeter comparison covers the other half of this choice from the k6 side.

What a locustfile costs to keep

A locustfile is a program, so it has the upkeep of one. Each task runs its requests one after another, as written. When the API renames an endpoint or adds a required field, the file needs an edit, the same as any code that calls that API.

In CI, Locust runs without the web UI. The --headless flag is used together with -u/--users and -r/--spawn-rate. By default the process gives an exit code of 1 if there were any failed samples, and you can control the exit code from your own test scripts, which the documentation calls particularly useful for a CI pipeline. Pass and fail rules beyond failed requests are code you write and keep.

The documentation index also lists a way to automatically translate a browser recording (HAR-file) to a locustfile. That saves typing the first version. The output is still a script, and it still needs the edit when the API changes.

When a recorded flow replaces the script

Plain disclosure: Stresseur publishes this page, and Stresseur is the third option here.

Stresseur records how an API is really used during development and turns those flows into YAML tests, and any recorded flow can also run as a load test. The flow lives in the repository under api-tests/, and the load profile in api-tests/stresseur.load.yaml. Locally, npx stresseur flow run runs a flow or a load scenario. In the cloud, load generators start in the regions you pick (Frankfurt, Virginia, San Jose, Singapore) and stream results live: virtual users, req/s, p95, errors and per-step latency. Profiles support ramping VUs, constant and ramping arrival rate, thresholds and abort rules. Recording also covers page loads and form posts, so apps that build their pages on the server work too. The load testing page shows the product side.

A recorded flow is enough when the load you want is the traffic your API already sees: log in, list, order. The load test reuses a flow the team already has, so there is no second script to keep in step with the API. The guide to virtual users and throughput helps size the first run.

The limits are real. The Free plan runs load tests up to 50 VUs for 10 minutes in one region. Team goes up to 1,000 VUs for 1 hour in all regions. Load goes only to domains the workspace has verified. Scheduled soak tests are not available.

Stay with Locust when the test needs custom behavior in code, a protocol beyond HTTP, or load generators you run yourself. A recorded flow replays traffic the API has already seen; it does not invent scenarios nobody has run.

Choose Locust for custom behavior written in Python and for protocols beyond HTTP, k6 for JavaScript tests with thresholds that fail the run, and a recorded flow when the API’s real traffic is the load you want and no one wants a second script to maintain. Run a small test first with whichever you pick, and check the result against what the API handles in production.

Frequently asked questions

Is Locust free?

Yes. Locust is open source under the MIT license.

Do you need the web UI to run Locust?

No. The web UI is optional: you can supply the load parameters on the command line and get reports in text form. The --headless flag is used together with -u/--users and -r/--spawn-rate.

Can Locust load test something other than HTTP?

Yes, with extra work. Locust only comes with built-in support for HTTP/HTTPS, and it can be extended to test almost any system by wrapping the protocol library and triggering a request event after each call.

Can Locust fail a CI build?

Yes. By default the locust process gives an exit code of 1 if there were any failed samples, and a test script can set the exit code itself.

Can I load test an API without writing a script?

With Stresseur, yes: any recorded flow can also run as a load test. The Free plan allows up to 50 VUs for 10 minutes in one region.

All posts