How to perform a load test with ramp up&down with fixed amount of iterations?

Hello :slight_smile: I have a big script with over 600 requests in default function and I need each VU to run 1 iteration end-to-end with ramp-up period for example 1 VU start, after each 2 minutes VU increase by 1 till 10 VU and stop the test when all 10 VU executed their iteration, can someone please help do it? I tried stages and they work but i did not find how to stop the test when each VU finish his iteration, per-vu-iterations executor is not working combined with stages. Thank you!

Hi @AG1337

Let me clarify, do you want that each VU execute its iteration only once (like does 600 requests and no more) during the test run, or do you want to stop the test run once the test run riches 10 VU numbers and once the 10th VU does 600 requests stop the test?



Thanks for reply, Oleg :slight_smile:
Yes I want that each VU execute only one iteration from beginning to end and test to stop when 10th VU finish his iteration, so for example test start with 1 vu and gradually increase VU number by 1 each 1 minute untill 10 VU then keep the load(all VUs are executing their iteration) then gradually finish execution per VU so i.e. 15m ramp up; 30m load period; 15m ramp down(but the time is not fixed because of random sleep time between each request and i do not need any duration limits, just to stop when all allocated VUs finish their iteration completely).
Thanks a lot!

Sorry, I still think that I am missing something :frowning_face:

But maybe this could work:

import { sleep } from 'k6';

export const options = {
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: 'ramping-vus',
      startVUs: 1,
      stages: [
        { duration: '2m', target: 10 },        
        { duration: '1m', target: 0 },        
      gracefulRampDown: '1m',

// a simple counter of iterations for each VU
let i = 0;

export default function () {    
  if (i > 0) {
      console.log(`no more work for the #VU: ${__VU}`)
      // iteration for that user already done
      // we just sleep a bit and exit
  console.log(`VU #${__VU} is doing some job`);

  // heavy work (600 requests)

  // we are done with the job

Basically, the whole scheduling of execution is still managed by k6, but using this simple i variable guarantees that the VU executes only once, which means that once you reach the 10 VUs, it’s just a matter of the grace shutdown to wait when the scheduler simply stop all VUs.

Does that help? :thinking:


1 Like