Performance Testing

Setups and Configs

This documentation guides you through configuring and setting up the K6 automation testing tool for performance testing. You'll learn how to install K6, customize configurations, and manage test settings to optimize your performance testing process.

Prerequisites

  1. Knowledge of JavaScript
  2. Understanding of performance testing concepts (e.g., load testing, stress testing).
  3. Node.js installed on your machine.

Installation

Installation has been diveded into multiple sections for different platforms. k6 has packages for Linux, Mac, and Windows. Alternatively, you can use a Docker container or a standalone binary.

MacOS

For installation in MacOS, you should have homebrew installed on your system.

Once homebrew is installed, execute the command given below:

brew install k6

Windows

If you use the Windows Package Manager, install the official packages from the k6 manifests

winget install k6 --source winget

Alternatively, for windows you can download and run the latest official installer.

If you face any trouble during the installation, kindly refer to this documentation by grafana.com.

First Test Script

Here's a simple test script in JavaScript for K6:

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

export let options = {
    vus: 20,
    duration: '10s',
}

export default function () {
    http.get('https://test.k6.io');
    sleep(1);
}

This K6 script performs a basic load test by making HTTP GET requests to https://test.k6.io and simulating a user pause between requests. Here's a breakdown of what the script does:

  1. Importing Modules:
    • import http from 'k6/http';: Imports the HTTP module from K6 for making HTTP requests.
    • import { sleep } from 'k6';: Imports the sleep function from K6 for adding delays between operations.
  2. Options Configuration:
    • export let options = { vus: 20, duration: '10s' }: Sets the test configuration.
      • vus: 20: Specifies that the test will run with 20 virtual users (VUs).
      • duration: '10s': Specifies that the test will run for a total duration of 10 seconds.
  3. Default Function:
    • The export default function () defines the default function that K6 runs for each virtual user (VU) iteration.
  4. HTTP GET Request:
  5. Sleep:
    • sleep(1);: Pauses the execution for 1 second to simulate a user thinking time or delay between actions.

Executing the Test

To execute the test script, run the command given below:

k6 run [filename.js]

Eg,

k6 run script.js

Analysing the Result

After executing the above test, you'll see an output metrics similar to the screenshot attached below:

Here are a few key points that we can analyze from the results provided:

  1. HTTP Request Metrics
    • Total Requests: 159 requests at 14.31 requests per second
    • Request Failures: 0.00% (0 failed, 159 successful)
    • The high request success rate (100%) indicates stable performance with no errors during the test.
  2. Response Time Metrics
    • Average Duration: 247.63 ms
    • Minimum Duration: 224.36 ms
    • Median Duration: 232.09 ms
    • Maximum Duration: 468.73 ms
    • 90th Percentile (p90): 239.31 ms
    • 95th Percentile (p95): 448.65 ms
    • The average, median, and percentile metrics provide a comprehensive view of the response times, highlighting overall performance and potential outliers.
  3. Connection Timing
    • Blocked: Average 67.96 ms (min: 2 µs, max: 1.45 s)
    • Connecting: Average 36 ms (min: 0 s, max: 1.21 s)
    • TLS Handshaking: Average 31.76 ms (min: 0 s, max: 268.67 ms)
    • These metrics help identify delays during connection establishment and secure handshake, which can impact overall performance.
  4. Request Processing
    • Receiving: Average 15.81 ms (min: 13 µs, max: 232.08 ms)
    • Sending: Average 32.66 µs (min: 10 µs, max: 333 µs)
    • Waiting (Time to First Byte): Average 231.78 ms (min: 223.81 ms, max: 246.41 ms)
    • These metrics show the time spent in different phases of the request lifecycle, helping pinpoint specific areas of latency.

You can now modify the script or create a new one to test and explore more concepts of Performance testing using k6. To know more, refer to the official documentation about k6 by grafana.com.


Copyright © 2024