"Introduction to JMeter" @ CPTM 3rd Session
-
Upload
tharinda-liyanage -
Category
Education
-
view
8.972 -
download
4
description
Transcript of "Introduction to JMeter" @ CPTM 3rd Session
Introduction to JMeter
By Ranil Weerasinghe &
Tharinda Liyanage
What will be covered…
• 1st Phase
• Getting to know about the tool
• Types of Applications/protocols• Features• Installation and configuration• Components• Strengths and Weaknesses
• 2nd phase
• Practical session with examples
What is JMeter• Performance testing tool (like LoadRunner, WebLoad, OpenSTA , etc)
• It supports performance testing of:
• Web application • Web services (SOAP and REST)• Database query performance• Mail - SMTP(S), POP3(S) and IMAP(S)• JMS• Mobile
• Apache Project - http://jmeter.apache.org/
• 100% pure Java desktop application
• Originally developed by Stefano Mazzocchi
Features of JMeter• Load and performance test various protocols - HTTP(S), FTP, JDBC, JMS, LDAP, SOAP
•HTTP proxy server for recording test scripts – eliminates 3rd party recording tools like “Badboy”
•Platform Independent
•Execution can do in batch mode and analyze offline.
•Distributed testing.
•Extensible. – Plugins (https://code.google.com/p/jmeter-plugins/)
Test Architecture
Strengths • Free and open source
• Active development/ community
• Extensibility
• Capability of dynamic scripting/ generate load/ and reporting
• Supports automation (Maven with Jenkins CI for performance testing in regression mode)
• Cloud compatibility
Weaknesses
• Memory management issues But …adjust Heap memory/ use 64-bit version/ run non-GUI mode • Reports are a bit lacking But... Plugins provides many
• Steep learning curveLack of Training opportunities and require technical skills
• Limited Support No dedicated support like commercial tools
Setting Up and Running JMeter
• The latest version of JMeter can be downloaded from the project website: http://jmeter.apache.org/download_jmeter.cgi
• JMeter requires a fully compliant JVM 1.6 or higher. You need Java, with the JAVA_HOME environment variable set.
• To install a release build, simply unzip the zip/tar file into the directory where you want JMeter to be installed.
• To run JMeter, run the jmeter.bat (for Windows)• or jmeter.sh (for Unix) file.
JMeter Elements• Test Plan: where the overall settings for a test are specified.
• Thread groups: defines a pool of users that will execute a particular test case against your server.
• Samplers: sends requests to a server• Logical controllers : control flow of test plan (loops, conditionals, ordering, etc.)• Listeners: record, summarize and display record and response data• Timers: introduce delays in test plan• Assertions: assert facts about responses, for functional testing• Configuration elements: Configuration Elements set default values for other parts of
the Test Plan as well as configure variables.• Pre-processors and post-processors
• Workbench :It provides a place to temporarily store test elements while not in use for copy/paste purposes • JMeter Proxy Server : watch and record your actions while you browse your web
application with your normal browser
Test plan• Where the overall settings for a test are specified.
Thread group
• Thread group elements are the beginning points of any test plan.
• It controls the number of threads JMeter will use to execute your test
Samplers
• Samplers tell JMeter to send requests to a server and wait for a response.
• Processed in the order they appear in the tree.
• Controllers can be used to modify the number of repetitions of a sampler.
• HTTP Request
• JDBC Request
• Java object request
• LDAP Request
• SOAP/XML-RPC Request
• FTP Request
Logical controllers
• Loop Controller
• If controller
• Transaction Controller
• Recording Controller
Logic Controllers determine the order in which Samplers are processed
Some controller are:
Listeners
• “Listen" to the test results.
• View, save, and read saved test results
• Can be saved to JTL, CSV or XML format.
• Listeners can be added anywhere in the test, including directly under the
test plan.
Listeners
Timers
• Add delay to script
• If not, overwhelms your server
• Ex:
• Constant timer
• Random timer
• Synchronizing timer
Assertions
• Verify correctness of your response.
• Ex:
• Response assertion – Verify fields of response
• Size assertion - tests that each response contains the right
number of bytes in it
• Duration assertion- tests response received within a given
amount of time
Functions & Variables• Variables – to parameterized
• JMeter variables are local to each thread.• Referenced as ${VARIABLE}
•Functions• Are special values that can populate fields of any Sampler or other element in a
test tree ${__FunctionName()}
• Types• Information
• Ex: ${__log()}• Input
• Ex: ${__StringFromFile()}• Calculations
• Ex: ${__RandomString()}
Demo
1. Adding a Thread Group Test Plan -> Thread Group
– Number of thread– Ramp-up Period– Loop count
2. Adding a HTTP Request Defaults Test Plan -> Thread Group -> HTTP Request Defaults (HTTP Request Defaults saves you time when doing lots of HTTP Samplers)
– Protocol – enter “HTTP”– Server name – enter “jakarta.apache.org”– Path – leave blank– Port number – enter “80”
How to Build a Test Plan
How to Build a Test Plan Cont..3. Adding a HTTP Proxy Server
Workbench -> HTTP Proxy Server
– Port field - Enter “9090”– Target Controller – click on the drop down and select “test plan > thread group”– Click the “add” button in “Patterns to include”. – This will create a blank entry. Enter “.*\.html”– Click the “add” button in “Patterns to exclude”. – This will create a blank entry. Enter “.*\.gif”– Click the “start” button at the bottom
4. Setting a Proxy in IE – Start Internet Explorer, but do not close Jmeter.
– From the tool bar, click “tools -> internet options”.
– Select the “connection” tab
– Click “LAN settings” button
– On the connections tab, check “Use a proxy server for your LAN”.
How to Build a Test Plan Cont..– Address – enter “Localhost” or the IP address of your system
– Port – enter “9090”.
– Click “ok” button
– Click “ok” button again. This should return you to the browser
– In the “Address” bar at the top, enter “http://jakarta.apache.org/jmeter/index.html” and hit the “enter” key.
– Click on a few links on Jmeter's page.
– Close internet explorer and bring up the JMeter window.
5. Adding a Listeners
Test Plan -> Thread Group -> Listeners
– Graph Results
– View Results in table
– View Results in tree
– Aggregate report
How to Build a Test Plan Cont..
6. Adding a Cookie Manager
Test Plan -> Thread Group -> HTTP Cookie Manager
Many Web applications use cookies. JMeter provides cookie capabilities through a Cookie Manager. Adding this element to a thread group allows you to send cookies to the application being tested, just as Web browsers do.
Creating a Load Test Scenario and Execution
JMeter Performance Test Results- View Results Tree
JMeter Performance Test Results- Summary Report
Assertions• Assertions allow you to assert facts about responses received from the server being
tested. Using an assertion, you can essentially "test" that your application is returning the results you expect it to.
Parameterization – User Define Variables
• Thread Group -> Config Element -> User Define Variables
Parameterization – CSV Data Set Config
• Thread Group -> Config Element -> CSV Data Set Config
Parameterization – CSV Data Set Config
Session Handling
Session Handling Cont..
Session Handling Cont.. • Thread Group -> Post-Processors -> Regular Expression Extractor
Session Handling Cont..
Regular Expressions* - Matches 0 or more time+ - Matches 1 or more time.(dot) – match any character? – stop when first match succeeds( and ) – these enclose the portion of the
match string to be returnedMore Regular Expressions
http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html
Session Handling Cont..
Session Handling Cont..
JMeter Best Practices
Use non-GUI mode: jmeter -n -t test.jmx -l test.jtl
Use as few Listeners as possible; if using the -l flag as above they can all be deleted or disabled.
Don't use "View Results Tree" or "View Results in Table" listeners during the load test, use them only during scripting phase to debug your scripts.
Rather than using lots of similar samplers, use the same sampler in a loop, and use variables (CSV Data Set) to vary the sample. Or perhaps use the Access Log Sampler. [The Include Controller does not help here, as it adds all the test elements in the file to the test plan.]
JMeter Best Practices Cont.. Don't use functional mode
Use CSV output rather than XML
Only save the data that you need
Use as few Assertions as possible
JMeter Distributed Testing- Pre conditions• The firewalls on the systems are turned off.• All the clients are on the same subnet.• The server is in the same subnet, if 192.x.x.x or 10.x.x.x ip addresses are used. If the serverdoesn't use 192 or 10 ip address, there shouldn't be any problems.• Make sure jmeter can access the server.• Make sure you use the same version of Jmeter on all the systems. Mixing versions maynot work correctly.• Following image Illustrate the way, how the JMeter Master / Slave configuration works