k6
Load test websites and APIs
TLDR
Run load test locally
Run load test locally with a given number of virtual users and duration
Run load test locally with a given environment variable
Run load test locally using InfluxDB to store results
Run load test locally and discard response bodies (significantly faster)
Run load test locally using the base JavaScript compatibility mode (significantly faster)
Log in to cloud service using secret token
Run load test on cloud infrastructure
SYNOPSIS
k6 [global options] <command> [command options] [arguments]
Common Commands:
k6 run <script.js>
k6 archive <script.js>
k6 cloud <script.js>
k6 login <token>
k6 inspect <script.js>
PARAMETERS
-v
, --version
Prints the k6 version number and exits.--config <file>
Specifies a configuration file to load. Settings from this file will override defaults but can be further overridden by command-line options.--log-output <path>
Redirects logs from k6 to a specified file or stdout
/stderr
. Defaults to stderr
.--no-color
Disables colored output in the terminal.--summary-export <path>
Exports the end-of-test summary to a JSON file at the specified path.--console-output <path>
Redirects output from console.log()
statements within the JavaScript test script to a specified file.
DESCRIPTION
k6 is an open-source load testing tool designed for developer experience and automation. It allows performance tests to be written in JavaScript (ES2015+), providing a rich API for making HTTP requests, defining checks, and setting thresholds. Unlike traditional tools that often simulate full browser actions, k6 focuses on API and protocol-level testing, making it efficient for testing backend services, microservices, and network protocols like HTTP, WebSockets, and gRPC.
Written in Go, k6 is performant and resource-efficient, making it suitable for generating high loads from a single machine. It integrates well into CI/CD pipelines, supporting automation and enabling continuous performance testing. Its strong emphasis on scripting flexibility, extensibility, and detailed metric output makes it a preferred choice for modern DevOps and SRE teams.
CAVEATS
While k6 excels at API and protocol-level load testing, it does not simulate full browser rendering or user interaction in a browser. For browser-level performance testing (e.g., evaluating page load times with full DOM rendering), it may need to be combined with other tools like Playwright or Selenium. Test scripting requires JavaScript knowledge.
<B>TEST SCRIPTING LANGUAGE</B>
k6 tests are written in standard JavaScript (ES2015+), allowing developers to define complex test scenarios, virtual user behavior, and assertions using familiar programming constructs. This enables version control, code review, and reusability of test scripts, making performance testing a more integrated part of the software development lifecycle.
<B>METRICS AND RESULTS</B>
k6 generates detailed metrics about test execution, including request durations, response times, throughput, and error rates. These metrics can be outputted to various formats (e.g., JSON, CSV, InfluxDB, Prometheus, Datadog) and integrated with monitoring systems for comprehensive analysis and visualization. Crucially, k6 supports defining 'thresholds' – pass/fail criteria for test metrics – directly within the script or via command-line options, enabling automated test gating in CI/CD environments.
HISTORY
k6 was created by Grafana Labs (initially by the R&D team behind Load Impact) and open-sourced in 2017. The project aimed to address perceived shortcomings of existing load testing tools, focusing on a developer-centric workflow, ease of automation, and modern scripting capabilities. By leveraging Go for its performance and JavaScript for scripting, k6 quickly gained traction as a modern alternative, emphasizing integration into CI/CD pipelines and supporting continuous performance testing as a DevOps practice.
SEE ALSO
JMeter(1) - A popular open-source Apache tool for load testing functional behavior and measuring performance., Locust(1) - An open-source load testing tool written in Python, allowing tests to be scripted as Python code., Gatling(1) - A powerful open-source load testing tool written in Scala, known for its DSL and performance.