PROVIDER - Load testing written in Python

Locust

Locust defines user behaviour in Python, runs distributed tests with 1 master coordinating 100+ workers, charts 4 core metric groups in a built-in UI and simulates thousands of users per machine; the costs are Python skills, limited reporting and script tuning at high concurrency.

Developer Tools Sweden 2026.11.19
4.3pts

Detailed Notes

Pros 5 items

Defines user behaviour in Python so tests are 1 ordinary module that reuses business logic
Supports distributed testing natively, with 1 master coordinating more than 100 workers
Built-in web UI charts 4 core metric groups: latency, throughput, errors and user count
Supports headless mode and custom metric reporting for 2 integration targets: CI and monitoring
A single machine simulates thousands of users with about 1/10 the overhead of process-based tools

Cons 4 items

Python skills are required, raising the barrier for non-engineers
Reporting and charting trail commercial platforms, so trend analysis needs external systems
HTTP dominates protocol support, and other protocols require custom work
High concurrency depends on event loop tuning, and poor scripts distort results

Service Overview

Locust is an open source load testing tool written in Python. Its principle is tests as code: user behaviour lives in a class derived from User, with requests, waits and assertions expressed in code that can be version controlled and reviewed.

In the development tools category it is the developer-friendly load testing option: compared with JMeter's graphical configuration, Locust suits teams that need complex business flows and CI integration.

Key Strengths

  • Code-defined scenarios: scripts reuse business and utility libraries
  • Distributed scale: master-worker topology supports 100+ workers
  • Live UI: 4 core metric groups visible instantly
  • CI friendly: headless runs with custom metric reporting
  • Efficient resources: coroutines simulate thousands of users per host

Product Ecosystem

Platform capabilities

Scenario definition, task weighting, distributed coordination, live statistics, headless execution, custom metrics and event hooks.

Integrations

Works with the Python ecosystem, GitHub Actions, Prometheus, Grafana and Kubernetes deployments.

Typical scenarios

API load tests, capacity assessments, performance regression gates and mixed business flows.

Limitations

  • Programming required: non-technical roles ramp up slowly
  • Reporting limits: long-term trends need external systems
  • Protocol coverage: HTTP first, others require extensions
  • Tuning needs: script quality drives high-concurrency accuracy

Use Cases

  • API and web load tests (★★★★★): code-defined scenarios are most flexible
  • Performance regression gates (★★★★☆): headless mode integrates easily
  • Complex business flows (★★★★☆): multi-step journeys expressible
  • Purely graphical testing (★★★☆☆): JMeter fits better

Pricing

Item Price Notes
Locust itself $0 MIT open source, commercial use allowed
Distributed deployment Self-hosted cost Driven by load generator size and count
Locust Cloud Usage subscription Managed offering billed by test scale

FAQ

Should I choose Locust or JMeter?

Choose Locust when the team knows Python and needs complex scenarios with CI integration; choose JMeter for graphical design and wide protocol support.

How does distributed mode work?

Start 1 master and several workers passing --worker to connect to the master so they generate load together.

Can results reach monitoring systems?

Yes, event hooks push custom metrics to systems such as Prometheus, and Grafana renders them.

How many users fit on one machine?

It depends on scenario complexity and hardware; coroutines usually handle thousands, but validate with real runs.

Code Examples

from locust import HttpUser, task, between

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

    def on_start(self):
        resp = self.client.post("/login", json={"user": "demo", "pass": "demo"})
        self.token = resp.json()["token"]

    @task(3)
    def list_items(self):
        self.client.get("/items", headers={"Authorization": f"Bearer {self.token}"})

    @task(1)
    def create_item(self):
        self.client.post("/items", json={"name": "demo"})
# Headless run with 100 users for 5 minutes
locust -f locustfile.py --headless -u 100 -r 10 -t 5m --host https://api.example.com

Community & Resources

Visit Locust Website → https://locust.io/
Visit Website ↗