k6 community forum

SetEnvironment Variable in Postman to K6 Converter is Local or Global

postman.setEnvironmentVariable("invitationKey", post.Key);

In above example, invitationKey needs to be different for each virtual user. I have used Postman to K6 converter to generate K6 test script.

postman.setEnvironmentVariable("invitationKey", post.Key);
EnvironmentVariable set using above, Is it local to virtual user or global to all virtual users

Hi @vishal.lanke,

Not really certain how postman-to-k6’s postman API works and stuff(or postman’s API as well), but given the fact that it gets a postman file and generates a k6 script it can’t do anything that can’t be done with a k6 script as-is.

K6 runs your script in separate JS VMs which we call VUs, looping over the default function defined in the script. After the initial initialization and the setup data that can be transmitted from the setup function the the default one and the teardown one (if there is one), there is no current way of communication between VUs from strictly inside k6.

So the answer is that if postman.setEnvironmentVariable("invitationKey", post.Key); happens in the default function it will mean that it will be different (given that post.Key is different) for each and every VU.

p.s. “by strictly from inside k6” I mean that you can technically communicate through an outside HTTP server but this is not what postman-to-k6 is doing :wink:

I am finding Postman to k6 converter very useful. Our development team has provided 20 Postman collection. Each collection has TestScripts and each collection contains 7 to 10 API which has a purpose in performing end to end activities.

I have converted 1 same postman collection to K6. Then, modified the converted draft as per my requirements and then defined checks, thresholds, VUs. It is working well for us.Current limitations of converted scripts like pm.sendrrqest has no impact on us.

My query is that can I use Postman to K6 converter script for my real-time performance testing? Or it’s better to write JS scripts instead of postman to k6 conveyed JS scripts ?

I am glad that you have found it useful :smiley: .

I suppose that by “real-time” you mean when you start do performance testing instead of just trying it out? And not in the sense of Real-time computing :wink: .
I would say that technically nothing will be in the way of you using the postman-to-k6 generated scripts with you adding thresholds and checks and so on …

The converter adds overhead though … you essentially do additional calls on JS objects to convert from the postmany requests to the ones k6 can understand more easily, also (depending on what you are using) this will require the imports of additional JS code which will also probably then will be executed. As mentioned above each VU is a separate JS VM so for each of those JS files they will need to be loaded and executed for each one separately. This all adds up and at some point, a VU starts using like 20 MB of RAM each … This is not a big problem if you are running like 20, 30, 50 VUs but once you go in the hundreds this makes both the initial startup time and execution slower and more resource consuming.

I (and AFAIK nobody else) has done any amount of benchmarking with postman-to-k6 so maybe the effect is negligible and this will definitely depend on you using more of the functionality :). For example, if you are doing stuffs with xml you will need the xml2js which is 10k lines …

On the other hand as you have seen it means that someone can just use postman … make the requests that need to be made, not knowing anything about k6, and then you can just use the converter to generate a script … easy :smiley: .

Depending on what you do in your scripts also not using postman-to-k6 may necessitate, that you basically import those same shims and libraries and use them yourself instead of the converter doing it for you …

So I would argue that you should think about whether you will want to run a lot VUs in the first place. I would like to say that … in my experience everybody overestimates how many VUs they truly need by a factor of 10 or more :wink: so maybe first test with whatever your machines can handle … Also maybe you can run 2k VUs on your hardware even with all the libraries imported and it is not a big problem that the initialization of the VUs will take … several minutes (you can look around this forum it’s a common problem with multi MB scripts). Because if you using the converter works great for you, there really is no reason for you doing the work even if it isn’t much …

Also maybe if the postman scripts are done or will keep coming, and they have hundreds of URLs doing different things - it will take you a lot of time to rewrite them and will be better invested elsewhere and just buying more hardware or using Load Impact’s cloud service :wink: might again be a better situation.

Again postman-to-k6 just creates a k6 script for you … it can do just as much and as little as k6 can , but maybe doesn’t do it as performant as it possibly can … but you might not need it to be so … test it out with some of the scripts … see if you are using any of the features of postman that will necessitate you importing xml2js … cheerio or some of the others really big JS files. Does that then mean that the startup times and the execution requirements are not satisfiable and if not can you rewrite it without using it … maybe even just the converted script instead of from scratch.

Good luck and we always are happy to hear how stuff went, so please write back if things go bad … or good :wink: