Capture parallel request response time

Hi Team,

I want to capture the response time for a parallel request.

image

Hope we can simulate the parallel request with the help of http.batch

For individual requests, we can call the res.timing.duration to capture the timing. And summing up the parallel request response time individually is not the correct option.

Then how to capture the current response time for the parallel request ??

Hello, @Gerard!
Maybe tags can help you?
In the example responses.timings.connecting but you can choose the desired method

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

// Create treads in which we record for example time.

const TredHTML = new Trend('html');
const TredCSS = new Trend('css');
const TredIMAGES = new Trend('images');

export default function () {
  const responses = http.batch([
    ['GET', 'https://test.k6.io', null, { tags: { ctype: 'html' } }],
    ['GET', 'https://test.k6.io/style.css', null, { tags: { ctype: 'css' } }],
    ['GET', 'https://test.k6.io/images/logo.png', null, { tags: { ctype: 'images' } }],
  ]);
  check(responses[0], {
    'main page status was 200': (res) => res.status === 200,
  });

//response[number in array] it is numbers of corresponding numbers in request .

  TredHTML.add(responses[0].timings.connecting, { ctype: "html" });
  TredCSS.add(responses[1].timings.connecting, { ctype: "css" });
  TredIMAGES.add(responses[2].timings.connecting, { ctype: "TredIMAGES" });

}

1 Like