Using CSV Data Set in Load Tester (multiple remote servers) Powered by Apache JMeter™ (for old versions)
How to use CSV Data Set in JMeter to read values from a file and use them for load testing in the Load Tester.
The latest version of Load Tester allows you to distribute test data files to a remote JMeter server more easily than the method described in this article.
Please see this article for the procedure.
Load Tester (multiple remote servers) Powered by Apache JMeter™ is designed to run Apache JMeter™ on multiple servers on Microsoft Azure to perform large-scale load testing.
Apache JMeter™ creates a huge load with a lot of remote hosts, and this solution allows you to build it up in a very short time of operation.
If you want to pass a different parameter values for each request in JMeter, you can prepare the values in a CSV file.
This CSV file must be distributed to all JMeter servers when running JMeter remote tests.
In this tutorial, I will show you how to do it in the Load Tester environment.
Outline of steps
- Prepare a CSV file
- Copy the CSV file to the local disk of the JMeter servers
- Configure CSV Data Set Config to import values from a CSV file
- Use that values in the sampler
- Add the listener
- Execute the load test
- Confirm the results
Details of steps
If you want to use the same CSV file on all JMeter servers, prepare the file on the shared disk.
Instead, if you want to use different CSV files for each JMeter servers, prepare files for each servers and place it on the shared disk.
This tutorial will show you how to do both.
Use the same CSV file on all JMeter servers
-
Prepare a CSV file
Create a CSV file as the test data in /mnt/jmuserdata in your JMeter client.
There are network disk mounted to /mnt/jmuserdata on the JMeter client and JMeter servers.ex. /mnt/jmuserdata/chemicalelements.csv
atomic_number,symbol,element 1,H,Hydrogen 2,He,Helium 3,Li,Lithium 4,Be,Beryllium 5,B,Boron 6,C,Carbon 7,N,Nitrogen 8,O,Oxygen 9,F,Fluorine 10,Ne,Neon
-
Copy the CSV file to the local disk of the JMeter servers
It is possible to use the CSV file on the network disk as it is, but I do not recommend it due to the slow file access.
That’s why copy the CSV file to the local disk of the JMeter servers.- Launch the JMeter on JMeter client.
- Add a “setUp Thread Group” to the Test Plan. Add > Threads > setUp Thread Group
- Add a “OS Process Sampler” to the setUp Thrad Group
Add > Sampler > OS Process Sampler
- Name: Copy CSV files
- Command: bash
- Command parameters (Value)
( Click “Add” to add the following line)- -c
- cp -f /mnt/jmuserdata/* /tmp
- Check Return Code: Check
- Expected Return Code: 0
In the above example, the file created in /mnt/jmuserdata has been copied to /tmp on the JMeter servers.
- Add a “View Results Tree” to the setUp Thread Group Add > Listener > View Results Tree
- Copy the CSV file by running the test
MENU > Run > Remote Start All - Confirm the result
If the Response code is 0 in the View Results Tree, the command has succeeded.
You should connect to the JMeter servers by ssh to make sure the file are copied just in case.If it fails (Response code is “1”), you can try and run it locally and see the error information output in Response data.
- Disable the setUp Thread Group Right click on “setUp Thread Group” and click “Disable”.
If you have increased the number of JMeter servers, you must run this copy process again because this copy process is not being performed on the added JMeter servers.
-
Configure CSV Data Set Config to import values from a CSV file
- Add a “Thread Group” to the Test Plan
Add > Threads (Users) > Thread Group
“Loop Count” should be set to “3” and so on. - Add a “CSV Data Set Config” to the Test Plan or the Thread Group
Add > Config Element > CSV Data Set Config
- Configure the CSV Data Source
- Filename: The CSV file name you just created
- Variable Names (comma-delimited): If the CSV file does not have a header line, separate the column names with a comma.
- Configure the CSV Data Source
- Add a “Thread Group” to the Test Plan
Add > Threads (Users) > Thread Group
-
Use that values in the sampler
In this case, use the HTTP Request sampler to assign the CSV file data as a QueryString of the GET request.
The values in the CSV file can be assigned by writing “${COLUMN_NAME}”.Add a “HTTP Request” sampler to the Thread Group
Add > Sampler > HTTP Request
- Web Server
- Protocol [http]: Protocol (http or https)
- Server Name or IP: Server name or IP Address of the target
- HTTP Request
- (Method) GET
- Parameters
Click “Add” and add parameters- Name: Parameter name (ex. element)
- Value: Paramaeter value (ex. ${element})
- Web Server
-
Add the listener
Add a “View Results Tree” to the Test Plan or the same Thread Group to confirm that it works.
Add > Listener > View Results Tree -
Execute the load test
MENU > Run > Remote Start All -
Confirm the results
View Results Tree to check some HTTP requests.
Use different CSV files for each JMeter servers
In this case, make requests using different CSV files on each of the three JMeter servers.
Change the configurations from the aforementioned CSV file.
-
Prepare CSV files
-
Know the IP address of each JMeter servers Include the IP address of the JMeter servers in the file name or directory name of the CSV files so that the JMeter servers can determine which CSV file to use.
Open the JMeter’s menu > Run > Remote Start and note the list of IP addresses that appear there.(No port number is required)
-
Create as directories as there are JMeter servers, including the IP address of each JMeter servers in its name
-
Create CSV files in each directories
ex.
/mnt/jmuserdata/10.0.2.4/chemicalelements.csvatomic_number,symbol,element 1,H,Hydrogen 2,He,Helium 3,Li,Lithium 4,Be,Beryllium 5,B,Boron 6,C,Carbon 7,N,Nitrogen 8,O,Oxygen 9,F,Fluorine 10,Ne,Neon
/mnt/jmuserdata/10.0.2.5/chemicalelements.csv
atomic_number,symbol,element 11,Na,Sodium 12,Mg,Magnesium 13,Al,Aluminium 14,Si,Silicon 15,P,Phosphorus 16,S,Sulfur 17,Cl,Chlorine 18,Ar,Argon 19,K,Potassium 20,Ca,Calcium
/mnt/jmuserdata/10.0.2.6/chemicalelements.csv
atomic_number,symbol,element 21,Sc,Scandium 22,Ti,Titanium 23,V,Vanadium 24,Cr,Chromium 25,Mn,Manganese 26,Fe,Iron 27,Co,Cobalt 28,Ni,Nickel 29,Cu,Copper 30,Zn,Zinc
-
-
Copy the CSV files to the local disk of the JMeter servers
- Enable the “setUp Tread Group”, which was disabled
- Disable all other Thread Groups, etc
- Replace the second line of Command parameters Value in “Copy CSV files” with the following
cp -f /mnt/jmuserdata/${__machineIP}/* /tmp
- Copy the CSV file by running the test
MENU > Run > Remote Start All - Confirm the results
- Enables the disabled Thread Group, etc., and disables the “setUp Thread Group”
-
Execute the load test
MENU > Run > Remote Start All
* No changes are required for samplers or listeners. -
Confirm the results
View Results Tree to see some HTTP requests.
Make sure the combination of the IP address output to Sampler result and QueryString output to Request > Request Body matches the CSV files you created.
This is the end of this tutorial.