LinuxCommandLibrary

k6

Load test websites and APIs

TLDR

Run load test locally

$ k6 run [script.js]
copy

Run load test locally with a given number of virtual users and duration
$ k6 run [[-u|--vus]] [10] [[-d|--duration]] [30s] [script.js]
copy

Run load test locally with a given environment variable
$ k6 run [[-e|--env]] [HOSTNAME=example.com] [script.js]
copy

Run load test locally using InfluxDB to store results
$ k6 run [[-o|--out]] influxdb=[http://localhost:8086/k6db] [script.js]
copy

Run load test locally and discard response bodies (significantly faster)
$ k6 run --discard-response-bodies [script.js]
copy

Run load test locally using the base JavaScript compatibility mode (significantly faster)
$ k6 run --compatibility-mode=base [script.js]
copy

Log in to cloud service using secret token
$ k6 login cloud --token [secret]
copy

Run load test on cloud infrastructure
$ k6 cloud [script.js]
copy

SYNOPSIS

k6 [command] [flags]

PARAMETERS

run script.js
    Executes the k6 script.

-u, --vus number
    Number of virtual users (VUs) to simulate.

-d, --duration duration
    Duration of the test (e.g., 10s, 1m, 2h).

-i, --iterations number
    Number of iterations to execute.

-r, --rps number
    The number of requests per second to send to the target.

-o, --out output
    Output format (e.g., json, csv, influxdb, cloud).

--http-debug output
    output http requests and responses.

--no-connection-reuse
    Disable keep-alive connections.

--no-usage-report
    Disable automatic k6 usage reporting.

--compatibility-mode string
    Enable compatibility mode for certain versions of k6.

--config config-file
    Specifies the configuration file to use.

--summary-export summary_file
    Exports the test summary to a file.

DESCRIPTION

k6 is a modern load testing tool built for developers and DevOps engineers. It allows you to test the performance of your systems and applications by simulating real user traffic.

Unlike traditional load testing tools, k6 is scriptable in JavaScript (ES2015/ES6), making it easy to write and maintain tests. It supports various protocols including HTTP, WebSocket, and gRPC. k6 is designed to be highly performant and scalable, capable of generating high volumes of traffic from a single machine or distributed across multiple machines using k6 cloud service. You can define key performance indicators (KPIs) and set thresholds to automatically detect regressions. k6 helps identify bottlenecks and ensure your system can handle the expected load. The tool provides valuable metrics around duration, throughput, error rates, and more for identifying performance problems.

Its modular design and extensive documentation make it easy to learn and integrate into your existing CI/CD pipelines.

JAVASCRIPT API

k6 exposes a powerful JavaScript API that allows you to define your load tests. This API includes functions for making HTTP requests, setting up WebSocket connections, defining custom metrics, and much more.

CLOUD EXECUTION

k6 offers a cloud service that allows you to run your load tests at scale, distributing the load across multiple machines. This is useful for simulating large user loads and testing the performance of your system under extreme conditions.

METRICS

k6 collects detailed metrics about the performance of your system, including response times, error rates, and throughput. These metrics can be used to identify bottlenecks and optimize the performance of your system.

HISTORY

k6 was initially developed by Load Impact AB (now Grafana Labs). It was designed to address the limitations of existing load testing tools, focusing on developer friendliness, performance, and extensibility. The tool has gained popularity due to its ease of use, JavaScript scripting capabilities, and integration with CI/CD pipelines. It has been actively developed and maintained with regular updates and new features.k6 continues to grow as a robust load testing solution.

The first commit to the github repository was made around late 2016.

SEE ALSO

curl(1), wrk(1), hey(1)

Copied to clipboard