Apache JMeter: Input from File, with HTTP Testing as An Example

Previous post covers how to set up basic HTTP testing with Apache JMeter. Many times we found ourselves need to read input from a file, say, a list of URLs for testing. Apache JMeter can be easily configured to do so. We’ll walk through a HTTP testing reading from URLs from an input text file.

0. Add Thread Group: Start JMeter, right click Test Plan > Add > Thread Group.

1. Add HTTP Request: Right click Thread Group > Add > Sampler > HTTP Request, specify the Path as ${PATH}, leave everything else as default. This is shown as below,
2. Add CSV Data Set Config: Right click Thread Group > Add > Config Element > CSV Data Set Config. Set the filename as the file contains the input URLs, Variables Names as “PATH,”,  Delimiter as “n”, so that JMeter will parse the URLs line by line and each line is fed to the PATH variable, which we used in HTTP Request at step 1. Another two important settings are Recycle on EOF and Stop Thread on EOF.

Recycle on EOF: The file is re-read from the beginning once it reaches EOF if set to true. In this  test, we set it to false.

Stop Thread on EOF: if Recycle on EOF is set to false, should the thread be stopped on EOF. In this test, we set it to true.

Below is a screenshot of what is the settings look like,

3. Add Listeners: Add listeners to show the testing results, we added Graph Results, View Results Tree and View Results in Table in our test.

4. Adjust Group Thread Settings: Adjust Thread Group settings. In our test, we set the settings as below,

In this case, JMeter will fire up 5 threads in 1 second and each thread will fetch 200 URLs from the input text file. Thread 1 fetches first line, thread 2 fetches second line etc. Since we set the Recycle on EOF at CVS config as false, the test will end either the input file reaches an end or 1000 URLs are fired.

If we set Recycle on EOF as true, the test will only end only 1000 URLs are fired as it can re-read the URLs from the beginning of the input file once it reaches EOF.

5. Test results: We can run the test, and view the results in the three listeners in different format.

Apache JMeter user manual: http://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config

Apache JMeter for HTTP Testing

Apache JMeter is a Java application used for various testing and performance evaluation. It is originally designed for web testing but has been extended to support other functions.

This post covers the basic steps of setting JMeter for HTTP testing on Ubuntu.

0. Install JMeter

At Linux Ubuntu, type the command below,

$ sudo apt-get install jmeter

Alternatively, one can go the official website to download the latest release. Once installed, start JMeter by command jmeter.

1. Right click Test Plan > Add > Thread Group. The Thread Group has several fields to allow us adjusting the testing behavior.

Figure 1. Thread Group

2. Right click Thread Group > Add > Config Element > HTTP Request Defaults. The settings in this configuration element will be applied to all HTTP requests we created later. We simply set the server name and leave the rest of the settings as default. This is shown as below,

Figure 2. HTTP Request Defaults

3. Right click Thread Group > Add > Sampler > HTTP Request. We leave all settings unchanged except for the path. We set path to the url we want to test, in this case, we want to test the YouTube About page. This is shown as below,

Figure 3. HTTP Request

We also add another HTTP Request to test Press&Blogs page.

4. Right click Thead Group > Add > Listener > View Results in Table. This will allow us to view all the testing results.

5. Save the test plan and run the test by clicking run > start.

6. Below is the testing results.

Figure 4. View Results in Table

7. We can add other listeners like View results in Tree, Graph Results etc. Each listener allows us to see the results in a different way.

1. Apache JMeter website: http://jmeter.apache.org/