Book Image

Apache JMeter

By : Emily H. Halili
Book Image

Apache JMeter

By: Emily H. Halili

Overview of this book

<p>A bad response time on a website can drive away visitors and prospective customers. To measure what a website can handle, there should be a way to simulate and analyze different load scenarios&acirc;&euro;&rdquo;this is where a load-testing tool like JMeter comes in. JMeter is a powerful desktop performance tool from the Apache Jakarta project, written in Java, for load-testing web pages, web applications, and other static and dynamic resources including databases, files, Servlets, Perl scripts, Java Objects, FTP Servers, and more.<br /><br />JMeter works by acting as the "client side" of an application, and measures response time. As such, it's one half of the testing arsenal; the other half consists of a tool to watch metrics on the server side, such as thread counts, CPU loads, resource usage, and memory usage. Although it can't behave like a browser to measure rich client-side logic such as JavaScripts or Applets, JMeter certainly measures the performance of the target server from the client's point of view. JMeter is able to capture test results that help you make informed decisions and benchmark your application.<br /><br />This book introduces you to JMeter (version 2.3) and test automation, providing a step-by-step guide to testing with JMeter. You will learn how to measure the performance of a website using JMeter.<br /><br />While it discusses test automation generally, the bulk of this book gives specific, vivid, and easy-to-understand walkthroughs of JMeter's testing tools showing what they can do, and when and how to use them.</p>
Table of Contents (16 chapters)

Appendix A. Component Description

Following is a table briefly explaining the components mentioned in this book. The description is adapted from the JMeter online manual. For more detailed information about these components, visit http://jakarta.apache.org/jmeter/usermanual.

Samplers

FTP Request

Lets you send an FTP "retrieve file" or "upload file" request to an FTP server. When downloading a file, it can be stored on disk (Local File) or in the Response Data, or both.

HTTP Request

Lets you send an HTTP/HTTPS request to a web server. It also lets you control whether or not JMeter parses HTML files for images and other embedded resources and sends HTTP/HTTPS requests to retrieve them.

JDBC Request

Lets you send an SQL query to a database.

Java Request

Lets you control a Java class that implements the JavaSamplerClient interface. By writing your own implementation of this interface, you can use JMeter to harness multiple threads, input parameter control, and data collection.

SOAP/XML-RPC Request

Lets you send a SOAP request to a Web Service. It can also be used to send XML-RPC over HTTP.

WebService (SOAP) Request

Uses Apache SOAP driver to serialize the message and set the header with the correct SOAP action.

LDAP Request

Lets you send one of four LDAP requests (Add, Modify, Delete, and Search) to an LDAP server.

LDAP Extended Request

Can send all 8 different LDAP requests to an LDAP server. It is an extended version of the LDAP sampler, therefore it is harder to configure, but can be used to make a test much more closely resembling a real LDAP session.

Access Log Sampler

Designed to read access logs and generate HTTP requests.

BeanShell Sampler

Allows the user to write a Sampler using the BeanShell scripting language.

BSF Sampler

Allows you to write a sampler using a BSF scripting language. See the Apache Bean Scripting Framework website for details of the languages supported.

TCP Sampler

Opens a TCP/IP connection to the specified server. It then sends the text, and waits for a response.

JMS Publisher

Publishes messages to a given pub/sub topic. For those not familiar with JMS, it is the J2EE specification for messaging.

JMS Subscriber

Subscribes to messages in a given pub/sub topic. For those not familiar with JMS, it is the J2EE specification for messaging.

JMS Point-to-Point

This sampler sends and optionally receives JMS Messages through point-to-point connections (queues). This is different from pub/sub messages and is generally used for handling transactions.

JUnit Request

The current implementation supports standard JUnit convention and extensions. It also includes extensions like oneTimeSetUp and oneTimeTearDown.

Mail Reader Sampler

Not yet implemented. TBA.

Test Action

This sampler is intended for use in a conditional controller. Rather than generate a sample, the test element either pauses or stops the selected target.

Logic Controllers

Simple Controller

Lets you organize your Samplers and other Logic Controllers. This controller provides no functionality beyond that of a storage device.

Loop Controller

Lets JMeter to loop through its child controllers a certain number of times, in addition to the loop value you specified for the Thread Group.

Once Only Controller

It tells JMeter to process the controller(s) inside it only once, and pass over any requests under it during further iterations through the Test Plan.

Interleave Controller

Lets JMeter to alternate among the controllers for each loop iteration.

Random Controller

Acts similarly to the Interleave Controller, except that instead of going in order through its sub-controllers and samplers, it picks one randomly at each pass.

Random Order Controller

Much like a Simple Controller, it will execute each child element at most once, but the order of execution of the nodes will be random.

Throughput Controller

Allows the user to control how often it is executed.

Runtime Controller

Controls the time for which its children are allowed to run.

If Controller

Allows the user to control whether the test elements below it (its children) are run or not.

While Controller

Runs its children until the condition is "false".

Switch Controller

Acts like the Interleave Controller in that it runs one of the subordinate elements on each iteration but rather than run them in sequence, the controller runs the element number defined by the switch value. If the switch value is out of range, it will run the zeroth element, which therefore acts as default.

