Allocate Test Data to Threads in JMeter

Performance Testing is a blend of art and science. It is our responsibility to simulate real-world situation in a test environment. Test data plays a crucial role in performance testing. In a few instances, each thread needs allocation from the test data pool. Out of the box, JMeter doesn’t have this feature. But, not the case now. In this blog post, you will learn how to allocate test data to threads in JMeter.

Why allocate test data to threads?

Suppose you have a set of products which need to be in the shopping cart where the users are from a specific region. E.g, users from the US east coast cannot add certain products which belong to the US west coast. This is just a hypothetical scenario, but you got the idea, right.

LoadRunner Professional has an option in the Parameter Simulation box called Allocate Vuser values in the Controller. This setting will allow each vusers allocate x number of test data.

Allocate Vuser Values in the Controller
Allocate Vuser Values in the Controller

The above setting allocates 2 values for each Vuser in the Controller Each Vuser will continue in a cyclic manner if it is running out of test data. No Vuser can cross their allocation.

Below is the script you can try to validate this feature.




	lr_end_transaction("T00_Product_Page", LR_AUTO);
	lr_log_message("VUser ID is %s using the product %s", lr_eval_string("{P_VUSER_ID}"), lr_eval_string("{P_PRODUCT_ID}"));	
	return 0;

In the Controller Vuser log, you can validate the below highlighted section.

Controller VUser Log
Controller VUser Log

How to allocate Test Data to Threads in JMeter?

As mentioned earlier, JMeter doesn’t have this feature built-in. Thread can access the data based on the sharing mode in CSV Data Set Config.

To allocate test data for each thread, install baolu-csv-data-file-config from JMeter Plugins Manager.

Baolu CSV Data File Config
Baolu CSV Data File Config

After installation, restart JMeter and add the Baolu CSV Data Set Config element by right-clicking on test plan or thread group > Add > Config Element ? Baolu CSV Data Set Config.

Adding Baolu CSV Data File Config
Adding Baolu CSV Data File Config


Baolu CSV Data Set Config was built by extending the CSV Data Set Config class. Let us configure all the required configuration in this config element.

Baolu CSV Data File Configuration
Baolu CSV Data File Configuration

In this example, let us hit the product page and add the items to the cart. Assume that, each thread must pick 2 data from the below pool. Above are the configuration details.

Here is the sample test plan and the sample test data. Download the test plan, configure the test data, and open it in JMeter.


Apart from the typical configuration, Baolu needs the below configuration.

  • Allocate data for each thread – set to true
  • Automatically allocate block size – set to false
  • Set block size for each threads – 2

The above configuration allocates 2 values from the test data pool for each thread exactly.

Run the test plan with 2 threads, infinite loop count for the duration of 10 seconds. In the aggregate report, you will get the below stats (with different product IDs).

Block Size 2
Block Size 2

In this run, each thread (total 2 threads) will pick exactly two products and keep repeating them. Please note, we have 8 unique products in the data set source.

Allocate Automatically

If you would like to allocate block size automatically, configure the below settings.

  • Allocate data for each thread – set to true
  • Automatically allocate block size – set to true
  • Set block size for each thread – 0

The above configuration will yield the below output. Each thread will allocate 4 test data.

Block Size 0
Block Size 0

Disable Allocation

Setting the value false to Allocate data for each thread will disable the allocation and it inherits the CSV data set config behaviour.

Disable Allocation
Disable Allocation

Final Words

If you need the allocation feature in JMeter either you can do it logically using the Groovy in JSR223 feature, or you can make use of Baolu CSV Data File Config. I am still testing this plugin. If I find any issues I will let you know. If you are using it, please share your usecase. The author did a good job in creating this feature as a plugin. This should be implemented in the JMeter core.

Allocate Test Data to Threads in JMeter

2 thoughts on “Allocate Test Data to Threads in JMeter”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join the fastest growing Performance Engineers club at ClubhouseSHOW ME HOW
+ +
Share via
Copy link