Skip to main content

k6 vs Locust: The Same Test Run in Both Tools

k6 vs Locust, tested: at 2,000 users k6 sent 5,344 requests a second from one process, while one Locust process reached 2,990 and its own p50 rose to 260 ms.

k6 vs Locust: The Same Test Run in Both Tools

k6 vs Locust is mostly a choice of language and of how much load one machine has to produce. k6 runs JavaScript or TypeScript test scripts in a single Go binary that uses every CPU core. Locust runs Python test code, and each Locust process uses one core, so heavy tests need several processes. Both are free, open source and built for tests written as code.

To compare them on more than feature lists, we ran the same tests in k6 v2.4.0 and Locust 2.47.0 against one local API. At 200 users they reported nearly the same throughput. At 2,000 users, k6 kept up from one process; one Locust process could not, and the slowdown showed up in its own response times. Four Locust processes closed the gap.

Key Takeaways

  • Pick by language first. Python teams get plain Python with every library they already use in Locust; JavaScript and TypeScript teams get k6.
  • On a 200-user test both tools sent about 535 requests a second with no errors. Locust’s default HTTP client added a few milliseconds to each measured response time.
  • One k6 process uses all CPU cores. One Locust process uses one: at 2,000 users it delivered 2,990 of the 5,400 requests a second the test called for, and reported a 260 ms median for a server answering in about 25 ms or less.
  • Locust fails a CI run on any failed request by default. k6 exits with code 0 unless you define thresholds, then exits with code 99 when one fails.
  • k6 has arrival-rate executors that keep sending when the server slows down; Locust’s users wait for each response. LoadFocus runs k6 scripts in the cloud, not locustfiles.

k6 vs Locust at a glance

k6 v2.4.0Locust 2.47.0
LicenceAGPL-3.0, freeMIT, free
Tests written inJavaScript or TypeScriptPython (a locustfile)
RuntimeOne Go binary; each virtual user has its own JavaScript runtimegevent greenlets; one process uses one CPU core
InstallDownload one binarypip install locust, Python 3.11 or later
Built-in protocolsHTTP/1.1, HTTP/2, WebSocket, gRPC, real browserHTTP; contrib users for MQTT, Socket.IO, MongoDB, PostgreSQL, DNS; anything else through your own Python client
Load modelsClosed (VUs) and open (arrival-rate) executorsUsers and spawn rate (closed), pacing per user, custom shapes in Python
Pass or fail in CIThresholds, exit code 99 on failureExit code 1 on any failed request, or your own rule in Python
Live viewTerminal progress, optional web dashboardWeb UI on port 8089
Distributed loadk6 Operator on Kubernetes, or Grafana Cloud k6 (free tier, then usage-based)Free master and workers; --processes on one machine

Versions, licences and requirements are from each project’s release pages, documentation and the installed packages as of November 2026.

What is the main difference between k6 and Locust?

The language, and the way each tool turns a script into load. A k6 script is a JavaScript module whose default function runs once per iteration for every virtual user, inside a Go program that spreads those users over all CPU cores. A Locust test is a Python class: each user is a greenlet, a lightweight coroutine, and every user in a process shares one Python interpreter.

That shapes everything else. k6 scripts cannot import Python or Node.js packages, only JavaScript modules k6 understands and its own extensions. A locustfile can import anything on PyPI, which matters when a test needs a database driver, a message queue client or a signing library your service already uses in Python. In return, k6 gets more requests out of one process, and Locust needs to be told to start more processes.

How do the scripts compare?

Both scripts are about the same length and describe the same journey; they differ in where the configuration lives and in how per-user state is kept. Our test logs in once per user, keeps the token, then loops three requests: the product list, one product (which takes 25 ms on the server), and an add-to-cart call that sends the token, with one second of think time. In k6:

import http from 'k6/http';
import { check, sleep } from 'k6';

let token; // module scope: each VU has its own copy

export const options = {
  stages: [{ duration: '10s', target: 200 }, { duration: '50s', target: 200 }],
  thresholds: { http_req_failed: ['rate<0.01'], http_req_duration: ['p(95)<500'] },
};

export default function () {
  if (!token) {
    const res = http.post('http://127.0.0.1:8099/api/login',
      JSON.stringify({ user: `u${__VU}`, password: 'secret' }),
      { headers: { 'Content-Type': 'application/json' } });
    token = res.json('token');
  }
  check(http.get('http://127.0.0.1:8099/api/items'), { 'list 200': (r) => r.status === 200 });
  const id = Math.floor(Math.random() * 50) + 1;
  http.get(`http://127.0.0.1:8099/api/items/${id}`);
  http.post('http://127.0.0.1:8099/api/cart', JSON.stringify({ id }), {
    headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
  });
  sleep(1);
}

In Locust, the same test is a class. Logging in goes in on_start, which runs once per user, and the think time is the class’s wait_time:

import random
from locust import HttpUser, task, constant

class Shopper(HttpUser):
    host = "http://127.0.0.1:8099"
    wait_time = constant(1)

    def on_start(self):
        res = self.client.post("/api/login", json={"user": f"u{id(self)}", "password": "secret"})
        self.token = res.json()["token"]

    @task
    def shop(self):
        self.client.get("/api/items")
        item_id = random.randint(1, 50)
        self.client.get(f"/api/items/{item_id}", name="/api/items/[id]")
        self.client.post("/api/cart", json={"id": item_id},
                         headers={"Authorization": f"Bearer {self.token}"})

The visible differences are where configuration lives (k6 keeps stages and thresholds in the script; Locust takes users, spawn rate and duration on the command line) and how a dynamic URL is grouped in the results (Locust’s name= argument, a tag in k6). Our Locust tutorial covers the rest of the locustfile, and the k6 scenarios guide covers the options block.

Do k6 and Locust report the same results?

For throughput, yes. For response times, close but not identical. Both tools time a request from sending it to receiving the response, but Locust’s default HttpUser is built on the Python requests library, and that library’s processing time ends up in the measured response times. With 200 users running the test above for 60 seconds:

200 users, 60 sk6 v2.4.0Locust 2.47.0 (HttpUser)
Requests32,52231,888
Requests per second533538
Median, all requests0.86 ms7 ms
95th percentile28.05 ms35 ms
Errors00
Load generator CPUabout 10% of one coreabout 18% of one core

The server answers the product list in well under a millisecond and the single product in 25 ms. k6’s numbers sit right on that; Locust’s add a few milliseconds each. That gap only matters for fast endpoints. Against an endpoint that waits a random 100 to 400 ms (true 95th percentile 385 ms, true 99th 397 ms), with Locust’s faster FastHttpUser client:

100 users, uniform 100 to 400 msk6Locust
Median250.66 ms250 ms
90th percentile369.29 ms370 ms
95th percentile384.9 ms390 ms
99th percentile397.48 ms400 ms

Locust’s percentiles land on round numbers by design. Before storing a response time, it rounds it into a bucket so that workers send less data to the master; its source code gives the examples “147 becomes 150, 3432 becomes 3400 and 58760 becomes 59000”. Between 100 ms and 1 second that means 10 ms steps, which is why the 95th percentile read 390 ms instead of 385 ms. For pass or fail limits set in round numbers this rarely matters; for comparing two runs a few milliseconds apart, it does.

How much load can one machine generate?

On a 10-core laptop, one k6 process sent about 101,000 requests a second, one Locust process 4,000 to 15,000 depending on its HTTP client, and four Locust processes about 59,000. A Python process runs on one CPU core, so a single Locust process stops getting faster once that core is busy, while k6 spreads its virtual users across all cores. Locust’s documentation recommends one worker process per core; its --processes flag starts them on one machine.

With 50 users sending requests with no think time to an endpoint that answers instantly, for 30 seconds on a 10-core laptop that was also running the test server:

