k6
Developer-centric load testing tool by Grafana Labs. Write tests in JavaScript or TypeScript, run them on a blazing-fast Go runtime, define pass/fail thresholds, and integrate directly into your CI/CD pipeline — no GUI required.
What is k6?
k6 (pronounced "kay-six") is an open-source load testing tool built by Grafana Labs and the community. Unlike older tools that require XML configuration or a GUI, k6 tests are plain JavaScript or TypeScript files that live in your repo. The runtime is written in Go, not Node.js — meaning k6 can push enormous load from a single machine with minimal memory overhead.
k6 is opinionated about the developer experience: tests are code, results are structured, and pass/fail criteria (thresholds) are defined alongside the test logic. This makes k6 a natural fit for modern engineering teams that treat performance as part of the CI/CD pipeline rather than a one-off pre-production activity.
Key Features
- JavaScript/TypeScript tests — familiar language, ES modules, IntelliSense support; tests version-controlled like application code
- Go runtime — not Node.js; extremely low memory per VU enables high concurrency on modest hardware
- Built-in protocols — HTTP/1.1, HTTP/2, WebSockets, and gRPC out of the box
- Virtual Users + executors — constant VUs, ramping VUs, constant arrival rate, ramping arrival rate, and more for realistic load shapes
- Thresholds — define SLO-based pass/fail criteria (e.g.
p(95)<500) that fail CI on breach - Custom metrics — Counter, Gauge, Rate, Trend for domain-specific instrumentation
- xk6 extensions — build custom k6 binaries with Kafka, Redis, browser, SQL, and more
- Output integrations — stream metrics to Grafana Cloud, InfluxDB, Prometheus, Datadog, or JSON/CSV
- k6 browser — bundled Chrome DevTools Protocol module for real browser performance testing
Installation
# macOS (Homebrew) brew install k6 # Windows (Chocolatey) choco install k6 # Windows (winget) winget install k6 --source winget # Docker docker pull grafana/k6 # Linux (Debian/Ubuntu) sudo gpg -k sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69 echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list sudo apt-get update && sudo apt-get install k6 # Verify installation k6 version
Quick Start: Basic Load Test
A k6 script exports a default function (the "virtual user loop") and an options object for configuration. The example below ramps to 20 VUs, holds for 1 minute, then ramps down — and fails if the p95 response time exceeds 500ms.
// script.js — a basic k6 load test
import http from 'k6/http';
import { check, sleep } from 'k6';
// Test configuration: ramp up, hold, ramp down
export const options = {
stages: [
{ duration: '30s', target: 20 }, // ramp up to 20 VUs over 30s
{ duration: '1m', target: 20 }, // hold at 20 VUs for 1 minute
{ duration: '10s', target: 0 }, // ramp down to 0 VUs
],
thresholds: {
http_req_duration: ['p(95)<500'], // 95th percentile must be < 500ms
http_req_failed: ['rate<0.01'], // error rate must be < 1%
},
};
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1); // think time between iterations
} Run it with: k6 run script.js
Advanced: Custom Metrics & Authentication
Use the k6/metrics API to track domain-specific values. Define a Trend for login duration and a Rate for login failures, then set thresholds on them.
// Advanced: authenticated POST + JSON parsing + custom metrics
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate, Trend } from 'k6/metrics';
const loginFailRate = new Rate('login_failures');
const loginDuration = new Trend('login_duration_ms');
export const options = {
vus: 50,
duration: '2m',
thresholds: {
login_failures: ['rate<0.05'],
login_duration_ms: ['p(99)<1000'],
http_req_duration: ['p(95)<400', 'p(99)<800'],
},
};
export default function () {
const payload = JSON.stringify({ username: 'testuser', password: 'secret' });
const params = { headers: { 'Content-Type': 'application/json' } };
const res = http.post('https://api.example.com/auth/login', payload, params);
const success = check(res, {
'login status 200': (r) => r.status === 200,
'has access_token': (r) => JSON.parse(r.body).access_token !== undefined,
});
loginFailRate.add(!success);
loginDuration.add(res.timings.duration);
sleep(Math.random() * 2 + 1); // random think time 1-3s
} Executor Types
k6 scenarios let you mix different executor types in a single test. Use constant-arrival-rate to model steady-state throughput independent of response time, or ramping-arrival-rate to simulate traffic spikes.
// Executor types for realistic load shapes
export const options = {
scenarios: {
// Constant arrival rate — independent of response time
constant_load: {
executor: 'constant-arrival-rate',
rate: 100, // 100 requests per second
duration: '1m',
preAllocatedVUs: 20,
maxVUs: 50,
},
// Ramping arrival rate — simulate traffic spikes
spike_test: {
executor: 'ramping-arrival-rate',
startRate: 10,
stages: [
{ target: 500, duration: '30s' }, // spike to 500 rps
{ target: 10, duration: '30s' }, // recover
],
preAllocatedVUs: 50,
maxVUs: 200,
},
// Per-VU iterations — each VU runs exactly N times
smoke_test: {
executor: 'per-vu-iterations',
vus: 5,
iterations: 10,
maxDuration: '1m',
},
},
}; CI/CD Integration
k6 exits with a non-zero code when thresholds are breached, making it a drop-in CI gate. Grafana provides an official grafana/k6-action for GitHub Actions.
# GitHub Actions — run k6 as part of CI pipeline
name: Load Test
on:
push:
branches: [main]
jobs:
k6_load_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run k6 load test
uses: grafana/[email protected]
with:
filename: tests/load/api.js
env:
BASE_URL: ${{ secrets.STAGING_URL }}
# Or run k6 directly
- name: Install k6
run: |
curl https://github.com/grafana/k6/releases/download/v0.51.0/k6-v0.51.0-linux-amd64.tar.gz -L | tar xvz
sudo cp k6-v0.51.0-linux-amd64/k6 /usr/local/bin
- name: Run tests
run: k6 run --out json=results.json tests/load/api.js k6 vs JMeter vs Locust
| Feature | k6 | JMeter | Locust |
|---|---|---|---|
| Test language | JS / TypeScript | XML / GUI | Python |
| Runtime | Go (fast & lean) | JVM (heavy) | Python (GIL limits) |
| CI/CD fit | Excellent | Moderate | Good |
| GUI | CLI-first | Rich GUI | Web UI |
| Cloud offering | Grafana k6 Cloud | BlazeMeter | Locust.cloud |
| Browser testing | k6 browser (built-in) | Via plugins | No |
Pros and Cons
Pros
- ✓ Tests are code — version-controlled, reviewable, reusable
- ✓ Extremely low memory per VU thanks to Go runtime
- ✓ First-class CI/CD support via exit codes and threshold gates
- ✓ Rich metrics output: JSON, CSV, Grafana, InfluxDB, Prometheus
- ✓ Active ecosystem with xk6 extensions and official Grafana support
Cons
- ✗ No Node.js APIs — standard Node modules are unavailable in the runtime
- ✗ No built-in HTML report (requires k6 Cloud or external dashboards)
- ✗ Browser testing via k6 browser is newer and less mature
- ✗ Distributed testing requires k6 Cloud or manual orchestration
- ✗ Smaller plugin ecosystem than JMeter
Frequently Asked Questions
What is k6?▼
k6 is an open-source, developer-centric load testing tool built by Grafana Labs. You write tests in JavaScript or TypeScript using a clean ES module API, but the runtime is Go — not Node.js — which means k6 is extremely efficient: a single machine can generate massive load with low resource overhead. k6 is designed for CI/CD pipelines and developer workflows, with a CLI-first interface and rich metrics output.
How is k6 different from JMeter?▼
JMeter uses a GUI-based XML configuration model and runs on the JVM, which makes it memory-intensive and harder to version-control. k6 tests are plain JavaScript files that live in your repo alongside application code, work seamlessly in CI/CD pipelines, and produce structured JSON or CSV output. k6 also starts up much faster and uses far less memory per virtual user. JMeter has a larger ecosystem of plugins and a long enterprise track record; k6 is preferred for modern developer-owned workflows.
What are Virtual Users (VUs) in k6?▼
A Virtual User (VU) represents a simulated user executing your test script in a continuous loop. Each VU runs independently and concurrently, maintaining its own cookies, headers, and connection state. You control the number of VUs over time using stages (gradual ramp-up) or executors (constant arrival rate, ramping arrival rate, per-VU iterations, etc.). VU count is the primary knob for controlling concurrency and load.
How do thresholds work in k6?▼
Thresholds are pass/fail criteria defined in the options object. Examples: http_req_duration: ['p(95)<500'] (95th percentile response time must be under 500ms) or http_req_failed: ['rate<0.01'] (error rate must be below 1%). If any threshold is breached, k6 exits with a non-zero exit code, which fails the CI job. Thresholds can be applied to built-in metrics (http_req_duration, http_req_failed, vus) or custom metrics you define with the k6/metrics API.
Can k6 run in CI/CD pipelines?▼
Yes — k6 is designed for CI/CD. It exits with code 0 on pass and non-zero when thresholds are breached, which maps directly to pipeline success/failure. Grafana provides an official k6-action for GitHub Actions. k6 can output results as JSON, CSV, or stream them to Grafana Cloud, InfluxDB, or Prometheus for dashboard visualization. A typical pattern is to run a smoke test on every push and a full load test nightly or before releases.
What protocols does k6 support?▼
k6 has built-in support for HTTP/1.1, HTTP/2, WebSockets, and gRPC. The xk6 extension system lets you build custom k6 binaries with community or private extensions that add support for Kafka, Redis, SQL databases, browser automation (via k6 browser, now bundled), and more. The k6 browser module uses the Chrome DevTools Protocol for real browser-based performance testing without needing a separate tool.
Related Products
on GumroadPremium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad →GitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
HTTP Status Code Reference
Complete HTTP status code reference. Search all 1xx, 2xx, 3xx, 4xx, and 5xx codes with plain-English descriptions, real-world use cases, and when to use each in REST APIs.
Open free tool →
HTTP Status Code Reference
Complete HTTP status code reference. Look up all 1xx, 2xx, 3xx, 4xx, and 5xx codes with plain-English descriptions, real-world use cases, and when to use each. Searchable and filterable.
Open free tool →
HTTP Status Code Lookup
Browse and search all HTTP status codes (1xx–5xx). Get name, description, common causes, and when to use each code. Complete REST API status code reference.
Open free tool →
More Free Tools
Related Articles
Performance Testing in 2026: Beyond Page Load Times
A practical guide to performance testing in 2026 — Core Web Vitals, load testing, stress testing, soak testing, and building a performance culture that treats speed as a feature. Includes tooling recommendations and actionable measurement strategies.
Best Load Testing Tools for Developers in 2025: k6, JMeter, Locust, and More
A practical comparison of load testing tools in 2025 — k6, JMeter, Locust, Gatling, and Artillery — covering scripting ease, CI integration, cloud execution, and when each tool fits your testing needs.
DevOps Automation Tools in 2026: Orchestrating the Software Delivery Pipeline
Master DevOps automation with this guide to the tools that orchestrate modern software delivery. Covers CI/CD pipelines, infrastructure provisioning, configuration management, testing automation, and the emerging AI-assisted automation patterns that define 2026.
End-to-End Testing in 2026: Writing Tests That Don't Lie
E2E testing guide 2026: choose Playwright or Cypress, eliminate flakiness, structure test suites for CI/CD, and understand real application quality limits.
QA Automation in 2026: From Script Kiddies to Intelligent Test Suites
How modern QA automation has evolved in 2026 — AI-driven test generation, self-healing frameworks, shift-left strategies, and the real cost of not automating. A practical guide for teams still writing tests manually.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →