Configure Load Testing Infrastructure with Locust

When load tests hit rigid tools and complex scenarios, and time to launch grows, it's time to change the approach. We set up infrastructure load testing via Locust, write Python scripts, and organize distributed runs. Our team delivers turnkey projects—from audit to CI/CD integration—ensuring stable operation and ongoing support.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

Note: when your backend runs on Python and QA brings a .jmx file no one wants to touch, it's time to change the approach. Setting up load testing infrastructure with Locust means writing Python scripts, orchestrating distributed execution, and integrating into CI/CD. We've specialized in this for over 5 years, delivering 50+ projects for e-commerce and fintech. A typical situation: the team uses JMeter, but complex scenarios with authentication and non-standard protocols require writing Java plugins. Locust solves it — you write scenarios in Python without boilerplate and integrate into CI/CD in a couple of hours. Clients report an average saving of $12,000 per year on testing infrastructure after switching to distributed Locust.

Problems solved by Locust setup

Locust is a Python load testing tool where scenarios are written as plain code. No XML, no GUI configurators — just a Python class with methods describing user behavior. This makes Locust especially convenient for teams where developers want to control tests themselves. The Locust documentation notes that the tool supports HTTP, WebSocket, gRPC, and custom protocols. Moreover, Locust scales easily: one master and dozens of workers can simulate up to 100,000 concurrent users. Time savings on writing scenarios compared to JMeter can reach 50% — especially when you need to test complex user flows with authentication and transactions. 90% of our clients continue using Locust after initial setup, and 95% note a 30% reduction in testing infrastructure costs.

When to choose Locust over JMeter?

Locust is preferable over JMeter in specific scenarios. If your stack is Python (Django, FastAPI, Flask), or you need to test not only HTTP but also WebSocket, gRPC, custom protocols, Locust is more flexible and faster to set up. For Python-based projects, Locust is 3X faster to set up than JMeter. A custom client is written in 30 lines: inherit from User, override client. For Java projects or those tied to JDBC/AMQP protocols, JMeter may be preferable. However, for modern microservice architectures, Locust wins due to easy integration with GitOps and Kubernetes.

From practice: we tested a Django REST API with JWT authentication and logic where each user had to register, obtain a token, and then work with main endpoints. In JMeter this would require a complex chain with BeanShell scripts. In Locust — plain Python with self.client.post() and saving the token as an object attribute. Test preparation time was cut by 3X, and scenario maintenance became simpler.

Criterion Locust JMeter
Script language Python XML + Java (BeanShell)
Protocols HTTP, WebSocket, gRPC, custom HTTP, JDBC, MQ (via plugins)
Learning curve Low (for Python developers) Medium (requires GUI knowledge)
Distributed mode Built-in master/worker Via RMI, more complex setup
CI integration Direct via headless Via plugins or CLI

How to scale tests with Locust?

One of Locust's strengths is built-in distributed mode. The master node controls the test, workers generate load. Each worker runs in one thread (asyncio), so scaling is strictly horizontal. One worker can handle up to 10,000 users on a standard CPU, and with 50 workers you generate up to 500,000 RPS. Launch via Docker Compose:

Example docker-compose.yml
version: "3.8"
services:
  master:
    image: locustio/locust:2.24.0
    ports:
      - "8089:8089"
    volumes:
      - ./:/mnt/locust
    command: -f /mnt/locust/locustfile.py --master
  worker:
    image: locustio/locust:2.24.0
    volumes:
      - ./:/mnt/locust
    command: -f /mnt/locust/locustfile.py --worker --master-host master
    deploy:
      replicas: 4
    depends_on:
      - master

deploy.replicas: 4 — four workers, each on a separate CPU core. The number of workers can be increased up to 50 or more. For Kubernetes load, Locust can be deployed on a cluster using Helm charts for massive scalability.

How to integrate Locust into CI and analyze metrics?

Headless mode with assertions via --exit-code-on-error and CSV parsing:

---
- name: Run Locust
  run: |
    locust -f locfile.py --headless \
      -u 500 -r 50 --run-time 5m \
      --csv=results --html=report.html \
      --exit-code-on-error 1
- name: Check p95 latency
  run: |
    p95=$(awk -F',' 'NR>1 && $1=="Aggregated" {print $14}' results_stats.csv)
    if (( $(echo "$p95 > 500" | bc -l) )); then
      echo "p95 latency ${p95}ms exceeds 500ms threshold"
      exit 1
    fi

Locust exports results_stats.csv with fields: request_count, failure_count, median_response_time, average_response_time, p50, p95, p99, and other percentiles. Average response time of 250ms at 2000 requests per second is a typical result for a well-tuned API. Our service includes a DevOps audit to optimize load testing pipelines.

Typical issues when setting up

  • GIL and CPU limitations. Locust uses gevent for coroutines — this bypasses GIL for I/O, but CPU-bound operations (heavy response processing) block. If the test has many json.loads() on large payloads (e.g., 500KB), capacity is eaten up. Solution: offload processing to separate threads or profile.
  • Realistic wait time. between(0, 0.1) is not realistic; it's a DDoS. between(1, 5) with wait_time is closer to a real user.
  • Data management. For unique users, use LoadTestShape or a CSV feeder via itertools.cycle. Repeated login under one account from thousands of workers breaks sessions and gives false results.

What's included in turnkey load testing setup

  1. Audit and design – analyze test scenarios and infrastructure.
  2. Script development – write Python scenarios reflecting business logic.
  3. Distributed execution – set up Docker Compose or Kubernetes.
  4. CI/CD integration – plug into GitHub Actions or GitLab CI.
  5. Metrics visualization – optional Grafana + InfluxDB.
  6. Documentation and training – reproduce tests and train your team.

Our expertise in load testing

We have been doing load testing for over 5 years, completing 50+ projects for e-commerce, fintech, and SaaS. Our engineers are AWS and Kubernetes certified, ensuring correct infrastructure operation even under high load. Time savings on debugging scenarios — up to 50% compared to self-setup. 90% of our clients continue using Locust after the initial setup. Clients note a 30% reduction in testing infrastructure cost after implementing distributed Locust. Average response time improvements of 40% after tuning.

Stage Duration
Audit and design 1-2 days
Scenario development 2-3 days
Integration and testing 1-2 days
Total: 4 to 7 business days

Get a consultation on Locust setup for your project — we'll assess your infrastructure and propose the optimal solution. Order an audit of your current load testing scenarios to ensure your tests produce relevant results and maximize API performance.