Distributed load testing with Grafana K6

This tutorial shows how to distribute Grafana K6 tests across multiple nodes.

Illustration grafana devops tutorial

Running large load tests with Grafana K6 often requires distributing test executions across multiple nodes. This approach is necessary when a single node lacks the capacity to generate the target load or when you need to simulate load from multiple geographic locations.

This tutorial shows how to distribute existing Grafana K6 tests across multiple nodes using Step.

Prerequisites

Test scenario

For the sake of this tutorial, we’ll simulate 10 parallel users visiting our demo online store. The user journey that we’ll simulate consists of the following actions: navigate to the online store, search for a product, add it to the shopping cart, and complete the order.

For this simulation we have an existing K6 test: K6 sample test

Checkout the sample

Clone the sample project from GitHub:

  git clone https://github.com/exense/step-samples
  

Navigate to the sample directory:

  cd step-samples/automation-packages/load-testing-k6/
  

Project structure

Automation package descriptor

The automation-package.yaml file located at the root of our sample project serves as the automation package descriptor, outlining the details of our load test scenario:

  ---
schemaVersion: 1.0.0
name: "load-testing-k6-automation-package"
keywords:
  # Declare a Keyword which runs the K6 test 'opencart-test.js' with 1 VU and 10 iterations
  - K6:
      name: 'OpenCart Journey 10x'
      vus: 1
      iterations: 10
      scriptFile: "k6-tests/opencart-test.js"
plans:
  - name: "Load Testing OpenCart"
    # The agents (workers) are automatically determined and provisioned upon execution
    agents: auto_detect
    root:
      testScenario:
        children:
          # Declare a ThreadGroup that distributes the execution of the Keyword (and thus the K6 test)
          - threadGroup:
              # Distributes across 5 workers
              users: 5
              # Each worker executes the Keyword 10 times (which leads to 10 x 100 = 1000 executions of the script 'opencart-test.js' per worker)
              iterations: 100
              children:
                - callKeyword:
                    # Call the defined Keyword
                    keyword: "OpenCart Journey 10x"
  

For more details about the syntax, refer to the official documentation of the Automation Package Descriptor.

K6 test script

The K6 test simulating our user journey is located in k6-test/opencart-test.js. It is a standard K6 script written in JavaScript.

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

export default function () {
    // Home page
    var r = http.get('https://opencart-prf.exense.ch/',
        { tags: { name: "OpenCart Home" } });
    check(r, {
        'response is status 200': (r) => r.status === 200,
    });

    // Adding a Macbook
    r = http.get('https://opencart-prf.exense.ch/macbook',
        { tags: { name: "OpenCart Add MacBook - Step 1" } });
    check(r, {
        'response is status 200': (r) => r.status === 200,
    });
  

For more details about K6 scripts, refer to the official documentation of the K6.

Execute locally

Optionally, you can run the K6 test locally:

  cd k6-tests
k6 run opencart-test.js
# Navigate back to the base directory
cd ..
  

You can also run the full Automation Package plan locally with the Step CLI. In the base directory load-testing-k6:

  step ap execute --local
  

Note that this will launch the full load test from the machine where the command is executed. You may want to change the automation package descriptor to use a lower number of simulated users and/or iterations when launching the test this way.

Execute in Step

Before executing the test in Step, you’ll need the URL of your Step instance and an API key. For instructions on generating an API key, refer to Generate an API Key.

To execute the test in Step, run the following command at the root of the sample directory load-testing-k6:

  step ap execute --stepUrl=https://<Hostname of your Step cluster> --projectName=Common --token=<Your API key>
  

This command uploads the content of the automation package to Step and triggers the execution of the plans contained in the automation package descriptor.

Refer to the official documentation of the Step CLI for more details.

The execute command outputs a direct link to the execution report in Step:

  Execute automation package with parameters: {}
The automation package source is ...\step-samples\automation-packages\load-testing-k6
Preparing AP archive: ...\Temp\stepcli97053271864881569\load-testing-k6.stz
Execution(s) started in Step:
- 'Load Testing OpenCart' (https://<Host name of your Step cluster>/#/executions/66fd1171fda0775568ae802f)
  Waiting for execution(s) to complete...
Execution 'Load Testing OpenCart' (https://<Host name of your Step cluster>/#/executions/66fd1171fda0775568ae802f) succeeded. Result status was PASSED
  

Analyze the result

Open the execution report in Step by clicking the direct link printed by the execute command above.

In the Performance tab, you can explore the performance metrics:

Performance view of the execution report
Performance view of the execution report

There you’ll find all metrics relative to the transactions of your K6 test:

  • The metrics reported by K6:
    • iteration_duration: the duration of each iteration i.e. of each execution of the test script
    • http_req_duration: the duration of each HTTP request
    • Refer to the Metrics page of the official K6 documentation for more details
  • The total execution time of our Keyword: “OpenCart Journey 10x” which executes the K6 script 10 times according to the configuration of the automation package and thus correspond to the duration of 10 user journeys
Note: The total execution time of the Keyword “OpenCart Journey 10x” contains the time spent in the script plus the time spent starting the K6 process. This is useful for diagnosis purposes. For application performance measurements, use the metrics reported by K6.
Illustration for Using Step with Grafana
Using Step with Grafana

This article demonstrates how to connect Grafana to data generated by Step.

Illustration for Setting up system monitoring with a Step agent
Setting up system monitoring with a Step agent

This article demonstrates how to set up distributed system monitoring using Keyword executions, and analyze the results as measurements.

Illustration for NET tutorials: Microsoft Office automation with Step
NET tutorials: Microsoft Office automation with Step

This tutorial demonstrates how to automate interaction with Microsoft Office applications using the Office Interop Assembly.

Illustration for JUnit Plan Runner
JUnit Plan Runner

This article provides documentation for how to integrate JUnit tests into Step.

Illustration for How to monitor services availability and performance
How to monitor services availability and performance

This tutorial demonstrates how Step can be used to monitor services, availability and performance metrics.

Illustration for .NET tutorials: AutoIt with Step
.NET tutorials: AutoIt with Step

This tutorial demonstrates how to utilize the AutoIt C# binding to automate interactions with Windows applications.

Illustration for Android Testing using Step and Appium
Android Testing using Step and Appium

This article demonstrates the automation of mobile applications on Android using the Appium framework.

Illustration for Browser-based automation with Step and Selenium
Browser-based automation with Step and Selenium

This article defines three Keywords which will be used in browser-based automation scenarios, using Step and Selenium, as general drivers.

Illustration for Load Testing with Cypress
Load Testing with Cypress - advanced

This tutorial shows you how to efficiently set up a browser-based load test using existing Cypress tests in the Step automation platform.

Illustration for Adding and Configuring New Agents
Adding and Configuring New Agents

In this short tutorial, we show how to quickly implement a simple browser-based load test based on Cypress scripts in Step.

Illustration for Load Testing with Playwright
Load Testing with Playwright using Step UI

This tutorial shows you how to set up a browser-based load test using existing Playwright tests in the Step UI.

Illustration for Basic Keyword Development
Basic Keyword Development

This article explains Keywords in Step and demonstrates how to create simple ones.

Illustration for Designing functional tests
Designing functional tests

This tutorial demonstrates the design, execution, and analysis of functional tests using the web interface of Step.

Illustration for Robotic Process Automation (RPA) with Selenium
Robotic Process Automation (RPA) with Selenium

This tutorial will demonstrate how to use Step and Selenium to automate various browser tasks.

Illustration for Robotic Process Automation (RPA) with Cypress
Robotic Process Automation (RPA) with Cypress

This tutorial demonstrates how to use Step and Cypress to automate various browser tasks.

Illustration for Synthetic Monitoring with Selenium
Synthetic Monitoring with Selenium

This tutorial demonstrates how Selenium automation tests can be turned into full synthetic monitoring using Step.

Illustration for Load Testing with Cypress
Load Testing with Cypress

In this tutorial, you'll learn how to reuse existing Cypress tests to quickly set up and run a browser-based load test using the automation as code approach.

Illustration for Load Testing with Cypress
Load Testing with Serenity BDD and Cucumber

In this tutorial, you'll learn how to reuse existing tests written with Serenity BDD and Cucumber for load testing.

Illustration for Synthetic Monitoring with Cypress
Synthetic Monitoring with Cypress

This tutorial demonstrates how Cypress automation tests can be turned into full synthetic monitoring using the automation as code approach.

Illustration for Load Testing with Cypress
Load Testing with Cypress using Step UI

In this tutorial, you'll learn how to reuse existing Cypress tests to quickly set up and run a browser-based load test using the Step UI.

Illustration for Load Testing with Selenium
Load Testing with Selenium

This tutorial demonstrates how to leverage existing Selenium tests to set up and execute browser-based load tests, following a full code-based approach.

Illustration for Load Testing with Selenium
Load Testing with Selenium using Step UI

This tutorial demonstrates how to set up a browser-based load test in the Step UI using existing Selenium tests.

Illustration for Synthetic Monitoring with Playwright
Synthetic Monitoring with Playwright

This tutorial demonstrates how Playwright automation tests can be turned into full synthetic monitoring using Step.

Illustration for Synthetic Monitoring with Cypress
Synthetic Monitoring with Cypress using Step UI

This tutorial demonstrates how Cypress automation tests can be turned into full synthetic monitoring using the Step UI.

Illustration for Robotic Process Automation (RPA) with Playwright
Robotic Process Automation (RPA) with Playwright

This tutorial will demonstrate how to use Step and Playwright to automate various browser tasks.

Illustration grafana devops tutorial
Distributed load testing with JMeter

This tutorial shows how to distribute JMeter tests across multiple nodes.

Illustration for Load Testing with Playwright
Load Testing with Playwright for Java

In this tutorial, you'll learn how to reuse existing Playwright tests written in Java to quickly set up and run a browser-based load test using the automation as code approach.

Illustration for playwright synthetic monitoring in a devops workflow
DevOps Synthetic Monitoring with Playwright - Advanced

This tutorial demonstrates how Playwright tests can be reused for synthetic monitoring of a productive environment in a DevOps workflow

Illustration for playwright synthetic monitoring in a devops workflow
DevOps Synthetic Monitoring with Playwright

This tutorial demonstrates how Playwright tests can be reused for synthetic monitoring of a productive environment in a DevOps workflow

Illustration for okhttp devops
Protocol-based load testing with okhttp

In this tutorial you'll learn how to quickly set up a protocol-based load test with okhttp

Illustration for playwright devops
Continuous end-to-end testing

Learn how to set up continuous end-to-end testing across several applications based on Playwright tests in your DevOps pipeline using Step

Illustration for playwright devops
Continuous load testing with Playwright

Learn how to quickly set up continuous browser-based load testing using Playwright tests in your DevOps pipeline

Want to hear our latest updates about automation?

Don't miss out on our regular blog posts - Subscribe now!

Image of a laptop device to incentivize users to subscribe