How to use executor: 'shared-iterations' and stages together o simulate ramp-up scenario?

Hi all, i want to know how to use executor: ‘shared-iterations’ and stages together to simulate ramp-up scenario? Can anyone provide an example?

Hi @sunnini

Thanks for reaching out!

It sounds like the Ramping arrival rate executor would achieve exactly what you’re looking for? Depending on what your specific goal is, the Ramping VUs might also prove useful?

If that’s not the case, could you please elaborate on why you specifically don’t use them, and what your use case/scenario is, so I can try to support you.

Cheers :bowing_man:

I want to simulate a real continuous users increasing scenario, instead of starting constant VUS. But my script also must use executor: ‘shared-iterations’ to retrieve unique data from csv. How to use executor: ‘shared-iterations’ and stages together, any solution?

My understanding of what you’re trying to achieve, from your description, is: to simulate a ramping number of users interacting with your target, while using a predefined set of users to do that. Your initial approach was to try to achieve that by mixing ramping (modifying linearly the number of VUs at play), and shared-iterations (to make sure to execute exactly N iterations for a data set with N entries) executors. Is that correct?

Based on the assumption this is what you’re trying to achieve, I came up with the following script demonstrating how to use the Ramping VU executor hand in hand with the execution module’s ability to give you the current iteration number, to both having VUs ramping, and being able to have them pick a user from the data set based on the iteration number (to be sure that we go through all of them, sequentially):

import { sleep } from "k6";
import { SharedArray } from "k6/data";
import { scenario } from "k6/execution";

const usersJSON = new SharedArray("users", function () {
  return JSON.parse(
    open("./userdata.json", "r")

export const options = {
  discardResponseBodies: true,
  scenarios: {
    users: {
      executor: "ramping-vus",
      startVUs: 0,
      stages: [
        { duration: "20s", target: 10 },
        { duration: "10s", target: 0 },
      gracefulRampDown: "0s",

export default function () {
  // As demonstrated in
  // Plus, applying a modulo to the index of the user in the array to stay
  // in bounds of the users array.
  const idx = scenario.iterationInTest % usersJSON.length;
  const user = usersJSON[idx];

From your explanation, I had a hunch you might want to interrupt the execution once all the users from the data set have been used? If that’s the case, you should be able to check if scenario.iterationInTest == dataset.length and stop the execution there.

Let me know if that’s helpful :bowing_man:

Thanks a lot @oleiade , I think your example is very helpful to me and can fully satisfy my case, you mentioned when scenario.iterationInTest == dataset.length and stop the execution there, i want to know how to interrupt the execution ?

You’re very welcome!

I was thinking specifically of the execution module’s abort function which will stop the test all in all. The twist is that it will make k6 consider the test aborted, and exit with code 108, as it is originally designed to help exit unrecoverable scenarios, but if you handle that explicitly, you should be good to go :+1:

thanks your pointers @oleiade , very useful to me!

1 Like