Setup function duration


There are … a couple of possible solutions which depend on how your script is working. I am going to list them in the order I think is best but it depends on your needs :slight_smile:

  1. If each VU is essentially one user or you can map n user to a specific VU you can just authenticate them in the first iteration of the VU(or the first iteration you use the given user). VUs keep their global variables between iterations so you can just:
let authToken = ""
export default function() {
    if __ITER == 0 || authToken =="" { // which ever is easier
        authToken = ... // however you get your token
    // use the token 

This obviously will add some time to the execution of that iteration but it will be spread between the VUs and if you make a lot of iterations (which you probably do) I would guess it won’t be that big of a difference that it will skew your end results.

This will have a better/nicer way of doing it with the introduction of InitVU but this is currently not supported, but you can watch if for change

  1. Make all the authentications in a http.Batch request in setup() … this should speed up the process somewhat
  2. You can raise the setupTimeout so at least it finishes if that is your current problem or none of the other help
  3. You can authenticate outside of k6, write the tokens to a json file and (re)use it in the script with open one of the examples is somewhat what you want.

If you have any suggestion on how we can provide a better functionality for your use case maybe write us an issue :wink:

1 Like