50 users, no think timeRequests per secondCPU used
k6, one process101,345about 4.6 cores
Locust HttpUser, one process4,3111 core
Locust FastHttpUser, one process15,4331 core
Locust FastHttpUser, --processes 459,434about 4 cores

FastHttpUser, Locust’s client built on geventhttpclient, did about 3.6 times the work of the default client on the same core. k6 still produced about 1.7 times what four FastHttpUser processes did with a similar number of cores.

The more important finding came from the shopping test at 2,000 users, which needs about 5,400 requests a second. One Locust process reached 2,990 requests a second at 99% CPU and logged its own warning that CPU usage was above 90%. Worse, the response times it reported grew with its own backlog:

2,000 users, 60 sk6, one processLocust, one processLocust, --processes 4
Requests per second5,3442,9905,384
Median1.03 ms260 ms5 ms
95th percentile27.91 ms460 ms35 ms
CPU time per 1,000 requests0.11 s0.32 s0.33 s
Peak memory684 MB244 MB318 MB (four workers plus the master)
Peak threads471155

The server’s slowest endpoint waits 25 ms, and k6’s 95th percentile across all requests on the same test was 27.91 ms. The 260 ms median was time the requests spent waiting inside an overloaded load generator. A test like this one, read without the CPU warning, blames the server for the tool’s queue. Watch for Locust’s “CPU usage above 90%” warning and add processes before trusting the numbers.

Memory runs the other way. Each k6 virtual user carries its own JavaScript runtime, so k6 used 684 MB for 2,000 users, against 244 MB for one Locust process and 318 MB for the four processes that kept up. If the test is thousands of mostly idle users rather than many requests a second, Locust is the lighter of the two.

How do k6 and Locust fit in a CI/CD pipeline?

Both can fail a build, with opposite defaults. Locust exits with code 1 if any request failed, whatever the error rate. k6 exits with code 0 however many requests fail, unless the script defines thresholds; when a threshold fails, k6 exits with code 99. A pipeline that expects a few tolerated errors needs a rule in Locust; one that expects any limit at all needs thresholds in k6.

We sent 20 users at an endpoint that returns a 500 error for 5% of requests:

5% of requests failExit code
k6, no thresholds0 (5.08% failed)
k6, threshold http_req_failed: ['rate<0.01']99
Locust, default1 (5.17% failed)
Locust, own rule allowing up to 10% failures0 (5.20% failed)

k6’s thresholds are a line each in options, on any metric and percentile, and our k6 checks guide shows how checks feed them. Locust has no threshold syntax; you write the rule in Python. Its --exit-code-on-error flag changes the code used for “any failure”, and for a real limit you set the exit code yourself when the test ends:

from locust import events

@events.quitting.add_listener
def apply_rules(environment, **kwargs):
    stats = environment.stats.total
    failed = stats.fail_ratio > 0.10 or stats.get_response_time_percentile(0.95) > 500
    environment.process_exit_code = 1 if failed else 0

How do k6 and Locust model load?

k6 offers both models; Locust offers one. k6’s constant-vus and ramping-vus executors are closed models: a fixed number of users, each waiting for its response before sending the next request. Its constant-arrival-rate and ramping-arrival-rate executors are open models: k6 starts iterations at a set rate whether or not earlier ones have finished. Locust users always wait for each response, and its constant_throughput wait time only caps how often each user sends.

The difference shows up when the server slows down, which is the moment a load test exists to catch. We aimed both tools at 100 requests a second and made the server’s response time jump from 25 ms to 2 seconds for 20 seconds, counting arrivals on the server:

Target 100 requests a secondBeforeDuring the slowdownAfter
k6 constant-arrival-rate, up to 1,000 VUs100/s92/s, 153 iterations dropped100/s
k6 constant-arrival-rate, up to 100 VUs100/s50/s, 1,010 iterations dropped100/s
Locust, 100 users with constant_throughput(1)100/s50/s100/s

