[Solved] How much memory for k6 VU (Virtual User)? [closed]


How much memory a VU takes is highly dependent on what your script does and (usually more importantly) how many other files it imports/parses. Due to the fact that all VUs have their own JS VM they are separate copies of all JS files that need to be parsed. As such if you have some big JS library it will be copied between VUs and probably account for the majority of your memory usage. If your script also has some big files with a lot of test data in them – they will be copied as well and so on. In my experience simple scripts can use as little as 1-2mb or less and I have seen script go as high as 40mb in some really bad cases where they import some pretty big JS libs.

Obviously your script will use more memory during the execution, but the major source of that memory will be response bodies so we highly recommend using discardResponseBodies (At the very bottom of the page) to lower that memory usage and only set responseType where/if you need the body response.

About linearity – kind of, more or less the majority of memory in every script that I have profiled goes towards VUs once the JS scripts have been parsed in the beginning and all the VUs have been initialized. And they use around the same amount of memory but there is some memory that k6 needs for other uses depending on what you use that should be around 200-300mb.

Ultimately you will have to test your script and see. If you know that you are going to use some libraries import them without using them in order for them to parsed and to get a fast estimate. You can run k6 with --paused --no-teardown --no-setup to only initialize VUs without actually executing any of the code again for faster estimate. I recommend providing how many VUs should be ran/initialized with -u <count> for the testing. And you should wait until it says paused before a progress bar so that everything has been initialized.
Be advised that k6 will use some memory to parse your JS and initialize other stuff in the beginning so you should probably start testing with at least 50 VUs and go up in order to see how much memory is being added for the additional VUs. Obliviously execution of the final script will use more memory but this should be useful for gauging purposes.

2

solved How much memory for k6 VU (Virtual User)? [closed]