Martkos IT Ltd

View Original

JMeter Inter-Thread Communication

Thread groups within Apache JMeter are designed to be self contained units. Therefore, variables are private to that thread group and not global to the test plan. Inter-Thread communication is possible using FIFO via a plugin.

Installation

Download plugins-manager.jar and put it into lib/ext directory, then restart JMeter.

The Inter-Thread Communication plugin within JMeter is hosted on https://jmeter-plugins.org/wiki/InterThreadCommunication/ to install the sampler use the plugin manager. Click on Options > Plugins Manager and then click on “Available Plugins”. Click in the search box and type “fifo”. Click on the checkbox at the side of the “Inter-Thread Communication” and then click Apply Changes and Restart JMeter.

Usage

Once installed the Inter-Thread Communication plugin adds the following elements :-

  • Inter-Thread Communication PostProcessor - puts an item on a queue

  • Inter-Thread Communication PreProcessor - reads an item and removes it from the queue

  • fifoPut - puts an item into the queue

  • fifoGet - reads an item from the queue without removing it

  • fifoPop - reads an item and removes it from the queue

  • fifoSize - returns the number of items in the queue

Note: fifoGet doesn’t wait for data in the queue and can therefore return an empty string. fifoPop waits until a thread puts some data into the queue.

Create a Test Plan

To demonstrate the Inter-Thread Communication lets create an example test plan. In this instance we set the test plan to execute the thread groups sequentially so Thread Group 1 executes before Thread Group 2. We did this to ensure that the bloglist had been populated before the preprocessor gets the value from the fifo queue.

  • First create a HTTP Request Defaults and set

  • protocol = https

  • server name = martkos-it.co.uk

  • Create a Test Plan with two Thread Groups 1 & 2.

  • Under Thread Group 1 add a HTTP Request and under it a Boundary Extractor.

    • name = blogpost

    • left boundary = <a class="blog-more-link" href="/blog/

    • right boundary = “

    • Match = 0

  • Now add a Inter-Thread Post Processor.

  • queue name = blog_list

  • value to put = ${blogpost}

  • Under Thread Group 2 add a HTTP Request and set

  • path = /blog/${blog_post_data}

  • Under the HTTP request add an Inter-Thread Pre Processor and set

  • get data from = blog_list

  • store data = blog_post_data

On test execution thread group 1 will extract the blog post names and randomly pick a value. This will then be added to the Inter-Thread Communication postprocessor. In thread group 2 the Inter-Thread Communication preprocessor will read the value from the fifo queue and store it as a variable named blog_post_data. We can then use that value in the HTTP request like /blog/${blog_post_data}.

FURTHER READING

Blazemeter - Use Inter Thread Communication