I’m seeing a case where my SharedArray is getting initialized multiple times when run on the cloud.
If I log the function in the shared array init, it get’s called once ever when run locally.
for a simple app, the function is called twice, once client side, and once cluster side. this is confusing but doesn’t cause any problems as the second array is passed to the target function on the server.
but I have another job that runs 1 scenario with 1 vu, and 300vus for the second scenario. the first scenario uses the shared array to create a resource, and the second consumes the resources named by the shared array.
but I get one init client side, and two inits server side. the first scenario uses the second init values.
but the second scenario will run against either of they arrays concurrently. that is, there are two shared arrays with the same name, but different values.
this causes to second scenario to fail because the first one didn’t create the named resources.
if I reduce the number of vus for the second scenario to say 10, there are only two inits, one client one server, and there is no confusion with multiple array instances.
fwiw, I ran this with 200vus, and there was only one client and one server side init (not two). so 300vus causes me grief.
Hi @cwensel, sorry for the slow reply and welcome to the community forum!
SharedArray is getting initialized multiple times when run on the cloud.
This is expected and is limitation in the current implementation.
As SharedArray is run in the initcontext you can’t use anything that does requests to the outside so this usually has no sideeffects that are observable. I guess logging is a side effect that is observable.
While there is an idea on how to really only execute SharedArray once and consequently even let it be executed not only in the initcontext and let it do requests. That idea is currently not being worked on and is way too involved so I am not going to go down that path.
By the way you explain your problem, my expectation is that you are using some randomization in the SharedArray that means that 2 different calls to it may give you two different results. This arguably is not really a case SharedArray was envisioned to be used with.
The whole execute once is more optimization on not having to load and parse the same file than some “once called” protection.
I would try to get the random part out and instead make it deterministic. And maybe have randomness as environment variable in case that is actually needed.