Apache J Meter


Download Full Article

JMeter Complete Reference.doc

Introduction

Apache JMeter is an open source java based application which can be used to load test static and dynamic pages. It’s more often called as a developer tool and not as a QA tool, since its used by developers to fine tune their code. Its readings are always debated. It’s used by developers and QA alike because of its ease of use. Like any load testing tool, it also works at the protocol level. JMeter supports the following protocols.
1. HTTP
2. JDBC
3. FTP

Installation

JMeter is an open source tool and can be freely downloaded from http://jakarta.apache.org/site/downloads/index.html.

1. Download the zip file.
2. Extract it to a folder of your choice.
3. For running the application, double-click on the jmeter.bat file.

GUI

JMeter GUI consist of two panes, on the left pane there is a tree structure which displays the contents of the test and the right pane will show the details of the selected contents. In JMeter, the test plan is the node under which you can add the test components and the work bench is where you can keep temporary components as you save.
Note: – The nodes added under workbench won’t get saved when you save the test.

Thread Groups
It’s in a thread group where you specify the number of users and set some master parameters from which you can control the test. Here you can specify the number of users, the number of times to perform the test or optionally start time or end time for the test.
By default the thread runs for ever, but you can set the number of times that the test needs to run by entering the number at the column.

It can also be said that the thread group is a placeholder for the scenario being tested.

For example a scenario where a user logs in and logs out can be listed under a Thread Group.

To add a thread group:
1. Select the Test Plan.
2. Right Click on the test plan and select Thread Group. This will add a thread group under test plan.
3. In the Tread Group you can specify the then number of threads; this will constitute the number of users being simulated. The ramp up period and the number iterations can also be specified.

The thread group can be customized to have many branching and logical statements which can make the scenario more dynamic and adaptable to the application.

Test Plans
A test plan can contain one or more thread groups. It is one of the default nodes in JMeter. All items added under the test plan node can be saved into a jmx file.

Samplers
A sampler is an encapsulation of parameters belonging to a request. JMeter sends requests to a server through a sampler, in sampler you can specify the details of the request depending on the type of request that you are initiating. Samplers can be added under a thread group. JMeter contains the following samplers.
• FTP Request
• HTTP Request
• JDBC Request
• Java object request
• LDAP Request
• SOAP/XML-RPC Request
Listeners
A listener captures the results received from the server. JMeter provides different listeners ranging from capturing individual results to consolidated results. The listener can be added at the test plan level, thread group level or even under individual requests. When added under the test plan level, results will be generated for all the requests consolidated.

Assertions
Assertions can be added to check the results of the results from a server. There are many assertions that come with JMeter which can be used for specific purposes like checking for the duration for the response to come in or the size of the response. Assertions are individual handlers and can be added under a sampler.
There is also a multipurpose assertion called a bean shell assertion where you can code in bean shell script to check the results from a server.

Logic Controller
A logic controller provides a mechanism through which the flow of the test can be controlled. JMeter allows programming statements such as If statement, For loops While controllers and so on. More on Logic controllers

Recording a Script

JMeter includes a HTTP proxy, which when enabled can be used to record the scripts. The idea is to point the browser to the JMeter Proxy so that JMeter can sniff on the requests made through the browser and store them under the specified controller in JMeter.

Setting up the browser
1. Open IE, Point to Tools>Options>Connections Tab.
2. Click on the LAN Settings Button.
3. Check to enable the Proxy Servers option.
4. Enter localhost in address and 8080 in the port field. This port can be a valid number under 216. Ideally give a number more than 1024, since most of them under are reserved for specific purposes.
5. Save the changes.

Setting up JMeter
1. Start JMeter, When JMeter opens, you can see two default nodes in the left pane. Test Plan and Workbench.
2. Name the test plan by clicking the Test Plan node.
3. Next, set up the WorkBench to capture our requests. Right-click WorkBench then click Add>Non-Test Elements>HTTP Proxy Server.
4. Add the Logic Controller>Recording Controller under Thread Group.
5. Add ConfigElement>HTTP Request Defaults under Thread Group and set the app server host name and port. Example, www.google.com and 80 in port.
6. Select the Proxy Server element in the Tree. Enter the proxy server as 8080. Click on the Start Button.
7. Enable the proxy option in the browser to reflect the host name of the system and the port as mentioned in the proxy server.
8. Whatever sites requested through the browser will get recorded in JMeter.

