Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Time:2022-6-10

CSV Data Set Config in Sharing Mode – Made Easy

In order to make the performance test more realistic, it is better not to use the same user in each thread group. Therefore, you need a way to configure Apache JMeter ™ To use different users with unique user data, and propose ideas on how to effectively store user data that will be used during the test run.

For this reason, JMeter has a very useful configuration element called CSV dataset configuration. The CSV dataset configuration allows you to use a CSV file as an external data source where you can keep unique user data, such as name, e-mail, and password. With this configuration element, JMeter can read the CSV file line by line, and then use the split parameter to assign different values to different threads.

At first glance, all CSV dataset configuration parameters seem self explanatory. But one of them may not be as simple as you think. This parameter is shared mode. This blog post will explain all the information you need to know about this option.

Understanding the JMeter CSV Data Config Element

Create a user group with five threads:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Create an HTTP request for user login:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

You will see that all five users in the thread group have logged in using the same email and password. This happens because these values are hard coded in the request sampler and they are related to all five users in the thread group:

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Multiple Users With Multiple Requests

But what if you want to log in under different users? To simulate a real web application load, you might want to use different users with different credentials. To this end, JMeter has a CSV dataset configuration element designed to help resolve such situations.

The main idea of this element is that it reads the CSV file line by line and provides its value to the threads of the current thread group. There are many useful articles and practice sessions that explain this JMeter element with different examples.

But first, let’s create a simple CSV file that contains a list of users (each user is on a separate line), and the e-mail and password are separated by commas between each line:

Contents of CSV file:

JMeterSharingModeU[email protected],123qwe
JMeterSharingModeU[email protected],234wer
JMeterSharingModeU[email protected],345ert
JMeterSharingModeU[email protected],456rty
JMeterSharingModeU[email protected],567tyu
JMeterSharingModeU[email protected],678yui
JMeterSharingModeU[email protected],789uio
JMeterSharingModeU[email protected],890ipo
JMeterSharingModeU[email protected],901opq
JMeterSharingModeUser1[email protected],012pqw

‘All threads’ Sharing Mode

Let’s add the CSV dataset configuration element to our performance script (right click test plan – > Add – > configuration element – > CSV dataset configuration). In this element, you need to specify file names that contain user details and variable names that will be used as containers for these values obtained from the file.

Remember, there are two options: you need to specify the full path to the CSV file, or you can use only the file name. In this case, however, the file should be in the same folder as the JMX performance script. This time you will use the default shared mode: all threads.

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

After rerunning our script, you can see that all users have obtained e-mail and password respectively according to order and line number:

  • The first user uses the first line of email and password
  • The second uses the second line of email and password

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

“All threads” sharing mode means that the file will be shared among all threads, andEach request will be orderedRead a line in the CSV file. This is the default method for CSV dataset configuration. It looks like this:

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

‘Current thread’ Sharing Mode

When we want each thread to open and read CSV files separately, we should use the “current thread” sharing mode. under these circumstances,Each user reads the CSV file from beginning to end。 Let’s change the sharing mode to the current thread value and verify the behavior of the performance script this time.

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

As you can see, this time all threads try to run login requests under the same user. The reason is simple. Since each thread reads the file from beginning to end, all five threads in our thread group use the value in the first line to execute the login request.

Currently, you have only 1 loop configured in the thread group. If you want to ensure that each thread will read the second row in the next loop, let’s update our thread group with the “2” value in the “loop count”.

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Since you have 5 threads and 2 loops, there should be a total of 10 requests. The first five requests should be logged in under the first user (the first line of the CSV file), while the next five requests should be logged in under the second user (the second line of the CSV file).

Let’s run the script and confirm. But before that, it might be useful to add a “constant timer” to the current thread group. Since you want to show that two loops use different lines from the CSV file, you need to avoid the situation where the first thread executes the first loop and starts the second loop while the second thread just starts the first loop. In this case, the requests in the view results tree listener will be mixed. Let’s add a 2-second timeout for this (right click test group – > Add – > Timer – > constant timer).

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

As you can see, the first five requests use the first line of the CSV file, and the last five requests use the second line. It looks like this:

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

‘Current thread group’ Sharing Mode

In the’current thread group’sharing mode, each file is opened separately by each thread group (not to be confused with the “current thread” in which each thread reads the file separately. This basically means that each thread in each thread group reads the CSV file from beginning to end without affecting each other.

To actually demonstrate this sharing pattern, you need to create another thread group. You can copy and paste the existing and rename the thread group and login sampler as appropriate.

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Change the sharing mode to: current thread group

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

After running the script, you can find that each thread group uses a CSV file:

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

The workflow diagram of this case looks more complex, but the main idea is as follows:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

‘Edit’ Sharing Mode

This sharing mode usually brings a lot of confusion to many JMeter users. This field is converted to input when you select the edit option under the shared mode configuration element. You can then provide your own string in this field instead of using a predefined string.

The main idea of this sharing mode is that you can use the same CSV file in multiple thread groups, but only the specified thread groups will share the file with each other. Seems a little complicated? Let us give an example to illustrate this point.

First, you need to add an additional thread group (you can copy and paste in the same way as we did in the previous paragraph). This time, let’s copy and paste the “CSV dataset configuration” element under each thread group:

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Now you need to configure each CSV dataset configuration in this way:

Thread group 1: “shared mode” = “sharedwiththreadgroup1and3”
Thread group 2: “shared mode” = “all threads”
Thread group 3: “shared mode” = “sharedwiththreadgroup1and3”

“Thread group 1” configuration example:

Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

In this case, the values of the first and third thread groups should match each other. Such a configuration tells JMeter to share a CSV file between the two, and the second thread group will use its own CSV copy. Let’s run the script again and verify the request in progress again:

First thread group:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Second thread group:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Third thread group:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

As you can see, the first two thread groups read the CSV file from scratch and use the first line, while the third thread group does not. Since the third thread group has the same shared mode value as the first thread group, it continues to read the file from the line where the first thread group ends (the first line in the example provided).

By providing this sharing mode CSV dataset configuration element, you have great flexibility in controlling CSV file sharing in any way you want. This current mode can be visualized as follows:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

As you can see, CSV dataset configuration is very configurable and provides great flexibility, so you can always control the use of CSV files as needed.

More Jerry’s original articles can be found in: “Wang Zixi”:
Detailed explanation of the meaning of CSV data set config sharing mode in JMeter

Recommended Today

JS generate guid method

JS generate guid method https://blog.csdn.net/Alive_tree/article/details/87942348 Globally unique identification(GUID) is an algorithm generatedBinaryCount Reg128 bitsNumber ofidentifier , GUID is mainly used in networks or systems with multiple nodes and computers. Ideally, any computational geometry computer cluster will not generate two identical guids, and the total number of guids is2^128In theory, it is difficult to make two […]