To track the number of VUs for each flow across time, I have tried using a custom metric like this
const flows = new Counter('flows');
export default function() {
if (__VU % 10 ==1) {
// type and start tags are added to prevent points overwriting each other https://docs.influxdata.com/influxdb/v0.13/troubleshooting/frequently_encountered_issues/#writing-duplicate-points
flows.add(+1, {name: 'flow 1', type: 'start', vu: __VU});
flow1()
flows.add(-1, {name: 'flow 1', type: 'end', vu: __VU});
} else {
flows.add(+1, {name: 'flow 2', type: 'start', vu: __VU});
flow2()
flows.add(-1, {name: 'flow 2', type: 'end', vu: __VU});
}
}
But this does not work because I think for some VUs, the script ends before they register exiting. Looking at the output in influxdb confirms my suspicion as I have 128 starts and 58 ends.
Is it possible to achieve this using another approach?
your approach seems fine to me, though I couldn’t reproduce your issue of different number of start and end metrics, and my tests had the same number of both:
This might mean that your iterations are being cut short for some reason, or that there are errors submitting the metrics to InfluxDB. Did you receive any errors in the test output? What command did you use to run it?
Though if you just want to track the number of VUs for each flow across time, you only need the “+1” (type: start) metrics to do so.
After some internal discussion, the reason you’re seeing different start and end metric counts is because of the way stages currently works. When ramping down VUs k6 might interrupt some iterations without waiting for them to complete. See issue #879. In the upcoming #1007 major overhaul there will be new gracefulStop and gracefulRampDown settings which will allow you to control this better.
For now, instead of using custom metrics, you might get more accurate results if you use groups to separate your flows and the resulting group_duration metric if you want to keep track of the duration of each flow.