Note: Think times can also be recorded.

Proxy Servers

The proxy server contains many fields which need to be configured to successfully record a script.
Port: Specify the listening port used by the Proxy Server.
Target Controller: You can specify the controller to which the recorded requests are to be stored. This is by default the test plan itself, however you can select any alternative that is listed in the lot.
Grouping: Sometimes a request would end in multiple requests, if you want all the requests initiated by the first one to be in a single group, you can do so by selecting group samplers Put Each Group in a new Controller.
Patterns To Include/Exclude: Here you can specify the patterns of requests that you want to include or exclude.


The way to configure the proxy when internet is already accessed through a proxy server.

Simulating a Request

Requests to a server are initiated through a sampler. JMeter provides different samplers, like HTTP sampler, JDBC Sampler or a FTP Sampler. Here we will discuss only about HTTP Samplers.
HTTP Request Sampler

With the HTTP request sampler, you can give parameters of the HTTP Request. The major parameters are
Server Name: The IP address or the name of the server. This can be given with each http request or can also be given globally in HTTP Request Defaults. If any value is given in this server name field, the values given in HTTP Request Default will be overridden.
Port Number: The port number of the server. This can be skipped if its default port 80.
Protocol: Currently JMeter only supports HTTP, hence you can enter HTTP here.
Get/Post: It’s the kind of request posted to the server.
Path: Path of the resource at the server resides.

HTTP Request Defaults

If you have a series of HTTP Requests in the scenario and want to globally provide some values which are the same you can do so through HTTP Request Defaults. The values provided here will be taken for all HTTP Requests within the same level or a following level of the node. You can provide the following values in the HTTP Request defaults.

Protocol
Server Name
Path
Port Number

Adding Logic to your Scripts

JMeter also allows to use some programming statements in your performance scripts like, if, for while switch etc. The statements are again added as visual objects to the script. All controllers can be added under the thread group by right clicking for the popup menu and navigating to Add>Logic Controller> and then selecting the appropriate logic controller. All the samplers (e.g. http requests), added under the controller will be initiated according to the input to the logic controller.

If Controller
Whatever statements added under the if controller will

Parameter Description
Name You can provide a name for documentation purposes in this field.
Condition This can be a logical statement such as a>b or something, use the same can be used here.

For example, assume that we have a parameter called url and we are having different set of samplers based on the actual url provided, so we can the logical statement in the condition field as

‘${url}’==‘www.google.com’

Note:- There is no else statement for the controller, you will have to use another set of If controller for the else part.

Simple controller
Many requests can be grouped together under a simple controller. A simple controller doesn’t do any thing as such, but it can be considered analogous to curly braces in C.

Once Only Controller

All the items placed under the once only controller will be executed only once per thread, in spite of the loop count given in the thread group.

Recording Controller

A recording controller can be used as a place holder where you can place the scripts. While recording a script through a proxy, there is an option to select the Recording Controller; all the requests through the Proxy will be by default placed in the recording controller.

Timers

Any user interaction is embedded with typing or clicking delays, the delay can depend on the amount of user interaction required in any particular form. For example, a user can spend say 20 seconds in filling in a form with about 5 fields. In order to realistically simulate the user interactions, we can induce the delay between requests through timers. Think actual times can also be recorded.

JMeter provides different kinds of timers.
Constant TimerIt is something that induces the specified delay in milliseconds. i.e. if you provide 3000 as the delay, JMeter waits for 3 seconds before progressing to the next sampler.
Universal Random Timer
You can provide a constant and a random delay as parameter; the delay will be always be the sum of constant and random.

e.g.
assume that c is constant delay is 5000
and r israndom delay is 3000

the total delay will be
c+r <=8000 and
c+r>=5000

This timer can be added under a tread group as a whole, JMeter will apply the timer to all the samplers under the tread group and the delay will be the total of c+r and the r can change between samplers and users. Hence this will ensure some constant timing and will also induce some randomness in it.

Constant Throughput Timer

You can set the throughput per minute in the field.
Example. if you set the throughput to 100 per minute but have 200 threads, all
200 threads will run for an iteration and then wait for sufficient time to
achieve the throughput you requested and then run it again.

Gaussian Random Timer

