Firewall test measuring connection usage with k6

Hey folks. I’m using k6 to send load across a network to test firewall policy(s). One particular policy is Connection Reuse which I believe will cause the firewall to work harder if I disable connection reuse in k6.

My question is this. Does anyone have an example of measuring connection reuse? How do I actually know that noVUConnectionReuse or noConnectionReuse are “true”. I do not see any obvious metrics in the k6 default metrics package? Should I investigate creation of a custom metric to measure and possibly check connection usage?

thx

If a network connection is reused, the value of the http_req_connecting metric and the timings.connecting property of the Response object will be 0.

Try this script with the various connection reuse options to see what I mean:

import http from 'k6/http';
import exec from 'k6/execution';

export let options = {
    vus: 1,
    iterations: 2,

    // Uncomment these:
    // noConnectionReuse: true,
    // noVUConnectionReuse: true,
};

export default function () {
    let resp1 = http.get('https://test.k6.io');
    let resp2 = http.get('https://test.k6.io');

    console.log(`iteration=${exec.scenario.iterationInTest}, connecting1=${resp1.timings.connecting}ms, connecting2=${resp2.timings.connecting}ms`);
}

Hey @ned thanks for the response. I think I get it. You printed out the representation for 2 metrics. 1 metrics is the connection itself. When the connection is made on the 1st iteration its default connection metrics (the 2nd metric in ms) are recorded. When the option noConnectionReuse: true is set each iteration forces the use of a new connection which will in turn get a set of connection metrics. Meaning no new “connect” metrics will be recorded because the connection persists open.

is the above a valid approximation of what is occurring in the k6 client?

I think I would have seen this evidence if I were looking at a trendline rather than a metrics rollup. I’ll try that as well.

Thanks again

is the above a valid approximation of what is occurring in the k6 client?

Not quite, specifically this part is incorrect:

… You printed out the representation for 2 metrics. …

The script prints the value of the same metric (http_req_connecting, accessed through Response.timings.connecting) for 4 different HTTP requests, 2 requests in each of the 2 iterations.

If you don’t change any of the default options, only the first request in the first iteration will have a value for connecting, since only it will establish the network connection, all of the other requests will reuse it.

If you have noVUConnectionReuse enabled, k6 will reuse connections within an iteration, but will close any open connections when an iteration ends. So, the first requests in iteration 1 and iteration 2 will have to establish a network connection (and so have a non-zero connecting value), while the second requests will reuse it.

noConnectionReuse will prevent any connection reuse between requests whatsoever.

1 Like