Tuesday, January 31, 2012

JMeter quick start guide (part 2)

--------------------------
2. Setting up and recording a test
--------------------------

Overview:

A Test Plan is a group of Thread Groups which all run concurrently.

A Thread Group is a set of config elements and series of HTTP Requests (known as Samplers) for a user or group of users to execute in order. If there are several users in the group, each of them can be thought of as a Thread, and in fact each will run in its own java thread. I typically break Thread Groups down into groups of users of a specific type exercising a specific part of the application. For example: Inst users that each do 1 request or Partner users that visit several screens and exercise DWR functions (sort/filter lists) or Admin users that each run 3 reports.

In our setup, a Thread Group typically has a CSV Data Set Config, a Cookie Manager, a Uniform Random Timer, and the HTTP Requests.

Setting up a Test Plan:

  1. right click on your Test Plan, Add -> Config Element -> CSV Data Set Config
    1. Name: Hostname Config
    2. Filename: ../data/input/HOSTNAME.csv
    3. Variable Names: HOSTNAME
    4. Delimiter: a plain comma char
    5. Recycle on EOF?: I usually set this to true and use the Thread Group's Number of Threads and Loop Count to control how the test runs
    6. Stop thread on EOF?: again, I usually use the Thread Group to control this
  2. right click on your Test Plan, Add -> Listener -> Graph Results
    1. Filename: ../data/output/out_graph_results.csv
    2. on the Graph Results screen, click Configure
      1. uncheck any box with (XML)
      2. check: save field names, save active thread counts, save assertion failure message

Setting up a Thread Group in JMeter (we'll use my Inst User (IU) group 01 as an example):

  1. right click on your Test Plan, Add -> Thread Group
    1. give it a descriptive name and description in comments field
    2. Number of Threads: If you have 10 users in your input .csv, this # can be up to 10.
    3. Rampup: If it's a heavy duty test (20+ min), not bad to make it ramp for a couple minutes.
    4. Loop Count: Only tricky thing here is if you have 10 users in your .csv and you enter 3 in the Number of Threads and 2 in Loop count, users 1-6 in your .csv will each run the HTTP Requests 1 time. Another thing is, in this scenario for example, it will try to keep 3 threads alive, meaning if threads 1 and 2 finish and thread 3 is slow, threads 4 and 5 will kick off and run while 3 is also running.
  2. right click on your Thread Group, Add -> Config Element -> HTTP Cookie Manager
    1. done with cookie manager
  3. right click on your Thread Group, Add -> Config Element -> CSV Data Set Config
    1. Filename: something like "../data/input/IU_01.csv"
    2. Variable Names: a comma separated list of your var names such as IU_01_USER,IU_01_PASS
    3. Delimiter: a plain comma character
  4. right click on your Thread Group, Add -> Timer -> Uniform Random Timer
    1. I'm not positive this is the best way to do this, but I believe it is: Let's say you're running a report. When you record the test and you're actually going through the process of logging in, running the report, logging out, let's say it takes you 3 minutes. Now when you run the test, it will run the requests back-to-back, making it take 20 seconds or so. Play with the Timer's Random Delay Maximum field and try to find a number that makes the test take about 3 minutes so that it simulates a real user. Mine are typically between 1500-2500ms
  5. save your Test Plan in the data folder (jakarta-jmeter-2.5.1/data) and give it a descriptive name, not for the Thread Group but for the whole Test Plan!

Set up HTTP Proxy (for recording) in JMeter:

  1. right click Workbench -> Add -> Non-test Elements -> HTTP Proxy Server
  2. if you have a specific Thread Group that you want to save the recording to, choose it in the Target Controller dropdown
  3. check Attempt HTTPS Spoofing
  4. under URL Patterns to Exclude, click Add
  5. double-click the text area just created, enter .*google.* and press enter (don't want requests to google fouling up our response time metrics!)
  6. save the test plan

Record from Firefox (IE is similar):

  1. start Firefox
  2. go to Tools -> Options
  3. click Advanced at the top
  4. click the Network tab
  5. under Connections click Settings
  6. click the Manual Proxy Config radio button
  7. in HTTP Proxy enter localhost, port 8080
  8. check "Use this proxy server for all protocols"
  9. clear out the "No proxy for" text area
  10. click ok a few times
  11. if you want to simulate a user who has not been to the site before (has no JS cached), go to Tools -> Clear Recent History and clear it out
  12. in the browser address bar now instead of using https... you'll use http... when entering the app URL
  13. in JMeter, click Start at the bottom of the HTTP Proxy Server config screen
  14. log in, run a report, do whatever it is you want to record, log out
  15. in JMeter, click Stop at the bottom of the HTTP Proxy Server config screen
  16. undo the Proxy settings in Firefox if you're done
  17. save the Test Plan

No comments:

Post a Comment