Here you can provide constant amount of time, with most of the time intervals occurring near a particular value. The total delay is the sum of Gaussian distributed value times the deviation value that you specify and the offset value.

i.e. you can provide a constant time and a deviation, hence the time will always be between the constant and the deviation.

Recording the actual think time

Add a timer as a child of HTTP Proxy server element.
In the time delay field give the delay as ${T}

On recording the script, JMeter will automatically add a timer to every request with the actual time delay.

Session Tracking

Cookie
If the web server uses writes cookie to track sessions, you can add HTTP Cookie under the test plan to have JMeter manage the same. The session will be managed by JMeter. However, if there are some specific values which needs to be send along, you can provide it through the key value pair in the cookie manager setting.

Note: – While recording, JMeter doesn’t record cookies. You might have to get the developers help to find out the actual parameters used in the cookie.

Hidden Fields

Hidden fields form the part of the HTTP requests, therefore the same will get recorded. But its possible that the parameters used in the first page will be used in the following page as to track the session, in that case the value will have to be captured in a variable and it would have to be used in the next page. Capturing values from a page will require using regular expressions.

URL Rewriting
Session can also be tracked by rewriting URLs. The url will be embedded with some text or number which will be used for session tracking. For this case too, the text will have to be captured using regular expressions. This can be stored in a variable and can be used in the next

Regular Expression Extractor

Jmeter includes a regular Expression extractor, i.e. you can provide the regular expression and can extract the text to a variable.
The REE is used in conjunction with a sample. A sampler will send some request to the server and will wait for the response, the regular expression extractor can be used on the response the server sends.
Right click on a sampler say HTTP Request.
Select Add>Post Processors>Regular Expression Extractor

Remote testing in JMeter

It’s wise to restrict a system running with 1.4 Ghz processor with 100 threads and at most 300 threads on a system running on a 3Ghz Processor. However if there is a need to simulate higher loads, the same can be done with distributed load testing.
You can install JMeter in different systems then initiate a load test to target an AUT by centrally controlling them from one system. JMeter uses Java RMI protocol to communicate between the test agents in different system and will consolidate all the results to a singe system.
This kind of test needs some setup. For a start we need more than one system. Different systems perform different roles, hence we name it accordingly.

Master: Its where we run the JMeter GUI, we control the entire tests from this system.
Slave/Test Agents: Are those systems where the Jmeter-Server is run which takes commands from the JMeter GUI.
Target: – A target server is where the entire the load from the test agents are directed to.

Installation

Install JMeter Master and Slave systems.
Install JSDK on all systems. This is to ensure that the RMIRegistry is also installed in all systems.

Download and place the following files in the lib folder of all JMeter installations.

Logkit1.2.jar
Jorphan.jar

And the following in the lib/ext folder
ApacheJmeter_core.jar

Configuration
• In the Master System, change the property file, search for remote_host, add the IP address of the test agents in the file. You can provide more than one system by separating them with commas.
• Run Jmeter-server.bat in each Slave systems.

Running the test

1. Open the tests plan that contains the test script.
2. Add the necessary listeners, Its best to restrict with some aggregate listener, since the number of responses are very large.
3. Use the Tools>Remote Start option to start the test agent. You can individually start each one or start all the agents together using the remote start all option.

Read more at

http://jakarta.apache.org/jmeter/usermanual/jmeter_distributed_testing_step_by_step.pdf

15. Tips
Proxy Server: – JMeter captures the HTTP requests, through its proxy server which is configured in IE. However if the network restricts internet access through a proxy, the HTTP requests can’t be recorded directly. Direct access without a proxy is required to successfully record a script.

Direct access to a web resource is also required in running the script. Testing through the proxy server is meaningless, since the entire load will be directed to the proxy and its performance will cause hindrance to the actual test being done.

Secure Sites. In secure sites, the requests are encrypted from the browser and responses are decrypted back by the browser. Its not possible for a HTTP proxy to sniff on the communication between the server and client. Hence direct recording of a HTTPS transmission is not possible. Its only possible with the browser assistance, which is not currently available with JMeter.

Limit the number of Listeners. JMeter down is if you have many listeners active. Use only a simple listener like the Aggregate Report listener or write the respons


Download Full Article

JMeter Complete Reference.doc

You Should Also Check Out This Post:

More Active Posts: