Ragnar
Ragnar

Reputation: 1182

Unique data in each VU thread in k6 / shared state between VUs

Is it possible to get a global counter shared across VU threads in k6? e.g. for user registration where email address must be unique, I'm using "user" + i + "@example.com" ...

Currently using a global variable:

let i = 1

in global namespace. Single-VU works properly, but 2 VUs cause 50% of requests to fail, etc. I'm assuming each VU runs its own JS. Is there a reference to the thread (goroutine?) number/id available to the JS runtime?

Upvotes: 2

Views: 2420

Answers (1)

Ragnar
Ragnar

Reputation: 1182

You can use the numeric counters __VU and __ITER.

__VU: This value is assigned incrementally for each new VU. If the VU gets terminated (e.g. as part of a ramp-down operation) and the test coordinator launches the same VU again, the VU will have the same previous value.

__ITER: The current iteration number for a given VU.

Upvotes: 2

Related Questions