ForEach Controller

This controller loops through the values of a set of related variables. When you add samplers (or controllers) to a ForEach Controller, every sample Sampler (or controller) is executed one or more times, where during every loop the variable has a new value.

Module Controller

Provides a mechanism for substituting Test Plan fragments into the current Test Plan at run time.

Include Controller

Designed to use an external .jmx file. To use it, add samples to a Simple Controller, then save the Simple Controller as a .jmx file. The file can then be used in a Test Plan. However, this element does not support variables/functions in the filename field, but can be overridden if the property includecontroller.prefix is defined where the contents are used to prefix the pathname.

Transaction Controller

Used to group Samplers by generating an additional sample, which totals the nested samplers.

Recording Controller

Simply a place-holder indicating where the proxy server should record samples to. It has no effect during a test run. But during recording using the HTTP Proxy Server, all recorded samples will by default be saved under the Recording Controller.

Listeners

Sample Result Save Configuration

Listeners can be configured to save different items to the result log files (JTL) by using the Config popup as shown below. The defaults are defined as described in the Listener Default Configuration documentation. Items with (CSV) only apply to the CSV format; items with (XML) only apply to XML format. CSV format cannot be used to save any items that include line-breaks.

Graph Full Results

Not implemented yet. TBA.

Graph Results

Generates a simple graph that plots all sample times. Along the bottom of the graph, the current sample (black), the current average of all samples (blue), the current standard deviation (red), and the current throughput rate (green) are displayed in milliseconds.

Spline Visualizer

Provides a view of all sample times from the start of the test till the end, regardless of how many samples have been taken.

Assertion Results

This visualizer shows the Label of each sample taken. It also reports failures of any Assertions that are part of the Test Plan.

View Results Tree

This shows a tree of all sample responses, allowing you to view the response for any sample. In addition to showing the response, you can see the time it took to get this response, and some response codes. There are several ways to view the response, selectable by a radio button.

Aggregate Report

The aggregate report creates a table row for each differently named request in your test. For each request, it totals the response information and provides request count, Min, Max, Average, Error %, Throughput (request/second), and KB/second throughput.

View Results in Table

This visualizer creates a row for every sample result. Like the View Results Tree, it uses a lot of memory.

Simple Data Writer

This listener can record results to a file but not to the UI. It is meant to provide an efficient means of recording data by eliminating GUI overhead.

Monitor Results

Visualizer for displaying server status. It is designed for Tomcat 5, but any servlet container can port the status servlet and use this monitor.

Distribution Graph

This will display a bar for every unique response time.

Aggregate Graph

Similar to the Aggregate Report, the difference is the aggregate graph provides an easy way to generate bar graphs and save the graph as a PNG file.

Mailer Visualizer

The mailer visualizer can be set up to send email if a test run receives too many failed responses from the server.

BeanShell Listener

The BeanShell Listener allows the use of BeanShell for processing samples for saving, etc. The BeanShell jar file is not included with JMeter; it needs to be separately downloaded. Please see the BeanShell website at http://www.beanshell.org.

Summary Report

This report creates a table row for each differently named request in your test. This is similar to the Aggregate Report, except that it uses less memory.

Configuration Elements

CSV Data Set Config

Used to read lines from a file, and split them into variables. Easier to use than the __CSVRead() and _StringFromFile() functions, the file is only opened once, and each thread will use a different line from the file. Lines are read as the threads need them.

FTP Request Defaults

No documentation found.

HTTP Authorization Manager

Lets you specify one or more user logins for web pages that are restricted using server authentication.

HTTP Cookie Manager

This stores and sends cookies just like a web browser. If you are testing a website that uses a cookie for storing session information, each JMeter thread will have its own session. You can manually add a cookie to the Cookie Manager. However, if you do this, the cookie will be shared by all JMeter threads.

HTTP Request Defaults

Lets you set default values that your HTTP Request controllers use.

HTTP Header Manager

Lets you add or override HTTP request headers.

Java Request Defaults

Lets you set default values for Java testing. See the Java Request.

JDBC Connection Configuration

Creates a database connection pool (used by JDBC Request Sampler) with JDBC Connection settings.

Login Config Element

Lets you add or override username and password settings in samplers that use username and password as part of their setup.

LDAP Request Defaults

Lets you set default values for LDAP testing. See the LDAP Request.

LDAP Extended Request Defaults

Lets you set default values for extended LDAP testing.

TCP Sampler Config

Provides default data for the TCP Sampler.

User Defined Variables

Lets you define variables for use in other test elements, just as in the Test Plan. The variables in User Defined Variables components will take precedence over those defined closer to the tree root—including those defined in the Test Plan.

Simple Config Element

Lets you add or override arbitrary values in Samplers. You can choose the name of the value and the value itself.

Assertions

Response Assertion

Lets you add pattern strings to be compared against various fields of the response. The pattern strings are Perl5-style Regular Expressions.

Duration Assertion

This tests that each response was received within a given amount of time. Any response that takes longer than the given number is marked as a failed response.

Size Assertion

This tests that each response contains the right number of bytes in it. You can specify that the size be equal to, greater than, less than, or not equal to a given number of bytes.

