Saturday, October 15, 2011

Performance test using Apache JMeter

Load testing the web applications Using the Apache JMeter:
  1. Setting up JMeter :
  2. Start the JMeter:
    • To start the JMeter, Go to bin folder and click on 'jmeter.bat' Or you can start from the command  prompt  (/bin/jmeter.bat on Windows)
  3. Create a test plan:
    •  Right click on Test plan, Add Thread group, This results in
    • Thread group properties:
      • Name : The name of this thread group. You can give a descriptive name to this property.
      • Number of Threads (users) - the number of threads created. Each thread represents a single user. Therefore, if you want to simulate a load test with 10 concurrent users, enter 10 as the value for this property.
      • Ramp-Up Period (in Seconds) :  The number of seconds JMeter will take to accelerate to create all of the threads needed. If the number of threads used is 10 and the ramp-up period is 20 seconds, JMeter will take 20 seconds to create those 10 threads, creating one new thread every two seconds. If you want all threads to be created at once, put 0 in this box.
      • Forever: If clicked, this option tells JMeter to keep sending requests to the tested application indefinitely. If disabled, JMeter will repeat the test for the number of times entered in the Loop Count box.
      • Loop Count: This property value only has an effect if the Forever check box is unchecked. It tells JMeter the number of times it has to repeat the test.
  4. Configuring the HTTP Proxy server :
    • JMeter can work as a proxy between your browser and server and record a user's HTTP session, mainly to capture the individual HTTP requests, that can be re-played in a JMeter thread group later.
    • Right click on the Workbench node, Add-> Non-test elements ->HTTP Proxy server 
    • Configure the HTTP Proxy server setup
      • Port - Set a number that wont clash with an existing HTTP server on your system (set as - 8085)
      • Target Controller – set to "Test Plan > Thread Group".  - When the proxy server records the HTTP session between your browser and server, this setting implies the HTTP requests will be recorded against the Thread Group you created earlier, so we can reuse them later
      • URL Patterns to include – a regular expression based string that tells the proxy server which URLs to record, and those to ignore. To capture everything set it to .* (dot star).
      • HTTP Proxy server setup looks like this
Http proxy server setup
  1. After this we need to configure the browser
    1. To capture the traffic between your server and browser, setup the browser proxy configuration
    2. Firefox browser -> Tools-> Options menu ->  Advanced menu -> Network tab ->Settings will open the connections settings window
    3. Select Manual Proxy configuration 
      • HTTP Proxy – localhost
      • Port – 8085 as per the JMeter HTTP Proxy Server option we set earlier

Recording your HTTP Session :
    1. In JMeter hit the START button on the HTTP proxy server page 
    2. Goto browser and enter the website homepage URL which you want to stress test (www.test.com)
    3. Now navigate your web application, enter data and so on, JMeter will record each HTTP request between the browser in server against your Thread Group. 
    4. After recording your website actions, comeback to JMeter and click on STOP button
    5. To view the each thread expand the Thread Group and you'll see each HTTP request made from the browser to server
HTTP Session

Configuring the Thread group for replay:
  • To capture the cookie and session to track the each unique user session, we need to add HTTP cookie manager, Right click on the Thread Group -> Add -> Config Element -> HTTP Cookie Manager. and move it to the Top of the tree. Adding this element to a thread group allows you to send cookies to the application being tested.
  • To view the results we need to add the Listeners, Right click on the Thread Group ->Add -> Listener ->View results in Tree, View results in Table, Summary report. these will be added at the end of the Thread Group
  • Finally Save the Test Plan 
Running the Test plan :
  • The default Thread group will be set to 1, leave as it is, verify the overall test once
  • To run the test select the Run menu or press Ctrl-R -> Start, while running the thread group, you will see the top right of the JMeter has little box shows the green color, which means test is running, once the tests are complete, the green color will change to gray color.

View results in tree:

This Tree result displays the successful HTTP request in green triangles,  Error in the request displays in the red color

View results in table:

This Table result displays the average time to run the testplan and the deviation.


Load test:
Change the thread group number to a higher number and run the test 

Start building your test plan and explore the JMeter

For more information, Check the JMeter user manual : 




No comments:

Post a Comment