VUs / iteration task assignment

VUs / iteration task assignment

Hello,
I have a list / array of 10 points, how can I assign these 10 points to an iteration if there are several VUs?

How can I distribute these 10 points over the iterations

import { sleep } from 'k6';

export const options = {
  vus: 3,
  iterations: 10,
};

export default function () {
  console.log(`VU: ${__VU}  -  ITER: ${__ITER}`);
  if (__VU === 1) {
    sleep(1);
  };
}
Report
INFO[0000] VU: 1  -  ITER: 0                             source=console
INFO[0000] VU: 2  -  ITER: 0                             source=console
INFO[0000] VU: 2  -  ITER: 1                             source=console
INFO[0000] VU: 2  -  ITER: 2                             source=console
INFO[0000] VU: 2  -  ITER: 3                             source=console
INFO[0000] VU: 2  -  ITER: 4                             source=console
INFO[0000] VU: 2  -  ITER: 5                             source=console
INFO[0000] VU: 3  -  ITER: 0                             source=console
INFO[0000] VU: 3  -  ITER: 1                             source=console
INFO[0000] VU: 3  -  ITER: 2                             source=console

Setting options.vus + options.iterations will result in a shared-iterations executor: https://k6.io/docs/using-k6/scenarios/executors/shared-iterations/

In that executor, the VUs greedily try to execute iterations, i.e. as soon as a VU finishes an iteration, it will start another one from the total count, until all iterations are done. So different VUs might execute a different number of iterations during the test run. Until Add k6/execution JS module by imiric · Pull Request #1863 · k6io/k6 · GitHub is done, hopefully at the end of this month, there isn’t an easy way to partition iterations between VUs more fairly, and even after, depending on your use case, it might still not be enough.

For now, I’d suggest using separate scenarios or the per-vu-iterations executor, which allows you to run a specific number of iterations per VU.