Locust’s 100 users each needed 2 seconds per request during the slowdown, so they sent half as much, in bursts: 100 arrivals one second, none the next. The real traffic a slow server sees does not politely halve itself, so the closed model understates the overload. With room for 1,000 VUs, k6 kept starting iterations, adding virtual users as it needed them (201 at the peak). Even so, it dropped 153 iterations in the first seconds of the slowdown while it started new VUs, so set preAllocatedVUs close to what you expect to need. k6 records every skipped iteration in its dropped_iterations metric, so the shortfall is visible in the summary.

To get an arrival rate out of Locust, run many users with constant_throughput; its documentation suggests 5,000 users at constant_throughput(0.1) for 500 iterations a second. That keeps the rate as long as enough users are idle, which is the same trade-off as k6’s VU pool, with no counter for what was skipped.

How do you scale k6 and Locust beyond one machine?

Locust has distribution built in and free: one master process runs the web UI and gives orders, and any number of worker processes, on one machine or many, run the users and send their statistics back. k6 runs on one machine. Spreading one k6 test over several machines takes the k6 Operator on Kubernetes, which splits the virtual users across runner pods, or Grafana Cloud k6, Grafana’s hosted service.

Grafana Cloud k6 has a free tier of 500 virtual user hours a month and charges by usage beyond it. The hosted option has changed on the Locust side. Locust Cloud, the project’s own hosted service, is shutting down, and Locust 2.43.0 (December 2025) removed the references to it. The open-source tool carries on, so multi-region Locust now means running masters and workers in each region yourself, or a managed service such as Azure Load Testing, which Locust’s documentation lists as its hosted option. On the k6 side, our k6 Operator guide shows how the operator splits one test across pods, including what happens to setup and thresholds when it does.

When to choose k6 and when to choose Locust

Choose by language and by how much load one machine has to make. Both tools produce trustworthy numbers when the load generator is not the bottleneck, so the k6 vs Locust decision rests on who writes the tests, which libraries they need, how much load one machine must make, and whether arrival-rate load matters to what you are testing.

Choose k6 when:

  • the team writes JavaScript or TypeScript, or wants tests that read like front-end code;
  • one machine must produce thousands of requests a second without extra processes;
  • you need arrival-rate load that keeps coming when the server slows down;
  • you want pass or fail thresholds in the script;
  • you need gRPC, WebSocket or real-browser tests from one tool.

Choose Locust when:

  • the team writes Python, or the test needs Python libraries your services already use;
  • you want free distributed load across your own machines without Kubernetes;
  • you want a web UI to start, watch and change a test while it runs;
  • the test is thousands of mostly idle users rather than a high request rate.

For a YAML-based option, k6 vs Artillery repeats these tests in Artillery. For a GUI-based option, JMeter vs Locust compares Locust with JMeter on similar tests, and our k6 vs JMeter vs Gatling vs Locust comparison puts four tools side by side.

Running k6 tests in the cloud with LoadFocus

Generating load from one laptop is where both tools meet their limits, so many teams move the runs to a managed service. LoadFocus runs uploaded k6 scripts on its own cloud infrastructure from 25 regions, with up to 20,000 concurrent virtual users depending on the plan. You can set a percentage of the load per region. It runs k6 and JMeter scripts but not locustfiles.

The Locust alternative page sets out when staying on Locust is the better answer for a Python team. For k6, see k6 load testing in the cloud.

Frequently Asked Questions

Is k6 better than Locust?

Neither is better overall. k6 is better when one machine must produce a high request rate, when you need arrival-rate load or when the team writes JavaScript. Locust is better for Python teams, for tests that need Python libraries, and for free distributed load without Kubernetes. Run side by side on a 200-user test against one local API in November 2026, both sent about 535 requests a second with no errors.

Is k6 faster than Locust?

