Creating Performance Tests (k6)

Grafana k6 is an open-source load testing tool. BlazeMeter engines run on Taurus which supports various open-source testing tools including k6. Upload your k6 JavaScript or TypeScript files to BlazeMeter to run your tests and receive performance reports. You can upload additional files that will be distributed to every BlazeMeter test engine.

This article covers the following topics:

Example

Copy

k6 sample test

import http from 'k6/http';
import {sleep} from 'k6';

export default function () {
    http.get('https://blazedemo.com/');
    // Injecting sleep
    // Sleep time is 500ms. Total iteration time is sleep + time to finish request.
    sleep(0.5);
}

export const options = {
    vus: 10,             // number of virtual users (concurrent)
    duration: '600s',    // total test duration
    stages: [
        {duration: '10.0s', target: 5},
        {duration: '20.0s', target: 10},
        {duration: '570.0s', target: 15}
    ],
};

Create a k6 Performance Test in BlazeMeter

  1. In the main menu, click the Performance tab.
  2. Click Create Test.
  3. Select a project.
  4. Click Performance Test.
    The Configuration tab for the test opens.
  5. Upload the k6 JavaScript or TypeScript file. Either click the plus button and browse to the file on your hard drive, or drag and drop the file into the upload area.
    The script is detected as test type: k6.

Configure your k6 test

If you do not provide a Taurus YAML file, you configure options in the BlazeMeter web interface under Load Configuration. Alternatively, provide a Taurus YAML file with configuration options that loads a valid k6 scenario.

In your k6 JavaScript or TypeScript file, you can provide script options. BlazeMeter always runs k6 with at least one of the k6 command line options --vus, --iterations, or --durations. Consider that BlazeMeter may override some of the non-default k6 executors. For more information about options, see the k6 options docs (grafana.com).

Copy
execution:
  concurrency: 5000 # mandatory, number of K6 workers
  hold-for: 10m # mandatory, execution duration
  scenario: test
  locations:
    eu-central-1: 2
    us-west-2: 1

scenarios:
  test:
    script: k6-performance-test-for-blazemeter.js

Edit k6 tests in the BlazeMeter GUI

To edit the script, either upload a file with the same name to replace the previous one, or edit the JavaScript or associated Taurus YAML files in the built-in editor directly in the BlazeMeter web interface.

You can click the actions buttons next to a file to download, copy, or delete uploaded scripts.

Run k6 Tests in BlazeMeter

  1. Name your test.

  2. (Optional) Click Debug Test to validate your test configuration.
    For more information about debugging, see Debug Test: Low-Scale Test Run and Enhanced Logging.

  3. Click Run Test.