Install k6 Load Testing Tool on Ubuntu 24.04

Install k6 Load Testing Tool on Ubuntu 24.04

The k6 is an open-source load testing tool designed to help developers and DevOps teams evaluate the performance and reliability of their applications. This tutorial demonstrates how to install k6 load testing tool on Ubuntu 24.04.

Install k6

Get the latest k6 version from its GitHub repository and store the result in a variable:

K6_VERSION=$(curl -s "https://api.github.com/repos/grafana/k6/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Download k6 archive file using version determined earlier:

wget -qO k6.tar.gz https://github.com/grafana/k6/releases/latest/download/k6-v$K6_VERSION-linux-amd64.tar.gz

Create temporary directory and extract a tar.gz file:

mkdir k6-temp
tar xf k6.tar.gz --strip-components=1 -C k6-temp

Move executable to /usr/local/bin directory:

sudo mv k6-temp/k6 /usr/local/bin

To see the k6 version, use the following command:

k6 --version

Clean up unneeded archive and directory:

rm -rf k6.tar.gz k6-temp

Testing k6

First, create a JavaScript file for your k6 test script:

nano simple.js

Write your k6 test script. Here's an example script:

import http from "k6/http";

export const options = {
  vus: 10,
  iterations: 50,
};

export default function () {
  http.get("http://192.168.0.174");
}

To execute the test using k6, run the following command:

k6 run simple.js

The k6 will create 10 virtual users. Each virtual user will make GET requests to the specified URL until the total number of iterations reaches 50. The test will distribute these 50 iterations across the 10 virtual users. Since there are 50 iterations and 10 virtual users, on average, each virtual user will make 5 requests.

Result example:

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: simple.js
        output: -

     scenarios: (100.00%) 1 scenario, 10 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 50 iterations shared among 10 VUs (maxDuration: 10m0s, gracefulStop: 30s)


     data_received..................: 42 kB  27 MB/s
     data_sent......................: 3.8 kB 2.4 MB/s
     http_req_blocked...............: avg=58.37µs  min=442ns   med=2.15µs   max=339.48µs p(90)=267.78µs p(95)=320.05µs
     http_req_connecting............: avg=34.36µs  min=0s      med=0s       max=210.45µs p(90)=166.14µs p(95)=189.7µs 
     http_req_duration..............: avg=133.42µs min=43.91µs med=122.56µs max=335.33µs p(90)=209.66µs p(95)=271.17µs
       { expected_response:true }...: avg=133.42µs min=43.91µs med=122.56µs max=335.33µs p(90)=209.66µs p(95)=271.17µs
     http_req_failed................: 0.00%  ✓ 0            ✗ 50
     http_req_receiving.............: avg=28.27µs  min=6.38µs  med=25.85µs  max=96.42µs  p(90)=51.1µs   p(95)=57.26µs 
     http_req_sending...............: avg=14.66µs  min=2.04µs  med=9.81µs   max=70.27µs  p(90)=43.24µs  p(95)=46.72µs 
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=90.48µs  min=28.32µs med=86.63µs  max=249.63µs p(90)=143.92µs p(95)=180.65µs
     http_reqs......................: 50     31591.643884/s
     iteration_duration.............: avg=258.4µs  min=66.61µs med=159.06µs max=814.12µs p(90)=724.75µs p(95)=731.03µs
     iterations.....................: 50     31591.643884/s


running (00m00.0s), 00/10 VUs, 50 complete and 0 interrupted iterations
default ✓ [======================================] 10 VUs  00m00.0s/10m0s  50/50 shared iters

Uninstall k6

To uninstall k6, delete the associated file:

sudo rm -rf /usr/local/bin/k6

Leave a Comment

Cancel reply

Your email address will not be published.