PHPUnit and Selenium provide means for testing application functionality. But how can you test your application's performance? Here Apache JMeter comes in handy, as a tool used for load testing functional behaviour and measure performance.
JMeter is a desktop application, written in Java, made available as a package on most Linux distributions. It can be used for load testing various server types, such as HTTP, TCP, LDAP, FTP and others, as well as producing interesting reports. In the first part of this article, I provide an example setup on Ubuntu Linux:
- Install JMeter-http:
sudo apt-get install jmeter-http
- Download JMeter Plugins, required for producing graphs:
wget http://jmeter-plugins.googlecode.com/files/JMeterPlugins-libs-1.0.0.zip wget http://jmeter-plugins.googlecode.com/files/JMeterPlugins-1.0.0.zip
- Install the plugins and their libraries:
sudo unzip JMeterPlugins-1.0.0.zip -d /usr/share/jmeter/lib/ext/ sudo unzip JMeterPlugins-libs-1.0.0.zip -d /usr/share/jmeter/lib/
Once JMeter and the required plugins are installed, you can fire up the application by executing 'jmeter' from the command line. The application starts with a default blank 'Test Plan'.
Here is a description of components required for a basic test:
- Thread Group: "Thread group elements are the beginning points of any test plan. All controllers and samplers must be under a thread group". Here you can configure the number of Threads (Users to emulate), Ramp-Up period (how long to wait until loading the full number of threads), and the number of times to execute the test (setting a Loop Count, Forever, or Scheduled).
- HTTP Request: HTTP Requests are Sampler Controllers used for sending HTTP Requests. Each Sampler belongs to a Thread Group, thus being executed as many times as the Loop value is configured. Here you can configure the Server Name, Protocol, Request Method, Path, and various other HTTP request parameters.
- Timeline Graphs: The previously installed plugins provide a set of Listeners. Listeners are components that make use of the information gathered by JMeter. Here are a few interesting plugins: Response Times Over Time and Response Latencies Over Time. Each Listener should belong to an HTTP Request.
Create a basic test:
- Right click 'Test Plan', and select 'Add' -> 'Threads (Users)' -> 'Thread Group'.
- Right click the newly created 'Thread Group', and select 'Add' -> 'Sampler' -> 'HTTP Request'.
- Right click 'HTTP Request', and select 'Add' -> 'Listeners' -> 'jp@gc – Response Times Over Time'.
- Right click 'HTTP Request', and select 'Add' -> 'Listeners' -> 'jp@gc – Response Latencies Over Time'.
- Click 'Thread Group': Depending on your client system CPU, RAM and Bandwidth, you can configure a number of Threads(Users), Ramp-Up Period and Loops. In this example, I use 10 threads, 1 second ramp-up period, and 10 loops:
- Click 'HTTP Request': Configure the 'Server Name or IP' parameter to point to you server's Virtual Host Name or IP Address, and the 'Port Number' parameter. The 'Path' parameter specifies which URL to open. By default the protocol used is HTTP, but it can be configured to use HTTPs:
Various other options can be configured, such as GET/POST/COOKIE paramaters, proxy servers, optional tasks, file uploads, and so on. However, for the purpose of this test I focus on the main settings required to get it started.
To run the test:
- Click 'Run' -> 'Start'
Resulting graphs, for grosan.co.uk, using the above configuration:
- Response Times Over Time:
How to read the above chart: The X Axis specifies the time a request begins, the Y Axis indicates the time spent to receive a response.
- Response Latencies Over Time:
How to read the above chart: The X Axis specifies the time a request ended, the Y Axis indicates the time to receive a response.
While this entry does not go into the details of creating complex tests, it provides a starting point for performance testing. Apache JMeter is a powerful tool, that can be extended to use plugins, monitor server resources and produce comprehensive reports.