Go Other
Latest commit d4152d2 Aug 4, 2018
Permalink
Failed to load latest commit information.
.circleci Fix various dep stable installation issues Jul 11, 2018
api Fix all errcheck issues Jul 5, 2018
cmd Fix the config consolidation and hide password input in the form UI Aug 3, 2018
converter/har Improve options exporting in HAR conversion and to JS runtime Jul 16, 2018
core Fix the remaining issues from the real-time metrics refactoring Jul 17, 2018
external [fix] Gah, that broke every yml file mentioning speedboat Dec 1, 2016
js Adding no cookies reset option Jul 31, 2018
lib Adding no cookies reset option Jul 31, 2018
loader Fix all errcheck issues Jul 5, 2018
packaging Builds deb, rpm, msi and chocolatey packages (#675) Jun 21, 2018
release notes Update the release notes and Gopkg.lock Aug 3, 2018
samples Removing commented code on the sample May 2, 2018
stats Merge pull request #716 from loadimpact/cloud-errmsg-fixes Jul 23, 2018
ui Fix the linter issue Aug 3, 2018
vendor Update spf13/pflag to fix spf13/cobra breakage Jul 11, 2018
.dockerignore remove node docker stage, remove web ui Oct 19, 2017
.editorconfig [fix] Gah, that broke every yml file mentioning speedboat Dec 1, 2016
.gitignore Builds deb, rpm, msi and chocolatey packages (#675) Jun 21, 2018
.gitmodules Embedding JS dependencies as Go code (#658) Jun 4, 2018
API.md REBRANDING: speedboat -> k6 Dec 1, 2016
CODE_OF_CONDUCT.md [docs] CONTRIBUTING.md and CODE_OF_CONDUCT.md Feb 8, 2017
CONTRIBUTING.md Update contributing guidelines with CLA information Jun 5, 2018
Caddyfile [fix] Fixed Caddy Jul 29, 2016
Dockerfile Update Dockerfile Jul 6, 2018
Dockerfile.grafana Converted the POST parameters to JSON (isDefault didn't work with for… Apr 20, 2017
Dockerfile.influxdb Create Grafana's data source through the API Apr 20, 2017
Gopkg.lock Update the release notes and Gopkg.lock Aug 3, 2018
Gopkg.toml Try fixing the latest dep issues Jul 11, 2018
LICENSE.md Added AGPL license info Dec 13, 2016
Makefile Embedding JS dependencies as Go code (#658) Jun 4, 2018
README.md Merge pull request #683 from qoomon/patch-1 Jul 12, 2018
Vagrantfile REBRANDING: speedboat -> k6 Dec 1, 2016
appveyor.yml Fix various dep stable installation issues Jul 11, 2018
build-release.sh Embedding JS dependencies as Go code (#658) Jun 4, 2018
demo.svg New demo recording Jan 17, 2018
docker-compose.yml Update docker-compose with the new k6 version call Nov 23, 2017
gometalinter.json Embedding JS dependencies as Go code (#658) Jun 4, 2018
jsdoc.json [docs] Working on tutorials Oct 3, 2016
k6.sublime-project REBRANDING: speedboat -> k6 Dec 1, 2016
logo.png Switch back to png logo Jan 15, 2018
main.go Add missing copyright notice to files Jan 17, 2018

README.md

k6

Like unit testing, for performance

A modern load testing tool for developers and testers in the DevOps era.

Github release Build status Go Report Card Codecov branch
@k6_io on Twitter Slack channel

Download · Documentation · Community


k6 is a modern load testing tool, building on Load Impact's years of experience in the load and performance testing industry. It provides a clean, approachable scripting API, local and cloud execution, with command & control through CLI or a REST API.

This is how load testing should look in the 21st century.

Menu

Features

There's even more! See all features available in k6.

Install

Mac

brew install loadimpact/k6/k6

Other Platforms

Grab a prebuilt binary from the Releases page.

Install the binary in your PATH to run k6 from any location.

Docker

docker pull loadimpact/k6

Build from source

To build from source you need Git and Go (1.10 or newer). Follow these instructions:

  • Run go get github.com/loadimpact/k6 which will:
    • git clone the repo and put the source in $GOPATH/src/github.com/loadimpact/k6
    • build a k6 binary and put it in $GOPATH/bin
  • Make sure you have $GOPATH/bin in your PATH
  • Tada, you can now run k6 using k6 run script.js

Quick start

k6 works with the concept of virtual users (VUs), which run scripts - they're essentially glorified, parallel while(true) loops. Scripts are written using JavaScript, as ES6 modules, which allows you to break larger tests into smaller and more reusable pieces, which makes it easy to scale across an organization.

Scripts must contain, at the very least, a default function - this defines the entry point for your VUs, similar to the main() function in many other languages:

export default function() {
    // do things here...
}

"Why not just run my script normally, from top to bottom", you might ask - the answer is: we do, but code inside and outside your default function can do different things.

Code inside default is called "VU code", and is run over and over for as long as the test is running. Code outside of it is called "init code", and is run only once per VU.

VU code can make HTTP requests, emit metrics, and generally do everything you'd expect a load test to do - with a few important exceptions: you can't load anything from your local filesystem, or import any other modules. This all has to be done from init code.

There are two reasons for this. The first is, of course: performance.

If you read a file from disk on every single script iteration, it'd be needlessly slow; even if you cache the contents of the file and any imported modules, it'd mean the first run of the script would be much slower than all the others. Worse yet, if you have a script that imports or loads things based on things that can only be known at runtime, you'd get slow iterations thrown in every time you load something new.

But there's another, more interesting reason. By forcing all imports and file reads into the init context, we design for distributed execution. We know which files will be needed, so we distribute only those files. We know which modules will be imported, so we can bundle them up from the get-go. And, tying into the performance point above, the other nodes don't even need writable filesystems - everything can be kept in-memory.

As an added bonus, you can use this to reuse data between iterations (but only for the same VU):

var counter = 0;

export default function() {
    counter++;
}

Running k6

First, create a k6 script to describe what the virtual users should do in your load test:

import http from "k6/http";

export default function() {
  http.get("http://test.loadimpact.com");
};

Save it as script.js, then run k6 like this:

k6 run script.js

(Note that if you use the Docker image, the command is slightly different: docker run -i loadimpact/k6 run - <script.js)

For more information on how to get started running k6, please look at the Running k6 documentation. If you want more info on the scripting API or results output, you'll find that also on https://docs.k6.io.


Need help or want to contribute?

Types of questions and where to ask: