k6, also known as Grafana k6, is an open-source load testing tool that generates simulated user traffic from test scripts written in JavaScript and reports how a system behaves under that load. In server performance work, it is used to measure response time, throughput and error rates before real users discover the limits of a server, an API or a full web application.
The engine is written in Go, which lets a single machine drive thousands of virtual users with modest memory use. Test results can be judged automatically against pass or fail thresholds, which makes k6 a natural fit for continuous integration pipelines on Servers that must keep predictable performance after every release.
How k6 generates and measures load
k6 executes a script in which each virtual user (VU) runs a default function in a loop, and each completed run of that function is one iteration. The script sends HTTP requests, WebSocket messages or gRPC calls, checks the responses and optionally pauses with sleep() to imitate human think time.
Every request produces built-in metrics such as http_req_duration, http_req_failed and http_reqs. k6 aggregates these values into percentiles, averages and rates at the end of the test, and it can stream raw data points to an external backend for dashboards. Because the JavaScript runs in an embedded runtime rather than in Node.js or a browser, Node.js modules and browser APIs are not available by default.
The following table lists the core elements of a k6 test and their role in the measurement.
| Element | Purpose | Typical example |
|---|---|---|
| Virtual users | Simulate concurrent clients | 50 to 5,000 VUs |
| Options | Define duration, stages and executors | stages ramping to 200 VUs |
| Checks | Validate individual responses | Status equals 200 |
| Thresholds | Set pass or fail criteria for the run | p(95) below 500 ms |
| Scenarios | Combine several workload models | Browsing plus checkout traffic |
| Custom metrics | Track business-specific values | Counter of failed logins |
Test types and executors in k6
k6 supports every common load test profile by changing the options rather than the request logic. The same script can therefore serve as a quick smoke test in a pipeline and as a large stress test before a seasonal traffic peak.
| Test type | Load pattern | Question it answers |
|---|---|---|
| Smoke test | 1 to 5 VUs for a minute | Does the script and system work at all |
| Average-load test | Expected daily traffic | Does the server meet its targets normally |
| Stress test | Above expected peak | Where does performance degrade |
| Spike test | Sudden sharp surge | Does the system survive a burst |
| Soak test | Moderate load for hours | Do memory leaks or slow drift appear |
| Breakpoint test | Steadily rising load | What is the maximum capacity |
Executors control how iterations are scheduled. Closed models such as ramping-vus keep a fixed number of VUs, so a slower server automatically receives fewer requests. Open models such as constant-arrival-rate start iterations at a fixed rate regardless of response time, which reproduces real traffic more faithfully and avoids the coordinated omission problem that hides latency during overload.
Reading k6 results for server performance
The end-of-test summary shows distribution statistics for every metric. Experienced engineers focus on the 95th and 99th percentiles rather than the average, because averages conceal the tail latency that users actually notice during busy periods.
The table below explains the metrics most often used to diagnose server bottlenecks.
| Metric | What it measures | Warning sign |
|---|---|---|
http_req_duration | Total request time without connection setup | p(95) rising with load |
http_req_waiting | Time to first byte from the server | Growth points to backend work |
http_req_failed | Share of failed requests | Above 1 percent |
http_reqs | Requests per second achieved | Plateau while VUs still rise |
iteration_duration | Time for one full user journey | Rises faster than request time |
vus | Active virtual users | Fewer VUs than planned |
A flat request rate combined with rising latency usually signals resource saturation, such as an exhausted PHP worker pool or a database connection limit. Rising error rates at a fixed load more often indicate timeouts, rate limiting or a failing dependency.
How k6 compares with other load testing tools
k6 belongs to the code-first generation of load testing tools, in which tests are versioned in Git alongside the application. Its closest alternatives differ mainly in scripting language, resource efficiency and how tests are created.
| Tool | Test definition | Main strength |
|---|---|---|
| k6 | JavaScript scripts | Low resource use and CI thresholds |
| Apache JMeter | XML plans built in a GUI | Broad protocol support and plugins |
| Gatling | Scala, Java or Kotlin code | Detailed HTML reports |
| Locust | Python code | Flexible Python logic |
| wrk | Command line with Lua hooks | Maximum raw requests per second |
The practical choice depends on the team. Developers who already write JavaScript adopt k6 quickly, while groups that depend on GUI test design or unusual enterprise protocols often stay with Apache JMeter.
Limitations and common mistakes
k6 measures protocol-level behavior, so it does not render pages or execute front-end JavaScript unless the separate browser module is used, and that module consumes far more resources per user. The most frequent errors, however, come from test design rather than from the tool itself.
- Testing from an overloaded generator: when the load machine reaches high CPU use, measured latency reflects the client, not the server.
- Omitting think time: scripts without pauses create unrealistic request rates per user.
- Ignoring caches: repeated identical URLs hit a full-page cache and hide the real cost of uncached requests.
- Relying on averages: thresholds should use percentiles to catch tail latency.
- Testing production without coordination: unannounced load can trigger alerts, autoscaling costs or protective blocking.
Stripped to the essentials
k6 is a program that pretends to be many visitors at once. A short script describes what each visitor does, such as opening a page or sending a form. k6 then repeats those steps with hundreds or thousands of copies at the same time.
While this happens, k6 records how fast the server answers. It also counts how often the server fails. The key takeaway is simple. It shows how much traffic a server can handle in a calm test, not during a real rush of customers.
Where it is applied
An online retailer expects five times its normal traffic during a holiday sale. Two weeks before the event, the operations team writes a k6 script that browses categories, opens product pages and adds items to the cart. It uses a constant-arrival-rate executor ramping to 400 iterations per second, with a threshold requiring p(95) below 800 ms and fewer than 1 percent errors.
The first run fails at about 250 iterations per second: latency climbs sharply while the request rate stalls. Server metrics show the PHP worker pool fully occupied and slow uncached cart queries. After the team adds an object cache, enlarges the pool and tunes database indexes, a repeat test sustains the target rate with p(95) at 520 ms. The sale then runs without a measurable slowdown, and the script remains in the pipeline as a regression check.