Updated recently
Last updated:
Quick Answer: k6 is a JavaScript-based load testing tool that runs performance tests from the command line. To start: install k6, write a test script with virtual users and duration, run from CLI, and analyze response time metrics (p50, p95, p99) and error rates.
What is k6?
k6 is an open-source load testing tool built in Go with JavaScript scripting. It measures response times, throughput, error rates, and custom metrics.
Install k6
# macOS
brew install k6
# Windows
choco install k6
# Linux
sudo apt-get install k6
Write Your First k6 Test
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://api.example.com/users');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
Run the Test
k6 run load-test.js
k6 run --vus 50 --duration 60s load-test.js
Understanding k6 Metrics
| Metric | What It Measures | Target |
|---|---|---|
| http_req_duration (p50) | Median response time | < 200ms |
| http_req_duration (p95) | 95th percentile | < 500ms |
| http_req_failed | Failed requests % | < 1% |
Integrate k6 with CI/CD
# GitHub Actions
- uses: grafana/[email protected]
with:
filename: load-test.js
When to Use k6 vs JMeter
k6 is better for developer-centric teams and CI/CD. JMeter is better for protocol diversity and enterprise environments.
Training Resources
Master performance testing with SkilBrill Load Testing Training.
FAQ
Is k6 better than JMeter?
k6 is better for modern CI/CD workflows. JMeter is better for protocol diversity and enterprise environments.
