I am trying to understand how a FIFO queue of the inter-thread communication plugin for Jmeter works.
I made a simple test plan.
Added a setUp Thread Group
under which I added a JSR223 Sampler
with the following code:
def targetFIFOQueueName = "SYNC_FIFO_" + ${TESTSTART.MS}
log.info ("targetFIFOQueueName: " + targetFIFOQueueName)
props.put("targetFIFOQueueName", targetFIFOQueueName)
Then I added a classic Thread Group (default, just 1 thread, 1 loop), under which I added a JSR223 Sampler
with the following code:
${__fifoPut(props.get(targetFIFOQueueName),'variable1')}
Under this sampler, I added a JSR223 PreProcessor
and JSR223 PostProcessor
, both with the same debug code:
def targetQueueName = props.get('targetFIFOQueueName')
def queueSize = '${__fifoSize(props.get(targetFIFOQueueName))}'
log.info (queueSize.toString())
kg.apc.jmeter.modifiers.FifoMap.getInstance()['props.get(targetFIFOQueueName)'].eachWithIndex { entry, index -> log.info(targetQueueName + ' Queue has '+ 'entry # ' + index + ': ' + entry) }
In the end it looks like this:
You can see the JMeter log in the screenshot. I have highlighted the outputs from the preprocessor and postprocessor. What I don't understand is :
fifoPut
function so then how does the queue exist in the first place...?)fifoPut
function) another entry seems to be added (so I call fifoPut` function once but it gets executed twice). Why is this happening?Any insight into this matter would be greatly appreciated.
Don't inline JMeter Functions or Variables into Groovy scripts.
Take a look at JSR223 Sampler documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
- Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
- Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
In your case the functions are being evaluated when they appear in the test plan.
Once you get rid of this crazy mix of functions, variables and Groovy code your script will start behaving closer to what you expect.
More information: Apache Groovy: What Is Groovy Used For?