k6

Also known as: Grafana k6

On this page 7

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.

ElementPurposeTypical example
Virtual usersSimulate concurrent clients50 to 5,000 VUs
OptionsDefine duration, stages and executorsstages ramping to 200 VUs
ChecksValidate individual responsesStatus equals 200
ThresholdsSet pass or fail criteria for the runp(95) below 500 ms
ScenariosCombine several workload modelsBrowsing plus checkout traffic
Custom metricsTrack business-specific valuesCounter of failed logins
Core elements of a k6 test script

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 typeLoad patternQuestion it answers
Smoke test1 to 5 VUs for a minuteDoes the script and system work at all
Average-load testExpected daily trafficDoes the server meet its targets normally
Stress testAbove expected peakWhere does performance degrade
Spike testSudden sharp surgeDoes the system survive a burst
Soak testModerate load for hoursDo memory leaks or slow drift appear
Breakpoint testSteadily rising loadWhat is the maximum capacity
Common test types run with k6

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.

MetricWhat it measuresWarning sign
http_req_durationTotal request time without connection setupp(95) rising with load
http_req_waitingTime to first byte from the serverGrowth points to backend work
http_req_failedShare of failed requestsAbove 1 percent
http_reqsRequests per second achievedPlateau while VUs still rise
iteration_durationTime for one full user journeyRises faster than request time
vusActive virtual usersFewer VUs than planned
Key k6 metrics and their interpretation

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.

ToolTest definitionMain strength
k6JavaScript scriptsLow resource use and CI thresholds
Apache JMeterXML plans built in a GUIBroad protocol support and plugins
GatlingScala, Java or Kotlin codeDetailed HTML reports
LocustPython codeFlexible Python logic
wrkCommand line with Lua hooksMaximum raw requests per second
k6 compared with related tools

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.