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.
Table of Contents
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.
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.
Action()
{
lr_start_transaction("T00_Product_Page");
web_custom_request("web_custom_request",
"URL=https://onlineboutique.dev/product/{P_PRODUCT_ID}",
"Method=GET",
"TargetFrame=",
"Resource=0",
"Referer=",
"Body=",
LAST);
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}"));
lr_think_time(1);
return 0;
}
In the Controller Vuser log, you can validate the below highlighted section.
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.
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.
Configuration
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.
In this example, let us hit the onlineboutique.dev 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.
OLJCESPC7Z,1
66VCHSJNUP,2
1YMWWN1N4O,4
9SIQT8TOJO,6
6E92ZMYYFZ,3
9SIQT8TOJO,2
0PUK6V6EV0,5
L9ECAV7KIM,1
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).
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.
Disable Allocation
Setting the value fal
se to Allocate data for each thread
will disable the allocation and it inherits the CSV data set config behaviour.
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.
Does this work in distributed test also? Currently we have to upload individual data set in individual loadgen ?
At this moment, no. It will be available in the upcoming release. The author is working on it.
For distributed load testing with multi jmeters. I recommand Http Simple Table Server
https://jmeter-plugins.org/wiki/HttpSimpleTableServer/