"introduction to jmeter" @ cptm 3rd session

40
Introduction to JMeter By Ranil Weerasinghe & Tharinda Liyanage

Upload: tharinda-liyanage

Post on 11-May-2015

8.966 views

Category:

Education


4 download

DESCRIPTION

This is a presentation done at 3rd session of Colombo PerfTest Meetup

TRANSCRIPT

Page 1: "Introduction to JMeter" @ CPTM 3rd Session

Introduction to JMeter

By Ranil Weerasinghe &

Tharinda Liyanage

Page 2: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 3: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 4: "Introduction to JMeter" @ CPTM 3rd Session

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/)

Page 5: "Introduction to JMeter" @ CPTM 3rd Session

Test Architecture

Page 6: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 7: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 8: "Introduction to JMeter" @ CPTM 3rd Session

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.

Page 9: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 10: "Introduction to JMeter" @ CPTM 3rd Session

Test plan• Where the overall settings for a test are specified.

Page 11: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 12: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 13: "Introduction to JMeter" @ CPTM 3rd Session

Logical controllers

• Loop Controller

• If controller

• Transaction Controller

• Recording Controller

Logic Controllers determine the order in which Samplers are processed

Some controller are:

Page 14: "Introduction to JMeter" @ CPTM 3rd Session

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.

Page 15: "Introduction to JMeter" @ CPTM 3rd Session

Listeners

Page 16: "Introduction to JMeter" @ CPTM 3rd Session

Timers

• Add delay to script

• If not, overwhelms your server

• Ex:

• Constant timer

• Random timer

• Synchronizing timer

Page 17: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 18: "Introduction to JMeter" @ CPTM 3rd Session

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()}

Page 19: "Introduction to JMeter" @ CPTM 3rd Session

Demo

Page 20: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 21: "Introduction to JMeter" @ CPTM 3rd Session

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”.

Page 22: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 23: "Introduction to JMeter" @ CPTM 3rd Session

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.

Page 24: "Introduction to JMeter" @ CPTM 3rd Session

Creating a Load Test Scenario and Execution

Page 25: "Introduction to JMeter" @ CPTM 3rd Session

JMeter Performance Test Results- View Results Tree

Page 26: "Introduction to JMeter" @ CPTM 3rd Session

JMeter Performance Test Results- Summary Report

Page 27: "Introduction to JMeter" @ CPTM 3rd Session

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.

Page 28: "Introduction to JMeter" @ CPTM 3rd Session

Parameterization – User Define Variables

• Thread Group -> Config Element -> User Define Variables

Page 29: "Introduction to JMeter" @ CPTM 3rd Session

Parameterization – CSV Data Set Config

• Thread Group -> Config Element -> CSV Data Set Config

Page 30: "Introduction to JMeter" @ CPTM 3rd Session

Parameterization – CSV Data Set Config

Page 31: "Introduction to JMeter" @ CPTM 3rd Session

Session Handling

Page 32: "Introduction to JMeter" @ CPTM 3rd Session

Session Handling Cont..

Page 33: "Introduction to JMeter" @ CPTM 3rd Session

Session Handling Cont.. • Thread Group -> Post-Processors -> Regular Expression Extractor

Page 34: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 35: "Introduction to JMeter" @ CPTM 3rd Session

Session Handling Cont..

Page 36: "Introduction to JMeter" @ CPTM 3rd Session

Session Handling Cont..

Page 37: "Introduction to JMeter" @ CPTM 3rd Session

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.]

Page 38: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 39: "Introduction to JMeter" @ CPTM 3rd Session

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

Page 40: "Introduction to JMeter" @ CPTM 3rd Session