Setup function duration

Hello everyone!

Situation:
I need to make performance test with e.g. 100 users, adding according to stages.
All these users must authenticate first.
I’ve moved authentication of users into setup() function in purpose to not impact on test execution.
But now it takes at about 60sec to login all users before test starts. And what if I want to simulate 1000 users? Several minutes of waiting?

Is it possible to somehow solve this issue and make it faster?
Maybe there is an ability to create some function, that will be run before each user adding to simulation?

Thx :slight_smile:

Hi,

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

Hi,

Thank you for so fast response. Yeah, we thought about these ways. The first way is closest to one we are looking for.
However, it makes tests are not so clean as we are doing setup actions in the main body itself. Usually, in test frameworks there are “SuiteSetup” and “TestSetup” which in case of data driven tests (the same as having tests under many users) are run before test and before each case specifically.

I think the first option will work for us but initial concern is still relevant I guess and t might be just a small feature request across community (just to make tests clean).

Thanks,
Yuri.

Hi @AlexJioev and @ybushnev

I wonder if this problem could be solved in a different way.

It looks you want the authentication request to not impact the test execution.

Please, would you mind clarifying your goal? I thought that perhaps this could be solved if k6 provides an option to not report particular requests.

http.post(loginURL, loginData, { headers: headers, report: false });

Hi, @ppcano.
Not exactly. The point here was a)make iterations faster and don’t waste time on unnecessary auth calls and b) don’t produce unnecessary load on authentication service, which runs separately.

We used first approach, suggested by mstoykov. It works fine :slight_smile:

But thanks for your suggestion! It’s always good to learn something new :slight_smile:

hello, I had the same problem and I solved it by creating a seed.ts script where I do all the authentication process and save the result in a file with all the tokens. Then I can run my test on the test.ts file using the info from the file created with seed.ts and it works fine so far