Yes, per process. In LoadFocus tests in November 2026 on a 10-core laptop, with 50 users and no think time, one k6 process sent 101,345 requests a second to a fast endpoint, against 4,311 for one Locust process with its default client and 15,433 with FastHttpUser. Locust uses one CPU core per process, so it needs several processes to approach k6 on one machine; four Locust processes with FastHttpUser reached 59,434.

Can Locust run k6 scripts?

No. Locust runs Python test classes, and k6 runs JavaScript or TypeScript modules, so moving a test from one tool to the other means rewriting it. The request flow, think times and pass or fail limits carry over as a design; the code does not.

Does k6 support Python?

No. k6 tests are written in JavaScript or TypeScript, and k6 runs TypeScript files directly, without a build step. A Python team that wants to keep its tests in Python should use Locust, or another Python-based tool.

Is Locust free?

Yes. Locust is open source under the MIT licence, including its distributed mode. The hosted Locust Cloud service is shutting down, so large runs mean hosting the master and workers yourself or using a managed service such as Azure Load Testing. k6 is also free, under the AGPL-3.0 licence, and Grafana Cloud k6 is its hosted service, with a free monthly allowance and usage-based pricing beyond it.

Sources

  • k6 v2.4.0 release notes and licence: github.com/grafana/k6, release v2.4.0 (12 November 2026) and repository licence, November 2026.
  • k6 executors and the arrival-rate options (preAllocatedVUs, maxVUs, dropped_iterations): grafana.com/docs/k6, “Executors” and “Constant arrival rate”, November 2026.
  • Locust 2.47.0 package metadata (MIT licence, Python 3.11 or later) and response-time bucketing (locust/stats.py): pypi.org/project/locust and the installed 2.47.0 package, November 2026.
  • Locust distributed runs, one process per core, --processes: docs.locust.io, “Distributed load generation”, November 2026. Wait times (constant_throughput, constant_pacing, poisson) and the 5,000-user example: docs.locust.io, “Writing a locustfile”, November 2026. Background checks on the fail ratio: docs.locust.io, “Extending Locust”, November 2026.
  • Grafana Cloud k6 free tier (500 virtual user hours a month) and usage-based Pro pricing: grafana.com/pricing, read 17 November 2026.
  • Azure Load Testing as the hosted option for Locust tests: docs.locust.io, “Hosted load testing”, November 2026.
  • Locust Cloud shutdown: Locust 2.43.0 release notes (30 December 2025), “Remove references to locust.cloud now that it is shutting down”, github.com/locustio/locust, November 2026.
  • LoadFocus k6 cloud runs, regions and virtual user limits: loadfocus.com/k6-load-testing and loadfocus.com/pricing; LoadFocus on Locust: loadfocus.com/alternatives/locust-alternative, read 17 November 2026.
  • Test runs: k6 v2.4.0 (macOS arm64 binary) and Locust 2.47.0 on Python 3.12.13, against a local Node.js test API (four worker processes; one for the slowdown test, which counted arrivals itself) on an Apple M1 Max, 17 November 2026. Memory and threads were sampled per process every second, with CPU totals from /usr/bin/time -l. The laptop carried other work during the runs (load average 7 to 30), so compare the tools within a test, not between tests. Timings show patterns, not benchmarks.

Bogdan

Founder at LoadFocus

Bogdan builds and runs the tools this blog is about. He writes from what the products actually do in production, including the parts that break.

Weekly tips right in your inbox.

Don’t miss out on the latest testing tips and tricks, tools and news related to software testing.

Already +20,000 members in the list.

The Load Testing Platform with AI That Explains Your Results

Load test websites and APIs from 25 cloud regions, monitor page speed and uptime, and get AI analysis that explains your results in plain English.

Cloud load testing, website speed and API monitoring in one place.

Hi there! Can I share a cool thing I'm working on with you?

A software testing newsletter that sparks joy.

Our goal is to create helpful content for software developers and testers.

If you're not into it, you can unsubscribe instantly.