Initial VU value in init context or setup lifecycle

Hi k6 community,

I am using k6 to setup a load test to know the mean request duration of uploading a file to microservice backend. And I really fall in love with k6! What a great tool.

For this use case I need to create a resource before I can upload files there. Usually I would do this in a setup phase. But I need this for each virtual user, before a VU can start sending files. But the setup function is once per test, not per VU. Unfortunately in init context it is also not possible. GoError: Making http requests in the init context is not supported

I will not implement the creation of resources in first iteration. Because this would affect my measurement. The metric should only include requests with file uploads.

I could solve this with a workaround: to setup all resources beforehand in another external script. But I would like to do everything in the k6 script. And I would not know the count of resources to create. (Count of VUs that will run later)

Is there a possibility to know the initial VU parameter count in setup phase? Then I could create the resources for all the initial users in setup phase. The only thing that would not work then, is the k6 scale approach.

Or are there any plans to include a lifecycle phase of a setup per vu?

best regards
Sebastian

Hi @SBJ, welcome to the forum.

You could use the K6_VUS environment variable to run your script, and in it you can access this value with __ENV.K6_VUS, which is also accessible from the setup() function, so you can create your resources there.

See the documentation for details.

Or are there any plans to include a lifecycle phase of a setup per vu?

Yes, this has been discussed before. See issue #785. Currently the team is focused on getting #1007 out the door, but a per-VU setup/teardown feature is on the near-term roadmap after that.

Hi imric,

and thanks for welcoming me.

Thanks for your reply. Your proposal with __ENV.K6_VUS is exactly what I was doing after I sent my post here. Nice, that I am not the only one with this workaraound idea :slight_smile:

The plans of a per-VU setup/teardown are really good. I added my +1 in the issue and subscribed to it.

Thanks for your reply

1 Like