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

  1. Prepare a CSV file
  2. Copy the CSV file to the local disk of the JMeter servers
  3. Configure CSV Data Set Config to import values from a CSV file
  4. Use that values in the sampler
  5. Add the listener
  6. Execute the load test
  7. 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

  1. 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
    
  2. 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.

    1. Launch the JMeter on JMeter client.
    2. Add a “setUp Thread Group” to the Test Plan. Add > Threads > setUp Thread Group
    3. Add a “OS Process Sampler” to the setUp Thrad Group Add > Sampler > OS Process Sampler
      Copy CSV files
      • 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.

    4. Add a “View Results Tree” to the setUp Thread Group Add > Listener > View Results Tree
    5. Copy the CSV file by running the test
      MENU > Run > Remote Start All
    6. Confirm the result If the Response code is 0 in the View Results Tree, the command has succeeded.
      View Reults Tree - Copy CSV files
      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.

    7. 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.

  3. Configure CSV Data Set Config to import values from a CSV file

    1. Add a “Thread Group” to the Test Plan Add > Threads (Users) > Thread Group
      “Loop Count” should be set to “3” and so on.
    2. Add a “CSV Data Set Config” to the Test Plan or the Thread Group
      Add > Config Element > CSV Data Set Config
      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.
  4. 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
    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})
  5. 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

  6. Execute the load test
    MENU > Run > Remote Start All

  7. Confirm the results
    View Results Tree to check some HTTP requests.

    • Sampler result tab
      The IP address of the JMeter Server that has been accessed is displayed in the Thread Name.
      View Results Tree > Sampler result
    • Request > Request Body tab
      The QueryString in the url shows the value of the CSV file.
      View Results Tree > Request > Request Body

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.

  1. Prepare CSV files

    1. 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)
      Remote servers

    2. Create as directories as there are JMeter servers, including the IP address of each JMeter servers in its name

    3. Create CSV files in each directories

      ex.
      /mnt/jmuserdata/10.0.2.4/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
      

      /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
      
  2. Copy the CSV files to the local disk of the JMeter servers

    1. Enable the “setUp Tread Group”, which was disabled
    2. Disable all other Thread Groups, etc
    3. Replace the second line of Command parameters Value in “Copy CSV files” with the following
      cp -f /mnt/jmuserdata/${__machineIP}/* /tmp
      Copy CSV Files
    4. Copy the CSV file by running the test
      MENU > Run > Remote Start All
    5. Confirm the results
    6. Enables the disabled Thread Group, etc., and disables the “setUp Thread Group”
  3. Execute the load test
    MENU > Run > Remote Start All
    * No changes are required for samplers or listeners.

  4. 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.