Performance Testing With JMeter PDF
Performance Testing With JMeter PDF
OBJECTIVE EXAMPLE
Performance Will 2,000 concurrent hits
test Stability crash the server?
Is response time
Performance acceptable according to
specifications?
Do business processes
Functionality function properly under
under load heavy load?
Load Testing
This subcategory of performance testing is focused on
determining or validating performance characteristics of the
system or application under test when subjected to workloads
and load volumes anticipated during production operations.
This is done within the expected WorkLoad
Stress Testing
Stress testing is focused on determining an application’s
robustness, availability, and reliability under extreme conditions
like heavy loads, high concurrency and limited computational
resources.
These tests are designed to determine under what conditions an
application will fail, how it will fail, and what indicators can be
monitored to warn of an impending failure.
Capacity Testing
To determine how many users and/or transactions a given system
will support and still meet performance goals.
Capacity testing is conducted in conjunction with capacity
planning, which you use to plan for future growth, such as an
increased user base or increased volume of data. For example, to
accommodate future loads, you need to know how many
additional resources (such as processor capacity, memory usage,
disk capacity, or network bandwidth) are necessary to support
future usage levels.
Capacity testing helps you to identify a scaling strategy in order to
determine whether you should scale up or scale out.
Speed
User Expectations
– Experience
– Psychology
– Usage
System Constraints
– Hardware
– Network
– Software
Costs
– Speed can be expensive!
Scalability
How many users…
– before it gets “slow”?
– before it stops working?
– will it sustain?
– do I expect today?
– do I expect before the next upgrade?
16
Activity 1. Identify the Test Environment.
17
Activity 2. Identify Performance Acceptance Criteria.
18
Activity 3. Plan and Design Tests.
19
Activity 4. Configure the Test Environment.
20
Activity 5. Implement the Test Design.
21
Activity 6. Execute the Test.
Run and monitor your tests. Validate the tests, test data,
and results collection. Execute validated tests for analysis
while monitoring the test and the test environment.
22
Activity 7. Analyze Results, Report, and Retest.
23
Additional Concepts / Terms
Endurance test
An endurance test is a type of performance test
focused on determining or validating performance
characteristics of the product under test when
subjected to workload models and load volumes
anticipated during production operations over an
extended period of time. Endurance testing is a subset
of load testing.
Latency
Latency is time to complete the execution of a request.
Latency may also represent the sum of several
latencies or subtasks.
Performance thresholds
Maximum acceptable values for the metrics identified for
your project, in terms of
response time,
throughput (transactions per second),
resource-utilization levels.
Resource-utilization levels include
processor capacity,
memory,
disk I/O,
network I/O
Scenarios
In the context of performance testing, a scenario is a
sequence of steps in your application. A scenario can
represent a use case or a business function such as
searching a product catalog, adding an item to a
shopping cart, or placing an order.
Smoke test
A smoke test is the initial run of a performance test to
see if your application can perform its operations
under a normal load.
Spike test
Spike testing is done by suddenly increasing
the load generated by a very large number of users,
and observing the behavior of the system.
Spike testing is a subset of stress testing.
Baselines
Creating baseline is the process of running a set of tests to
capture performance metric data.
Its purpose is to evaluate the effectiveness of performance-
improving changes to the system or application
With respect to Web applications, you can use a baseline to
determine whether performance is improving or declining
and to find deviations across different builds and versions.
Also within the same build and version we can create
baselines with single user and find deviations with multiple
users.
Benchmarking
Benchmarking is the process of comparing your
system’s performance against a baseline that you have
created internally or against an industry standard
endorsed by some other organization.
You need to play by the rules.
Because you play by the rules, you can be transparent
In the case of a Web application, you would run a set of
tests to compare against industry benchmark
Throughput
Transactions per second your application can handle. It is
actually the amount of capacity that a website or application can
handle.
When presenting performance test results, throughput
performance is often expressed as transactions per second,
or TPS.
Response Time
Load
App DB Server
Injector
Server
34
Think Time
Think time is the time taken by the users to think or to navigate
to different pages in the application.
Think times are used to simulate human behavior that causes people to wait between
interactions with a Web site.
Think time is the time taken for selecting a new Transaction after the response for the
previous Transaction has been received
Transaction 1
Transaction 2
35
Transaction Mix
Account Opening Credit
Loans
36
Bottleneck
A bottleneck is a slowdown, not a stoppage. A stoppage is a
failure
Identifying bottlenecks is an incremental process whereby
alleviating one bottleneck can lead to the discovery of the next
one.
Some bottlenecks can be addressed by upgrading hardware.
Hardware can be upgraded either by scaling-up (more CPU’s,
memory or cache) or by scaling-out (additional servers).
General Bottlenecks in DB Application
Bottlenecks in DB servers
Inferior Hardware
Low Network Bandwidth
Large volume of data
Too much use of Join functions
Memory Leaks
General Bottlenecks in Web Application
Bottlenecks in Application Server
Inferior Hardware
Low Network Bandwidth
Inappropriate choice of data structure & algorithms
Memory Leaks
Manual Testing Is Problematic
Do you have the testing resources?
• Testing personnel
All of you,
click the • Client machines
GO button How do you synchronize users?
again
How do you collect and analyze results?
How do you achieve test repeatability?
Coordinator
Testers
Operating Systems:
JMeter has been tested and works under:
Unix (Solaris, Linux, etc)
Windows (98, NT, XP, etc)
OpenVMS Alpha 7.3+
Installation
Download the latest production release from
http://jakarta.apache.org/site/downloads/downloads_
jmeter.cgi
To install a release build, simply unzip the zip/tar file
into the directory where you want JMeter to be
installed.
It is recommended that most users should run the
latest release.
Do not rename the sub-folders. You can rename the
parent folder name
Running JMeter
To run JMeter, run the jmeter.bat (for Windows) or jmeter (for Unix) file present
in the bin directory. After a short pause, the JMeter GUI should appear.
Running Jmeter in Command Line
To run JMeter in Non-GUI Mode, Use the following command options
-n This specifies JMeter is to run in non-gui mode
-t [name of JMX file that contains the Test Plan].
-l [name of JTL file to log sample results to].
-j [name of JMeter run log file].
Example : jmeter -n -t my_test.jmx -l log.jtl -H my.proxy.server -P 8000
50
JMeter's Classpath
JMeter automatically finds classes from jars in the
following directories:
JMETER_HOME/lib - used for utility jars
JMETER_HOME/lib/ext - used for JMeter components
and add-ons
Testing Process
Analyze
Run Test Plan
Results
Building a Test Plan
A test plan describes a series of steps JMeter will execute when run.
• Test plans consist of:
1. Thread groups: organize threads of execution
2. Samplers: sends requests to a server
3. Logical controllers : control flow of test plan (loops, conditionals,
ordering, etc.)
4. Listeners: record, summarize and display response data
5. Timers: introduce delays in test plan
6. Assertions: assert facts about responses.
7. Configuration Elements: used to modify requests
8. Pre-Processor Elements: executes some action prior to a Sampler
Request being made
9. Post-Processor Elements: A Post-Processor executes some action after a
Sampler Request has been made
Elements of a Test Plan
Thread Group
Configuration
Elements
Timers
Pre-Processors
Assertions
Post-Processors
Samplers
Listeners
Getting Familiar with the New Tours Application
55
Defining the Application Performance Requirements
Now that you are familiar with Mercury Tours, imagine that you are the
performance engineer responsible for signing off that Mercury Tours
meets the needs of your business. Your project manager has given you 4
criteria for release:
56
Demonstration of Record and Play
and Creation of Web Test Plan
What is a Test Plan?
• A test plan describes a series of steps JMeter will execute when run.
• A complete test plan will consist of one or more Thread Groups, logic controllers, sample
generating controllers, listeners, timers, assertions, and configuration elements.
Thread Group
• Thread group elements are the beginning points of any test plan.
• All controllers and samplers must be under a thread group. Other elements, e.g. Listeners, may be placed
directly under the test plan, in which case they will apply to all the thread groups. .
• In the Thread Group, No of Threads is the Number of users to simulate.
• Ramp-up Period: How long JMeter should take to get all the threads started. If there are 10 threads and a
ramp-up time of 100 seconds, then each thread will begin 10 seconds after the previous thread started, for a
total time of 100 seconds to get the test fully up to speed. Ramp-up needs to be long enough to avoid too large
a work-load at the start of a test, and short enough that the last threads start running before the first ones finish
Start with Ramp-up = number of threads and adjust up or down as needed.
• Loop Count: Number of times to perform the test case. Alternatively, "forever" can be selected causing the
test to run until manually stopped.
• Delay Thread creation until needed: If selected, threads are created only when the appropriate proportion of
the ramp-up time has elapsed. This is most appropriate for tests with a ramp-up time that is significantly longer
than the time to execute a single thread. I.e. where earlier threads finish before later ones start.
• Scheduler: If selected, enables the scheduler
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.
• FTP Request
• HTTP Request
• JDBC Request
• Java object request
• LDAP Request
• SOAP/XML-RPC Request
• WebService (SOAP) Request
Logical Controllers
Logical Controllers let you customize the logic that JMeter uses to decide when to send requests.
• Simple Controller
• Loop Controller
• Once Only Controller
• Interleave Controller
• Random Controller
• Random Order Controller
• Throughput Controller
Logic Controllers determine the order in
which Samplers are processed
• Runtime Controller
• If Controller
• While Controller
• Switch Controller
• ForEach Controller
• Module Controller
• Include Controller
• Transaction Controller
• Recording Controller
Simple Controller
• It organizes your Samplers and other Logic Controllers.
• No functionality
Loop Controller
• If the Loop count is 2 in Loop Controller and the Loop count in Thread Group Loop is 5, then JMeter sends
10 HTTP requests
Once Only Controller
• It tells JMeter to process the controller(s) inside it only once.
• It execute always during the first iteration of any looping parent controller.
Interleave Controller
• It will alternate among each of the other controllers for each loop iteration.
• If this is selected, then the condition must be an expression that evaluates to "true"
For example, ${JMeterThread.last_sample_ok}
• Should condition be evaluated for all children? If not checked, then the condition is only evaluated on
entry.
The While Controller runs its children Switch Controller runs the element
until the condition is "false". defined by the switch value.
• It’s a place holder indicating where the proxy server should record samples to.
• All recorded samples will by default be saved under the Recording Controller.
Transaction Controller
• measures the overall time taken to perform the nested test elements
Logic Controllers
• Allows customization the logic that JMeter uses to decide when to send requests.
• Logic Controllers can change the order of requests coming from their child elements.
Timers
• By default, a JMeter thread sends requests without pausing between each request.
• It is recommended that you specify a delay by adding one of the available timers to your Thread Group.
• If not, JMeter could overwhelm your server by making too many requests in a very short amount of time.
• If you choose to add more than one timer to a Thread Group, JMeter takes the sum of the timers and pauses
for that amount of time before executing the samplers to which the timers apply.
• The timer will cause JMeter to delay a certain amount of time before each sampler which is in its scope.
• To provide a pause at a single place in a test plan, one can use the Test Action Sampler. This is similar to
pacing used in Loadrunner
• Timers are processed before each sampler in the scope in which they are found; if there are several timers in
the same scope, all the timers will be processed before each sampler
Constant Timer
• If you want to have each thread pause for the same amount of time between requests, use this timer.
Gaussian Random Timer
• This timer pauses each thread request for a random amount of time, with most of the time intervals ocurring
near a particular value.
• The total delay is the sum of the Gaussian distributed value (with mean 0.0 and standard deviation 1.0) times
the deviation value you specify, and the offset value.
Uniform Random Timer
• This timer pauses each thread request for a random amount of time, with each time interval having the same
probability of occurring. The total delay is the sum of the random value and the offset value.
Synchronizing Timer
• The purpose of the SyncTimer is to block threads until X number of threads have been blocked, and then they
are all released at once. A SyncTimer can thus create large instant loads at various points of the test plan.
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
• To view the assertion results, add an Assertion Listener to the Thread Group
It is like Checkpoints in
QTP/LoadRunner
Assertions Types
• Assertions are used to perform additional checks on samplers, and are processed after every sampler in the
same scope. To ensure that an Assertion is applied only to a particular sampler, add it as a child of the
sampler.
• Response Assertion
• Duration Assertion
• Size Assertion
• XML Assertion
• Bean Shell Assertion
• MD5Hex Assertion
• HTML Assertion
• XPath Assertion
• XML Schema Assertion
• BSF Assertion
• JSR223 Assertion
• Compare Assertion
• SMIME Assertion
Response Assertion
• The response assertion control panel lets you add pattern strings to be compared against various fields of the
response.
Duration Assertion
• The Duration Assertion tests that each response was received within a given amount of time.
• Any response that takes longer than the given number of milliseconds (specified by the user) is marked as a
failed response.
Size Assertion
• The Size Assertion tests that each response contains the right number of bytes in it.
Listeners
• Listeners provide access to the information JMeter gathers about the test cases while JMeter runs.
• It can direct the data to a file for later use.
• Configuration button which can be used to choose which fields to save, and whether to use CSV or XML
format.
• Listeners can be added anywhere in the test, including directly under the test plan.
Listeners Types
• A listener is a component that shows the results of the samples. The results can be shown in a tree, tables,
graphs or simply written to a log file.
• Listeners can use a lot of memory if there are a lot of samples
• A configuration element is accessible from only inside the tree branch where you place the element
• The Cookie Manager is accessible to the HTTP requests "Web Page 1" and "Web Page 2",but not "Web Page
3".
Pre-Processor Elements
• A Pre-Processor executes some action prior to a Sampler Request being made.
• If a Pre-Processor is attached to a Sampler element, then it will execute just prior to that sampler element
running.
• A Pre-Processor is most often used to modify the settings of a Sample Request just before it runs, or to update
variables that aren't extracted from response text.
Post-Processor Elements
• A Post-Processor executes some action after a Sampler Request has been made.
• If a Post-Processor is attached to a Sampler element, then it will execute just after that sampler element runs.
• A Post-Processor is most often used to process the response data, often to extract values from it. See the
scoping rules for more details on when Post-Processors are executed.
Execution order
1. Configuration elements
2. Pre-Processors
3. Timers
4. Sampler
5. Post-Processors (unless SampleResult is null)
6. Assertions (unless SampleResult is null)
7. Listeners (unless SampleResult is null)
• Timers, Assertions, Pre- and Post-Processors are only processed if there is a sampler to which they apply.
• Logic Controllers and Samplers are processed in the order in which they appear in the tree.
• Other test elements are processed according to the scope in which they are found, and the type of test
element
Scoping Rules
• The JMeter test tree contains elements that are both hierarchical and ordered.
• Some elements in the test trees are strictly hierarchical (Listeners, Config Elements, Post-Procesors, Pre-
Processors, Assertions, Timers), and some are primarily ordered (controllers, samplers).
• Values can be accessed in any test component in the same thread group, using the function syntax :
${variable}.
Post-Processors Types
• As the name suggests, Post-Processors are applied after samplers.
• Note that they are applied to all the samplers in the same scope, so to ensure that a post-processor is applied
only to a particular sampler, add it as a child of the sampler.
Regular Expression Extractor
• Allows the user to extract values from a server response using a Perl-type regular expression.
• As a post-processor, this element will execute after each Sample request in its scope, applying the regular
expression, extracting the requested values, generate the template string, and store the result into the given
variable name.
Regular Expressions
• JMeter includes the pattern matching software Apache Jakarta ORO
• Suppose you want to match the following portion of a web-page:
• name="file" value="readme.txt">
and you want to extract readme.txt .
• A suitable regular expression would be:
• name="file" value="(.+?)">
• The special characters above are:
• ( and ) - these enclose the portion of the match string to be returned
• . - match any character
• + - one or more times
• ? - don't be greedy, i.e. stop when first match succeeds
Regular Expressions
• Extract multiple strings
• Suppose you want to match the following portion of a web-page:
name="file.name" value="readme.txt" and you want to extract both file.name and readme.txt .
• A suitable reqular expression would be:
name="(.+?)" value="(.+?)"
This would create 2 groups, which could be used in the JMeter Regular Expression Extractor template
as $1$ and $2$.
• The JMeter Regex Extractor saves the values of the groups in additional variables.
For example, assume:
Reference Name: MYREF
Regex: name="(.+?)" value="(.+?)"
Template: $1$$2$
• Regular expressions use certain characters as meta characters - these characters have a special meaning to
the RE engine.
• Such characters must be escaped by preceding them with \ (backslash) in order to treat them as ordinary
characters.
Correlations
• Correlations is the process of capturing the dynamic values in the responses which changes at every run and
passing it to the request subsequently.
• To correlate in JMeter we need to add Regular Expression Extractor as a Post Processor.
• Consider any e-commerce or banking applications. Once you login or during checkout, secured session gets
created for safe transactions.
• In the URL you can observe long, random and dynamic session ids.
E.g. name=userSession jsessionid=gj22T5DXE4a0rAfJmt26Bw.1337343363927.1
• In this scenario, we going to store jsessionid into one variable using Regular Expression Extractor. Variable
name could be ${jsessionid}
Correlations - How to identify dynamic value
• Record your actions and design it appropriately.
• Add View Result Tree Listener
• Execute it once
• Definitely you will get few errors.
• Click on the samplers you are getting error during execution in View Result Tree.
• Then go to the respective sampler in the tree view an navigate to the respective Parameters and Post Body as
shown above.
• You will be able to check the dynamic value of osCsid.
• Now go back to Response Data in the tree view for the respective Sampler (which you’ve got error)
Correlations - How to identify dynamic value
• You could see the response the request you
had sent in text format, to view as HTML
select on HTML.
• Search for osCsid
• In notepad, capture unique and First
Occurrence of Left and Right Boundary
values.
• To Correlate, add Post Processor (Regular
Expression Extractor) on respective sampler.
Correlations
• Name Regular Expression Extractor as jsessionid.
• Enter Reference Name as jsessionid
• Enter Regular Expression as
osCsid="(.+?)" />
(.+?) this refers JMeter captures any values in between LB and RB)
• Enter Template as $1$ (this is for grouping)
• Enter Match No. as 1
• Default Value as blank. (To pass default value enter string here)
Correlations
• You have captured the dynamic value which changes frequently.
• Next step is to pass this dynamic value i.e. osCsid in next sampler request.
• Double click on osCsid value.
• Delete the junk value and enter ${<Regular Expression Extractor Name>} i.e. ${osCsid}
Demo & Exercise :
Create Script Using Regular
Expression Extractor
XPath Extractor
• This test element allows the user to extract value(s) from structured response - XML or (X)HTML - using
XPath query language.
Result Status Action Handler
• This test element allows the user to stop the thread or the whole test if the relevant sampler failed.
JMeter – Distributed Testing
• Consists of a Master system (the GUI) which
controls remote slave systems (running JMeter-
server)
• Master
the system running Jmeter GUI, which
controls the test
• Slave
the system running JMeter-server, which
takes commands from the GUI and send
requests to the target system(s)
• Target
the webserver we plan to test
• The JMeter GUI is a multi-threaded Java class
running Java Swing interfaces.
• It communicates with multiple remote injector
Java RMIRegistry service
• By default Remote servers listens to 1099 port.
• Things to check
• The JMeter should be installed in all the systems.
• 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 server doesn'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 may not work
correctly.
• Using different versions of Java may work - but is best avoided.
Remote & Distributed Testing
On master system acting as the console, open windows explorer and go to jmeter/bin
directory
11) Parameterizing should also be done for server names, No of users, loops / test duration etc so
that same script can be run in different environments.
12) Before recording Clear the cookies and cache of the browser.
13) Close JMeter window after the test is over and results have been saved. This would refresh the
jmeter.log when it is opened next time.
14) Use naming conventions always for all elements.
15) Check the Scoping Rules and design accordingly.
16) Be sure your load generator has enough hardware resources
17) Use HTTP Request Defaults to set the server name you are testing and leave this information
out of the requests. You can change one setting instead of modifying every request.
Exercise : Executing Performance
test run and Monitoring Servers
References
• Image courtesy from http://jmeter.apache.org
• Self learning and my experiences in various exercises.
• http://wiki.apache.org/jmeter/JMeterLinks
• http://jmeter-plugins.org/
Q&A
Thank You !
134