In PTS performance testing, you can use parameterization to build service requests that dynamically change. If you have the same requirement for dynamic stress testing when using JMeter stress testing, we recommend adding Config Element: CSV Data Set Config to the JMeter script for reading parameters from CSV files. At the same time, JMeter performance testing supports splitting CSV files and distributing data in the CSV files to each stress testing engine.
Background
CSV Data Set Config is an official configuration element provided by JMeter to read data from CSV files and split the data into variables. The element is suitable for scenarios where a large number of variables are processed.
If no CSV Data Set Config is added in the JMeter script for an uploaded CSV file, the CSV file is split by default as if it does not contain table headers (variable names). To facilitate operations and prevent data from being incorrectly split, we recommend configuring CSV Data Set Config to use CSV parameter files.
Configure CSV parameter files
To build stress testing requests that dynamically change, you need to configure CSV files in the JMeter script.
For example, to test the performance of the logon API of a website when 100 users log on to the website at the same time, 100 different user logon data records need to be generated. Perform the following steps:
Create a CSV file that contains 100 user data records. The first line in the CSV file is the table header, indicating the variable name. The following shows an example of the basic format:
username,password user1,Password1 user2,Password2 user3,Password3
NoteIf the CSV file contains no table headers, configure variable names in CSV Data Set Config.
Add CSV Data Set Config to Thread Group.
In the CSV Data Set Config configuration section, enter the CSV file name. Keep the default values for other configuration items. JMeter automatically reads parameter names from the table header of the CSV file as variable names.
NoteIf the CSV file contains no table headers, enter
username
andpassword
in Variable Names (comma-delimited) of CSV Data Set Config.Configure Sampler.
Right-click the thread group and choose Add > Sampler > HTTP Request. Set configuration items based on the service API. Example:
Name: specifies the API name.
Web Server: Enter the specific service API protocol, service name or IP address, and port number.
HTTP Request: Select a request method and enter the path.
Body Data tab: Use
${username}
and${password}
to read parameters in the CSV file.
Save the JMeter test script.
Upload the test script and the CSV file to PTS. For more information, see Create a JMeter scenario.
Split CSV files
Select Split File next to the CSV file to split data in the CSV file to each stress testing engine.
Split CSV files that contain file headers
When the original CSV file contains a file header, each split file retains this header, and the data is not duplicated. If the data records cannot be evenly distributed, some engines may have one more data record than others.
For example, when data in the preceding sample file is split into two engines:
The first file contains:
username,password user1,Password1 user3,Password3
The second file contains:
username,password user2,Password2
Split CSV files that contain no file headers
If the CSV file does not contain a file header (the first row is CSV data), such as in the case of a file named "b.csv" with contents:
user1,Password1
user2,Password2
user3,Password3
Configure variable names in JMeter, as shown in the following figure.
In this case, if you choose to split the CSV file, the split file does not retain the file header. If the data records cannot be evenly distributed, some engines may have one more data record than others. For example, when data is split into two engines:
The first file contains:
user1,Password1 user3,Password3
The second file contains:
user2,Password2
More details
For more information about how to configure and use CSV files, see JMeter documentation.