k6 — Modern Load Testing Tool Using Go and JavaScript
k6 is a modern load testing tool built by Grafana Labs. Write test scripts in JavaScript, run them in a high-performance Go runtime. Developer-centric with CLI-first workflow, CI/CD integration, and Grafana Cloud for result analysis.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 4240522f-364b-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
k6 is a modern load testing tool built by Grafana Labs. You write test scripts in JavaScript (ES6), and k6 executes them in a high-performance Go runtime (not Node.js). It is CLI-first, developer-friendly, and built for CI/CD integration.
k6 targets developers and QA engineers who need to validate API performance, test for regressions, and simulate concurrent user load. It works locally, in CI pipelines, and with Grafana Cloud for distributed testing and result analysis.
How it saves time or tokens
k6 combines the familiarity of JavaScript with the performance of Go. Unlike JMeter or Gatling, there is no GUI to configure. Tests are code, which means they are version-controlled, reviewed in PRs, and run in CI/CD automatically. Built-in thresholds fail the test if performance SLOs are not met, catching regressions before deployment. The CLI-first workflow means load tests run alongside unit tests in the same pipeline.
How to use
- Install k6:
brew install k6 # macOS
sudo apt install k6 # Debian/Ubuntu
- Write a load test script:
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '30s', target: 50 },
{ duration: '1m', target: 50 },
{ duration: '10s', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://api.example.com/health');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
- Run the test:
k6 run load-test.js
k6 run --vus 100 --duration 2m load-test.js
Example
A CI/CD-ready load test with multiple scenarios:
import http from 'k6/http';
import { check } from 'k6';
export const options = {
scenarios: {
smoke: {
executor: 'constant-vus',
vus: 1,
duration: '10s',
},
load: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '1m', target: 100 },
{ duration: '3m', target: 100 },
{ duration: '1m', target: 0 },
],
startTime: '15s',
},
},
thresholds: {
http_req_duration: ['p(99)<1000'],
http_req_failed: ['rate<0.005'],
},
};
Related on TokRepo
- Testing tools — More testing and quality assurance tools on TokRepo.
- DevOps tools — Browse CI/CD and infrastructure tools.
Common pitfalls
- Running k6 from a single machine limits the maximum number of virtual users. For large-scale tests, use k6 Cloud or distribute across multiple machines.
- Not setting thresholds means tests always pass regardless of performance. Define SLO-based thresholds for every test.
- Testing against production without rate limiting can cause outages. Use staging environments or set conservative VU limits for production tests.
常见问题
k6 embeds a Go-based JavaScript runtime (goja) that is optimized for running many virtual users concurrently with minimal memory overhead. Node.js is single-threaded and not designed for simulating thousands of concurrent connections efficiently.
Yes. k6 supports HTTP/1.1, HTTP/2, WebSocket, and gRPC protocols. Extensions via the xk6 framework add support for additional protocols like Kafka, SQL, and Redis.
k6 outputs metrics to Grafana Cloud for real-time dashboards and historical analysis. You can also pipe k6 output to InfluxDB, Prometheus, or Datadog for self-hosted monitoring.
Scenarios let you define multiple workload patterns in a single test. Each scenario has its own executor (constant VUs, ramping VUs, constant arrival rate), duration, and start time. This enables smoke, load, and stress tests in one script.
Yes. k6 is open source under AGPL 3.0. The CLI and all core features are free. Grafana Cloud k6 (distributed testing and cloud dashboards) is a paid service with a free tier.
引用来源 (3)
- k6 GitHub— k6 is a modern load testing tool by Grafana Labs
- k6 Documentation— k6 scripting and configuration documentation
- Grafana k6 Guide— Load testing best practices
讨论
相关资产
Ddosify — High-Performance Load Testing and Observability Platform
Ddosify is a high-performance load testing tool written in Go that supports HTTP, HTTPS, HTTP/2, gRPC, and GraphQL protocols, with scenario-based testing and distributed execution.
Artillery — Modern Load Testing for HTTP, WebSocket & More
Node.js load testing toolkit with YAML scenarios covering HTTP, WebSocket, gRPC and Playwright, plus distributed runs on AWS Fargate.
Gatling — High-Performance Load Testing for Web Applications
Gatling is an open-source load and performance testing tool for web applications, built on Scala and Akka, that generates detailed HTML reports from code-defined test scenarios.
hey — HTTP Load Generator for Benchmarking Web Servers
Lightweight HTTP load generator written in Go, designed as a modern replacement for ApacheBench with better concurrency handling.