UKCMG TEC 2010 Track P - Performance Session P7 Paul Seaton-Smith Agenda Performance Testing Costs Test Environment Scripting and Testing Resources Automated Test Tools Installation Test Plan Hierarchy Thread Groups Recording a Browser Session Script Parameterisation Regular Expression Extractor Response Assertions Assertion Results CSV Data Set Config View Results Tree Simple Data Writer View Results in a Table Summary
Performance Testing Costs Test Environment System Under Test Load Generators Scripting and Testing Resources Load Testing Tools P7-3 Test Environment Test environment does not need to be production size Industry benchmarks Single full size server of each type Test against production servers prior to delivery Test against virtualised test environments Resource controls to guarantee CPU/Memory Use virtualised servers as load injectors If collecting response times at least one physical load injector is required P7-4
Scripting and Testing Resources Ease of scripting Access to support and online help Availability of skilled testers Time to train testers P7-5 Automated Test Tools Automated test tools are required to conduct performance testing, including: Stress Testing Load Testing Volume Testing Soak Testing However, commercial automated test tools can be expensive This remainder of this presentation will discuss how Apache JMeter may be used to conduct performance testing and avoid costs associated with Automated Testing Tools
Installation JMeter is a free load testing tool from Apache that runs on Java Platform Standard Edition Download from http://jakarta.apache.org/site/downloads/downloads_jmeter.cgi Management of test data, scripts and test results can be difficult P7-7 Test Plan Hierarchy Test Plan HTTP Cookie Manager HTTP Request Defaults Thread Group HTTP Request Regular Expression Extractor Response Assertion Assertion Results Simple Data Writer View Results Tree Workbench P7-8
Thread Groups Each Thread Group should represent one use case or saga JMeter runs Thread Groups in parallel but runs the contents of each Thread Group sequentially Each Thread Group can be controlled separately by Number of Threads Ramp up period (time period to introduce all threads) Loop count Scheduler 10 threads with ramp up period of 60 seconds means introduce 1 thread every 6 seconds 100 threads with ramp up period of 1 second does not take 100 seconds to ramp up P7-9 Thread Groups P7-10
Test Ramp Up Ramp up refers to increasing the number of threads during a test Introducing all the threads at the same time is unrealistic and could cause the service to fail or suffer poor performance We can determine best-case performance on a lightly loaded system Allow some time for the system to achieve a steady-state Allow measurement of multiple points on the response time curve Additional control could be achieved through multiple identical Thread Groups with different start and end times P7-11 Thread Groups - Scheduler Startup delay overrides Start Time Duration overrides End Time P7-12
HTTP Request Defaults Use HTTP Request Defaults to specify a default URL for HTTP Requests P7-13 Recording a Browser Session Add a Thread Group to the Test Plan Add a Recording Controller to the Thread Group Add a HTTP Proxy Server to the WorkBench Edit your LAN Connection to use a proxy on localhost:8080 Start the HTTP Proxy Server Open a browser and navigate through the use case Browser actions are recorded in the Recording Controller Stop the HTTP Proxy Server Delete the HTTP Proxy Server Save and then edit the generated script P7-14
Internet Explorer and Chrome LAN Settings P7-15 Firefox Connection Settings Settings P7-16
Recording a Browser Session P7-17 Recording a Browser Session It is possible to use URL Patterns to filter out images, CSS, etc. using URL Match Strings and URL Patterns to include or exclude certain content It is typically safer to record all requests and responses and then manually delete unwanted calls from the script afterwards P7-18
Remove Unwanted HTTP Requests Typically unwanted.js files.css files.gif images.jpg/.jpeg images Typically wanted.asp files.php files.htm files.html files P7-19 Remove Unwanted HTTP Requests P7-20
HTTP Header Manager Automatically added during the recording process Should not need editing P7-21 Demonstration Record the following use case into capacitas.jmx 1. Navigate to http://www.capacitas.co.uk 2. Enter virtualisation into the search box and click search 3. Click on the first item that is returned P7-22
http://www.capacitas.co.uk/results.php P7-23 Demonstration Delete unwanted.css,.js,.gif,.jpg,.jpeg etc. HTTP Requests Move important HTTP Requests (.asp) under Thread Group Rename Thread Group to capacitas.co.uk Search P7-24
Demonstration P7-25 Script Parameterisation Many web sites manage the relationship between client and web server using session data Need to record the session data to send back to the web server Important to check that the expected response is returned May also wish to request different information in the scripts P7-26
P7-27 Regular Expression Extractor Use regular expressions to reference any data (.+) Any brackets in the string ( or ) must be preceded by a \ P7-28
Jakarta Regular Expressions JMeter uses is the Jakarta regular expression package For example, searching AaaaAaaaA for A(.+)A matches aaaaaaa rather than aaa The solution is to say A([^A]+)A, which will match any number of NOT A http://jakarta.apache.org/regexp/applet.html is an applet that lets you test Jakarta regular expressions P7-29 Response Assertions Response Assertions are used to check whether the response contains the expected result Pattern matching can be used to ensure that specific text either is, or is not displayed This is required to ensure the expected web page was returned when making a request Be wary when using Response Assertions to check that error messages are not returned, as they may be returned to a browser but not rendered on the screen P7-30
Response Assertions P7-31 Assertion Results Allows you to check visually if the Response Assertions passed or failed If the Response Assertions passed it will just write a line with the name of the transaction It is possible to only write failures and ignore successes P7-32
Assertion Results P7-33 HTTP Cookie Manager Nearly all web testing should use cookie support Add an HTTP Cookie Manager to each Thread Group This will ensure that each thread gets its own cookies, shared across all HTTP Requests P7-34
HTTP Cookie Manager P7-35 Fully qualify the file location Specify a.csv extension CSV Data Set Config P7-36
searchterm in searches.csv CSV Data Set Config P7-37
View Results Tree View Results Tree allows the user to see the response from the service during the tests Typically easiest to look at the Render HTML view under the Response Data tab P7-39 View Results Tree: Response Data P7-40
Simple Data Writer Used to save the results of the test Fully qualify the file location and specify a.csv extension D:\JMeter Tests\Capacitas Website Testing\Results\CAPACITAS_03.csv P7-41 Saving Results To ensure results are written in.csv format rather than XML uncheck all of the XML options P7-42
Saving Results To write in a date format convenient for Excel uncomment the following line in jmeter.properties #JMeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSSS in JMeter.properties in jmeter.properties P7-43 View Results in a Table Response times for HTTP Requests are collected by default P7-44
Summary Still need a test environment System under test Load injectors Still require skilled resources for scripting and testing Test management is difficult Jmeter is free Scripting language is simple Skills are in the marketplace Thank You paulseatonsmith@capacitas.co.uk P7-46