Search code examples
multithreadingjmeterperformance-testing

Ensure vars.get in a JSR223 postprocessor will set value only in current thread


In JMeter, I have a Thread Group which has a child JSR223 sampler. This JSR223 sampler attempts to execute some code to get a message from a remote system and if it is successful, it sets a variable var1 like so:

vars.put('var1', var1)

Then, in a child JSR223 PostProcessor of this JSR223 sampler, I do:

var1 = vars.get('var1')

Then I use var1 for some calculations to amend the parent JSR223 sampler results.

I am concerned that if I spawn multiple concurrent threads with this code, they will each try to put a value into var1 and then when the PostProcessor will run, I will not have a guarantee that the var1 value which I am trying to use in the postprocessor, is actually the var1 value set by the current thread parent sampler. Could it be the value set by another thread?

Is this a valid concern, and if yes, how can I mitigate it?

Thanks in advance!


Solution

  • JMeter Variables are local to the thread, each thread (virtual user) has its own instance of JMeterVariables class and other threads neither have read no write access to that vars object.

    So your concert is not valid hence it doesn't require "mitigation" (whatever it means)


    If you will need to pass data between threads/thread groups - it can be done via props object, this guy is "global" and accessible with any thread in any thread group (in fact in the whole JVM so props will still have values even if the test is ended but JMeter engine hasn't been yet shut down) so you need to be careful with it.

    More information: Top 8 JMeter Java Classes You Should Be Using with Groovy