Parameterization in the JMeter script is handled by the CSV Data Set Config element. CSV Data Set Config provides the easiest way to call the external CSV (Comma Separated Values) file which contains parameter values. But the confusion starts when a single CSV file is shared between multiple thread groups, threads and requests and we do not know how the test data will be distributed among them. This may also lead to the wrong calculation of the required test data. To predict the correct test data requirement and use the test data wisely, it is necessary to understand the sharing modes of CSV Data Set Config element in JMeter.
Let’s try to understand the sharing modes of CSV Data Set Config with an example.
Example:
Consider, there is one CSV file (say “perfTestData.csv”) having 10 values which are:
And the test scenario has the following metrics:
- No. of Thread Groups: 2
- No. of threads in each Thread Group: 2
- No. of iterations in each Thread Group: 2
- No. of occurrence of the parameter in each iteration: 2. Refer the Figure 02.
- All request samplers have ${perfVar} parameter which is defined as a variable in the “CSV Data Set Config” element. Refer the Figure 03.
Let’s run the script by selecting the different sharing modes one by one:
1. Sharing Mode: All Threads
In this mode, Thread Groups share the value of the CSV file. A new value of the parameter is passed in each iteration, by each thread and thread group.
Key Points:
1. Each thread group, thread, and iteration will have a separate value.
2. The parameter value will be shared at the occurrence level i.e. if more than one parameter occurrences in the same iteration then the same value will be passed.
Thread Group 1:
ThreadNum 1 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 1 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 1 -> Iteration 2 -> Request 1 -> perfVar = 2012
ThreadNum 1 -> Iteration 2 -> Request 2 -> perfVar = 2012
ThreadNum 2 -> Iteration 1 -> Request 1 -> perfVar = 2013
ThreadNum 2 -> Iteration 1 -> Request 2 -> perfVar = 2013
ThreadNum 2 -> Iteration 2 -> Request 1 -> perfVar = 2014
ThreadNum 2 -> Iteration 2 -> Request 2 -> perfVar = 2014
Thread Group 2:
ThreadNum 1 -> Iteration 1 -> Request 1 -> perfVar = 2015
ThreadNum 1 -> Iteration 1 -> Request 2 -> perfVar = 2015
ThreadNum 1 -> Iteration 2 -> Request 1 -> perfVar = 2016
ThreadNum 1 -> Iteration 2 -> Request 2 -> perfVar = 2016
ThreadNum 2 -> Iteration 1 -> Request 1 -> perfVar = 2017
ThreadNum 2 -> Iteration 1 -> Request 2 -> perfVar = 2017
ThreadNum 2 -> Iteration 2 -> Request 1 -> perfVar = 2018
ThreadNum 2 -> Iteration 2 -> Request 2 -> perfVar = 2018
2. Sharing Mode: Current Thread Group
In this mode, Thread Groups use the same set of values but different values are used by each thread within the thread group. To make the statement simple for understanding purposes, 2 copies of CSV files are created at the Thread Group level. Each thread within a thread group picks a new value from its own copy of the CSV file every time.
Key Points:
1. Each thread group has the same set of values.
2. Each thread and iteration will have a separate value.
3. The parameter value will be shared at the occurrence level too i.e. if more than one parameter occurrences in the same iteration then the same value will be passed.
Thread Group 1:
ThreadNum 1 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 1 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 2 -> Iteration 1 -> Request 1 -> perfVar = 2012
ThreadNum 2 -> Iteration 1 -> Request 2 -> perfVar = 2012
ThreadNum 1 -> Iteration 2 -> Request 1 -> perfVar = 2013
ThreadNum 1 -> Iteration 2 -> Request 2 -> perfVar = 2013
ThreadNum 2 -> Iteration 2 -> Request 1 -> perfVar = 2014
ThreadNum 2 -> Iteration 2 -> Request 2 -> perfVar = 2014
Thread Group 2:
ThreadNum 1 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 1 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 2 -> Iteration 1 -> Request 1 -> perfVar = 2012
ThreadNum 2 -> Iteration 1 -> Request 2 -> perfVar = 2012
ThreadNum 1 -> Iteration 2 -> Request 1 -> perfVar = 2013
ThreadNum 1 -> Iteration 2 -> Request 2 -> perfVar = 2013
ThreadNum 2 -> Iteration 2 -> Request 1 -> perfVar = 2014
ThreadNum 2 -> Iteration 2 -> Request 2 -> perfVar = 2014
3. Sharing Mode: Current Thread
In this mode, Threads use the same set of values but different values are used within the iteration. To make the statement simple for understanding purposes, separate copies of CSV files are created at the Thread level. But each iteration within a thread picks a new value from its own copy of the CSV file every time.
Key Point:
1. Each thread has the same set of values.
2. Each iteration will have a separate value.
3. The parameter value will be shared at the occurrence level too i.e. if more than one parameter occurrences in the same iteration then the same value will be passed.
Thread Group 1:
ThreadNum 1 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 1 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 2 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 2 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 1 -> Iteration 2 -> Request 1 -> perfVar = 2012
ThreadNum 1 -> Iteration 2 -> Request 2 -> perfVar = 2012
ThreadNum 2 -> Iteration 2 -> Request 1 -> perfVar = 2012
ThreadNum 2 -> Iteration 2 -> Request 2 -> perfVar = 2012
Thread Group 2:
ThreadNum 1 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 1 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 2 -> Iteration 1 -> Request 1 -> perfVar = 2011
ThreadNum 2 -> Iteration 1 -> Request 2 -> perfVar = 2011
ThreadNum 1 -> Iteration 2 -> Request 1 -> perfVar = 2012
ThreadNum 1 -> Iteration 2 -> Request 2 -> perfVar = 2012
ThreadNum 2 -> Iteration 2 -> Request 1 -> perfVar = 2012
ThreadNum 2 -> Iteration 2 -> Request 2 -> perfVar = 2012
4. Sharing Mode: Edit
This mode provides a facility to share the CSV file between the specific thread group only. Let’s consider, there are 4 thread groups and you want to share the test data between Thread Group 1 and Thread Group 4 only. The rest of the thread groups will use the file independently then you need to choose this ‘Edit’ option under the ‘Sharing mode’ config element and write down this statement ‘SharedWithThreadGroup1and4’. Make sure you have a specific CSV Data Set for all the thread groups. Refer to the figure:
Each CSV Data Set Config will have the following setting:
Thread Group 1: ‘Sharing mode’ = SharedWithThreadGroup1and4’
Thread Group 2: ‘Sharing mode’ = ‘Current Thread’
Thread Group 3: ‘Sharing mode’ = ‘Current Thread’
Thread Group 4: ‘Sharing mode’ = ‘SharedWithThreadGroup1and4’
And, the result is:
Proper use of sharing mode of CSV Data Set Config helps to pass duplicate or unique test data among the different Thread Groups and Threads in the test.
You may be interested:
Nicely explained with proper examples, thanks