How do you use group_duration?

I’ve set up a test where I get several items, and I want to measure the time it takes to complete all the requests. From reading the documentation, I should be able to use group_duration. But, I cannot figure out how to do it… Can someone please provide an example using group_duration?

group("RSS", function () {
	let req, res;
	req = [{
		"method": "get",
		"url": "https://www.test.com/page.html",
	}, {
		"method": "get",
		"url": "https://www.test.com/style.css",
	}];
	res = http.batch(req);
});

Hi,

group_duration is a metric emitted when you use k6.group(), and you can see it in the results output if you use the --out option. See the example for JSON.

Unfortunately, this metric is not exposed to the JS runtime, so you can’t directly run checks on it, but I see how it could be useful. I’ll bring this up to the team and will let you know if it can be done.

In the meantime, see this great SO answer by @mstoykov. His first solution would work for your use case, just wrap your http.batch() call inside the timer function, and do the regular check on the returned elapsed time.

Let me know if you have issues with this.

2 Likes