thread Local Cached Connection

Viewed 19

I was using JMeter properties for storing the threadLocalCachedConnection object. I made sure to use unique property names as properties.

In thread group 1, I had a JSR223 PostProcessor to scrape session per thread(VU), and then store it in a property called sessionID.

enter image description here

And I added another JSR223 PostProcessor as a child of the last sampler in the Thread Group1.

def connection = sampler.threadLocalCachedConnection
props.put("presenterConnection" + ctx.getThreadNum(), connection.get())

In Thread Group 2, I added a JSR223 PreProcessor as a child of the first sampler.

def presenterConnection = props.get('presenterConnection' + ctx.getThreadNum())
sampler.threadLocalCachedConnection.set(presenterConnection)

enter image description here

String sendCommand = "SEND\n" +
         "content-type:application/json;charset=UTF-8\n" +
         "destination:/v1/session/${__property(sessionId)}/command\n" +
         "id:perftest01-presenter-${__property(sessionId)}\n" +
           "\n" + 
           "{\"type\": \"go-to-slide\", \"data\": {\"index\": 0}}\n" +
           '\0'  // note: NULL char at end
           ;
vars.put("wsStompSendCommand", sendCommand);

I tested with 2 threads (VUs). Why both threads were using the last sessionId instead of using one sessionId per thread??

1 Answers

As per JMeter Documentation:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads

so your line

props.put('sessionId', vars.get('sessionUUID'))

creates a global sessionId propety which is:

  • common for all Threads no matter in which Thread Group they are
  • exists until you shut down JMeter/JVM

You need to play the same trick as with the presenterConnection to wit:

props.put('sessionId_'+ ctx.getThreadNum(), vars.get('sessionUUID'))

and then read it where required:

def sessionId =  props.get('sessionId_'+ ctx.getThreadNum())

More information: Apache Groovy: What Is Groovy Used For?

Related