Why init called 4 times?

So I am new to use k6.io and when I just try to add console.log(‘Hi!’) at the init stage, it seems to be called 4 times. I am quite confused here. Any reasoning why? Because I can’t found the reasoning at Test lifecycle

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

INFO[0001] Hi!                                           source=console
  execution: local
     script: script1.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0001] Hi!                                           source=console
INFO[0001] Hi!                                           source=console
INFO[0001] Hi!                                           source=console

running (00m00.1s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

Of course I am quite happy when I found out setup() only called once :smiley:

The first time the init context is executed is to get the exported script options. No other function is executed at the time, only the global init code. Then, the init context is executed once for every VU that needs to be initialized, as well as once for setup() and teardown(), since they are executed in their own separate transient VUs. So, in total, the global init context code will be executed MaxVUs+3 times.

3 Likes

Thanks for the explanation! :grin:

How to stop init function multiple times