Aug 20, 2013

Starting Performance Testing with Jmeter

This post is about performing tests in a web server using Jmeter.
First, to start load tests or performance tests, some planning is necessary in the following activities:

  • Understanding web application architecture, network environment and business rules and needs.
  • Choosing tools to automate load/performance tests
  • Selecting user scenarios, identifying the critical points.
  • Paying attention  to the test environment, there must be a network dedicated to testing and a good machine to run test automation tools and tools to monitor the net and the CPU of the server. 
  • Recording selected scenarios.
  • Choosing adequate reports to analyse the data from execution.
  • Analysing and generating reports.

Using Jmeter

Jmeter is an opensource tool used in performance testing, load testing and stress testing. It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types.

Jmeter can be downloaded through Apache Jmeter web site 

The Jmeter installation is very simple. It requires JRE/JDK correctly installed and the JAVA_HOME environment variable set. Just unzip the zip/tar file into the directory where you want JMeter.
In the Jmeter/bin directory you can run the jmeter.bat (for Windows) or jmeter (for Unix) file.

Jmeter Interface
First element is Test Plan, selecting and rigth click add the component Thread Group needed for the test.
TestPlan -> Add -> Threads (Users) -> Thread Group.

It's interesting to add the element called Recording Controller. It will help to organize the test scenarios according to functionality to be tested.

Right Click on Thread Group -> Add -> Logic Controller ->  Recording Controller

Then, it's good to add listeners to see the data generated by tests.

Thread Group right click ->Listener -> Agregate Gragh
Thread Group right click ->Listener -> Summary Report

If you want to collect isolated results, add listener just for Recording Controller.

Recording Controller right click ->Listener -> Agregate Gragh

After, the element HTTP Proxy Server must be added, it allows Jmeter to record the user requests and turns them into object Samplers.
  • Right click in Workbench -> Add -> Non Test Elements -: HTTP Proxy Server.
  • Open the browser and configure it to listen to the proxy server port which is set in Jmeter proxy server (default : localhost: 8080)
  • In Jmeter -> HTTP Proxy Server select in Target Controller your Thread Group and your Recording Controller created.
  • In Jmeter -> HTTP Proxy Server -> click on the Start button.
  • Execute the actions in the browser , they will be recorded by Jmeter.
  • Afterwards, access the web page and record the user scenarios.
When it finishes just go back to Jmeter and Stop HTTP Proxy Server. It's good to delete images, css files and scripts before running the tests.

Next, select Thead Group, in Thread Properties and set:
  • The number of threads: they are used to simulate concurrent connections to your server application.
  • The ramp-up period:  how long it take to "ramp-up" to the full number of threads chosen
  • Number of times to execute the test.
 Example: Set 10 threads and the ramp-up period 100 seconds. So, it will take 100 seconds to get all 10 threads up and running.

The next step is to select the Play button in Jmeter toolbar.

OBS: If you set a large number of threads for example 1000 and the Jmeter freezes showing Memory leak in command line. Verify the RAM memory of the computer and Edit the following line of Jmeter.bat :
set HEAP=-Xms2048m -Xmx2048m
For a good performance. It is recommended to execute a large number of threads in Jmeter using a computer with more then 4GB RAM.

When the execution stops, observe the Summary Report. It will show values on measurement.

  • Labelhttp request recorded.
  • Samplesnumber of http request ran for threads. 
  • Average:   average response time for http request. T
  • Minthe minimum response time taken by the http request. 
  • Max the maximum response time taken by the http request. 
  • Std.Deviation: how many cases were deviating from the average value of the receiving time.  
  • Error %: error percentage in samples during run. 
  • Throughput: number of requests per unit of time sent to server.

In Agregate Graph, the results are plotted and it is possible to identify bottlenecks of the http requests.
Agregate Graph

No comments:

Post a Comment