Hi Aleks. Weāll need more info to help debug this. Can you share your script file so that we can see your checks, and the output where you see a 98% failure rate?
If you canāt provide this here, feel free to email support@k6.io or message me directly here on the forums.
Itās always a good idea to check the contents of a HTTP 200 to ensure it contains the expected response. The web developer is not obliged to send any particular status code, even when thereās an error.
A HTTP 200 with an error message in the response body is essentially the equivalent of a handled exception, whereas the unhandled ones tend to be in the 4xx-5xx status code range.
I have a question.
It may be off-topic, and if it is I will gladly create a new question.
Is there any way to introduce a delay , even better, a random delay, between iterations?
The delay should not be seen as part of the iteration, and should not affect iteration duration metric.
Unfortunately not at the moment, sorry. The only way to introduce random delay in an iteration would be to use sleep() with some Math.random() calculation, and that would alter iteration_duration.
There are easy workarounds though. You can wrap your ābusinessā code in a group() and leave the sleep() call out of it, and then look only at the group_duration metric, ignoring iteration_duration.
Alternatively, you can define your own custom Trend metric and measure the iteration duration yourself by subtracting Date.now() values. Then you can either do the subtracting before any sleep() calls, or if you have multiple such calls sprinkled in your code, you can keep track of how long you sleep in the iteration and subtract that from the total sleep value from your measurement before you .add() it to the custom metric.
Ned beat me to it! But hereās some sample code for generating a custom Trend that can be used to accumulate group response times without also including the sleep response times:
import http from 'k6/http';
import { group, sleep } from 'k6';
import { Trend } from 'k6/metrics';
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
const groupDurationTotal = new Trend("group_duration_total", true); // true indicates we're adding time values (assumed to be in milliseconds)
let total;
export default function () {
total = 0;
total += group("group 1", function () {
const startTime = Date.now();
// http.get (or whatever) - the below sleep is just for testing
sleep(randomIntBetween(2, 5));
const duration = Date.now() - startTime;
console.log('group 1 duration: ' + duration);
// sleep representing "think time" that might not be interesting to include in group_duration_total
sleep(randomIntBetween(2, 5));
return duration;
});
total += group("group 2", function () {
// etc
});
total += group("group 3", function () {
// etc
});
console.log('Script finished. Total time: ' + total);
groupDurationTotal.add(total);
}