XML Assertion

This tests that the response data consists of a formally correct XML document. It does not validate the XML based on a DTD or schema or do any further validation.

BeanShell Assertion

Allows the user to perform assertion checking using a BeanShell script.

MD5Hex Assertion

Allows the user to check the MD5 hash of the response data.

HTML Assertion

Allows the user to check the HTML syntax of the response data using JTidy.

XPath Assertion

The XPath Assertion tests a document for well formedness and has the option of validating against a DTD, or putting the document through JTidy and testing for an XPath.

XML Schema Assertion

The XML Schema Assertion allows the user to validate a response against an XML Schema.

Timers

Constant Timer

Allows each thread to pause for the same amount of time between requests.

Gaussian Random Timer

Pauses each thread request for a random amount of time, with most of the time intervals occurring 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

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.

Constant Throughput Timer

Allows for variable pauses, calculated to keep the total throughput (in terms of samples per minute) as close as possible to a give figure.

Synchronizing Timer

Blocks threads until X number of threads have been blocked, and then releases them all at once. It can thus create large instant loads at various points of the Test Plan.

BeanShell Timer

The BeanShell Timer can be used to generate a delay.

Pre-Processors

HTML Link Parser

Parses HTML response from the server and extracts links and forms.

HTTP URL Re-writing Modifier

This modifier works similarly to the HTML Link Parser, but is especially useful for web applications that use URL Re-writing to store session IDs instead of cookies.

HTML Parameter Mask

This element is deprecated. Use Counter instead of this parameter. The HTML Parameter Mask is used to generate unique values for HTML arguments.

HTTP User Parameter Modifier

This element is deprecated. Use User Parameters instead of this parameter. The User Parameter Modifier uses an XML file get values for HTTP arguments. Any HTTP Request that this modifier modifies will be checked for the existence of the specified arguments.

User Parameters

Allows the user to specify values for User Variables specific to individual threads, which can be accessed in any test component in the same thread group, using the function syntax: ${variable}.

Counter

Allows the user to create a counter that can be referenced anywhere in the Thread Group. The counter now uses long to store the value, so the range is from -2^63 to 2^63-1.

BeanShell PreProcessor

Allows arbitrary code to be applied before taking a sample.

Post-Processors

Regular Expression Extractor

Allows the user to extract values from a server response using a Perl-type regular expression. This element will execute after each Sample request in its scope, apply the regular expression extracting the requested values, generate the template string, and store the result into the given variable.

XPath Extractor

Allows the user to extract values from a structured response—XML or (X)HTML—using XPath query language.

Result Status Action Handler

Allows the user to stop the thread or the whole test if the relevant sampler failed.

Save Responses to a file

For each sample in its scope, it will create a file of the response Data. The primary use for this is in creating functional tests.

Generate Summary Results

Generates a summary of the test run so far to the log file and/or standard output. Both running and differential totals are shown.

BeanShell PostProcessor

Allows arbitrary code to be applied after taking a sample.

Miscellaneous Features

Test Plan

The Test Plan is where the overall settings for a test are specified.

Thread Group

A Thread Group defines a pool of users that will execute a particular test case against your server. You can control the number of users simulated (num of threads), the ramp up time (how long it takes to start all the threads), the number of times to perform the test, and optionally, a start and stop time for the test.

WorkBench

The WorkBench simply provides a place to temporarily store test elements while not in use, for copy/paste purposes, or any other purpose you desire.

SSL Manager

The SSL Manager is a way to select a client certificate so that you can test applications that use Public Key Infrastructure (PKI). It is only needed if you have not set up the appropriate System properties.

HTTP Proxy Server

The Proxy Server can only record HTTP traffic. It is not possible to record HTTPS (SSL) sessions; however, there is an HTTPS spoofing mode to override this.

HTTP Mirror Server

This simply mirrors the data sent to it. This is useful for checking the content of HTTP Requests.

Property Display

Shows the values of System or JMeter properties. Values can be changed by entering new text in the Value column. It is available only on the WorkBench.

Debug Sampler

Generates a sample containing the values of all JMeter variables and/or properties. The values can be seen in the View Results Tree Listener Response Data pane.

Debug PostProcessor

Creates a subsample with the details of the previous sampler properties. This is intended for developer use only.

Functions and Variables

regexFunction

Parse previous response using a Regular Expression

counter

Generate an incrementing number

threadNum

Get thread number

intSum

Add numbers

StringFromFile

Read a line from a file

machineName

Get the local machine name

javaScript

Process JavaScript (Mozilla Rhino)

Random

Generate a random number

CSVRead

Read from a CSV delimited file

property

Read a property

P

Read a property (shorthand method)

setProperty

Set a JMeter property

log

Log (or display) a message (and return the value)

logn

Log (or display) a message (empty return value)

BeanShell

Run a BeanShell script

split

Split a string into variables

XPath

Use an XPath expression to read from a file

time

Return current time in various formats

jexl

Evaluate a Commons JEXL expression

V

Evaluate a variable name

eval

Evaluate a variable expression

evalVar

Evaluate an expression stored in a variable