Friday 21 March 2014

How to connect the PC Host with PC11 if fire wall is the bottleneck?


How to connect the PC Host with PC11 if fir wall is the bottleneck?








Contents of JMeter GUI

What is mean by Test Plan & WorkBench in JMeter. We are covering how to add and remove JMeter Elements, How to Load and Save JMeter Elements. Alongwith that we are covering how we configure Jmeter Elements. Finally we will see How to save a JMeter Test Plan, Running & stopping Test in JMeter.

After opening JMeter. Firstly, our eyes go to these two Elements,
  • Test Plan
  • Workbench


Test Plan

A test plan shows a series of Elements are useful in application tasting process. These Elements are: Thread Groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements.



WorkBench
The WorkBench is simply a place which creates space to temporarily store test elements at the time of constructing test. In other word, it is a sandbox or portion of a test on which you are working on. That’s why, if the designed test in the WorkBench is ready to proceed, copy that and move it into Test Plan. Jmeter only save the contents of Test Plan not WorkBench.

WorkBench keeps non-test Elements too: Http Mirror Server and Http Mirror Server, these elements are not available in the Thread Group and Test Plan.



Add and Remove JMeter Elements
Adding Elements in Test Plan is very important step to execute your Test Plan. Without going through this, JMeter is unable to execute your Test Plan. A Test Plan is capable to include many Elements such as Listener, Controller, and Timer. To add Element in the Test Plan, right click on Test Plan which opens context-menu of Test Plan, then choose new elements from “Add” list. Alternatively, elements can be loaded from file and added by choosing the “merge” or “open” option.

Before adding any Element in the Test Pane, it is necessary to add first a Thread Group element. The Thread Group says JMeter the number of users you need to simulate, how frequently the users should send requests, and how many requests they should send.

So, first let us know how to add the Thread Group element, right click on Test Plan which opens context-menu of Test Plan and then select Add –>Thread Group.

After adding the Thread Group, the Thread Group should display under Test Plan. If it is not visible, then “expand” the Test Plan tree by clicking on the Test Plan element.

After defining Users, define the task on which they will work. Let us take an example of HTTP Request Defaults Element, add this element by right clicking on Users and then choose Add –>Config Element –> HTTP Request Defaults.



As like adding, you can also remove the Element which is not required. Let us take an example of “HTTP Request Defaults” Element. To remove this Element, right click on “HTTP Request Defaults” and from context-menu choose “Remove” option. It will display the dialog box with message “Are you sure you want to remove the selected Element”, if yes, then click on “Yes” button, or if no, then click on “No” button

Click Yes to confirm delete this element on message box.



Load and Save JMeter Elements
a) Load Elements
To load the element from existing file, choose the element from existing tree on which you want to load the other element, then right click on the selected element and click on “Merge” option. Choose the file from the existing saved Element. JMeter will merge the elements into the tree.



b) Save Elements
To save tree elements, choose the element from the tree, right click on an element and from the context menu option choose the “Save Selection As…”option. JMeter will save the selected element, plus all child elements beneath it. Created file cannot be saved in jmeter by default; you have to explicitly save the element.

When you save the element, it will save with the default name of the element, you can save with the same name or you can change it. For example, The figure below shows the save dialog box with default name “HTTP Request Defaults.jmx”. Either you can give the same name or can change it before clicking on “Save” button.



JMeter Test Elements and Test plan are stored in *.JMX format. JMX is standing forJava Management Extensions.

Configure Jmeter Elements
To configure any Element, first select the element of the Tree from Left Pane and do the configuration settings of the same element in the Right Pane.



You can configure any element of the Test Plan, using the element frame present in the right side of the JMeter window. These frames facilitate to configure the nature of the specific test element.

Saving the Test Plan
First save the Test Plan, before running a test. This saving helps to avoid surprising error comes at the time of running the test plan. To save the Test plan, first go to the File ->Save Test Plan. It displays the save Dialog box,give the file name of Test Plan and click on “Save”.


Running a Test Plan
To run the Test Plan, from top of the menu item click on Run à Start or from the keyboard press “Control+R”. Also, JMeter shows a small green button at the right hand side just under the menu bar – this is an alternative tool to Run Test Plan.



Stopping a Test

There are two ways to stop running test,

First Way: Click on “Stop”, or from keyboard press Control + ‘.’. This is an immediately process to stops the threads, if possible.

Second Way: Shutdown,or press –> Control + ‘,’. This appeals the threads to stop at the end of any present work.


If you enjoy reading article then you can subscribe our updates for FREE, just add your email id below. If you need any specific point to be cover around JMeter GUI in detailed then let me know in comments below. I will keep on updating the article for latest testing information.

Grinder Tool -Java Load Testing Framework

The Grinder, a Java Load Testing Framework

What is The Grinder?
The Grinder is a JavaTM load testing framework that makes it easy to run a distributed test using many load injector machines. It is freely available under a BSD-style open-source license.

The latest news, downloads, and mailing list archives can be found on SourceForge.net.
Key features
Generic Approach Load test anything that has a Java API. This includes common cases such as HTTP web servers, SOAP and REST web services, and application servers (CORBA, RMI, JMS, EJBs), as well as custom protocols.
Flexible Scripting Test scripts are written in the powerful Jython and Clojure languages.
Distributed Framework A graphical console allows multiple load injectors to be monitored and controlled, and provides centralised script editing and distribution.
Mature HTTP Support Automatic management of client connections and cookies. SSL. Proxy aware. Connection throttling. Sophisticated record and replay of the interaction between a browser and a web site.

Dynamic Scripting
Test scripts are written using a dynamic scripting language, and specify the tests to run. The default script language is Jython, a Java implementation of the popular Python language.

The script languages provide the following capabilities:Test any Java code

The Grinder 3 allows any code (Java, Jython, or Clojure) code to be encapsulated as a test. Java libraries available for an enormous variety of systems and protocols, and they can all be exercised using The Grinder.Dynamic test scripting

The Grinder 2 worker processes execute tests sequentially in a fixed order, and there is limited support in some of the The Grinder 2 plug-ins for checking test results. The Grinder 3 allows arbitrary branching and looping and makes test results directly available to the test script, allowing different test paths to be taken depending on the outcome of each test.

The Grinder 2 HTTP plug-in's string bean feature provides simple support for requests that contain dynamic data. The Grinder 3 can use the full power of Jython or Clojure to create dynamic requests of arbitrary complexity.

The powerful scripting removes the need to write custom plug-ins that extend The Grinder engine. Although plug-ins are no longer responsible for performing tests, they can still be useful to manage objects that the tests use. For example, the standard HTTP plug-in manages a pool of connections for each worker thread, and provides an HTTPRequest object that makes use of these connections.

Thursday 20 March 2014

Timers in JMeter

Using Timers,JMeter delays each request while sending which is made by thread. Because of this reason, Timer resolves the server overload issue.

When you add more than one timer to a Thread Group, JMeter keeps the amount of the timers and pauses for that amount of time before executing the samplers to which the timers apply. Timers can be added as children of samplers or controllers in order to limit the samplers to which they are participated.
Types of Timers
  1. Constant Timer
  2. Constant Throughput Timer
  3. Uniform Random Timer
  4. Gaussian Random Timer
  5. BeanShell Timer
  6. Poisson Random Timer
  7. BSF Timer
  8. JSR223 Timer
  9. Synchronizing Timer
Constant Timer:
To delay every user request for the same amount of time use Constant Timer.




Constant Throughput Timer:

Constant Throughput Timer presents random delays between requests in a manner that a load/stress of necessary throughput is sent to the application. Figure shows, Constant Throughput Timer for 60 requests per minute.




Uniform Random Timer:To delay every user request for random amount of time use Uniform Random Timer with every time interval having the same possibility of occurring.





In the above figure,
Random Delay Maximum Value: Maximum random number of milliseconds to delay
Constant Delay Offset Value: Additional value




Gaussian Random Timer:
To delay every user request for random amount of time use Gaussian Random Timer with most of the time intervals happening near a specific value.

Gaussian Random means with most of the time intervals arising near a specific value i.e. constant interval & varying between constant interval + deviation.





In the above figure,
Deviations (milliseconds): A parameter of Gaussian Distribution Function
Constant Delay Offset (milliseconds): Additional value



BeanShell Timer:Between each user request, the BeanShell Timer can be used to create a delay time. (We will see each timer in detailed in upcoming articles with example.)




Poisson Random Timer:
To pause each and every thread request for random amount of time use Poisson Random Timer with most of the time intervals occurring close a specific value.





Sum of Poission Distributed Value and Offset Value generate Total Delay value.



BSF Timer:Between each user request, the BSF Timer can be used to create a delay time usingBSF scripting language.



JSR223 Timer:
Between each user request, the JSR223 Timer can be used to create a delay time using a JSR223 scripting language.


Synchronizing Timer:Synchronizing Timer is used to synchronize requests of various threads, means; it will increase delays between requests. So that, all threads fire at the same time there for regenerating heavy load bursts on your application. It is same like Rendezvous Point in LoadRunner and create big load at various places in JMeter plan.

Usage of _intSum and _longSum in JMeter

intSum:This is a built in function in Jmeter which helps to add multiple arguments/integer Values.
Drawback It can only add two real numbers. For float(12.23, 43.22), it is going to show an error message.
Arguments:

First Argument - The First integer value/Jmeter Variable

Second Argument – The Second integer Value/Jmeter Variable

. . . Nth Argument – The Nth integer value/Jmeter Variable

Last Argument – A variable or a reference name which will store the value for the addition and can be reused later.

Scenario:If User wants to increment a counter value by 2 with each iteration.

{__intSum(${tj_counter},2,tj_counter)}

Explanation:

1)__intSum- function name

2)${tj_counter}- First argument

3)1- Second Argument

4)tj_counter- Last Argument is the Reference name where the addition value get stored.
FAQ:

Is the function __counter better than __intSum?Yes Of course. Even __intSum can be used to increment a number with each thread which is quite similar to __counter function. But __counter function starts the counter with 1 and increment it by 1 and with __intSum we can start it from any number and increment it by any value.

Is there any scenario we can think of?Yeah. It will be helpful while user input needs any addition of any numbers. In that case we can simply add two or multiple values and use the variable to reference it any filed we want to.

longSum:

A Jmeter built in function which will help to add multiple long values.
Drawback - It can not take Float Value as arguments.
Arguments:

First Argument - The First long value
Second Argument – The Second long Value
. . . Nth Argument – The Nth long value
Last Argument – A variable or a reference name which will store the value for the addition and can be reused later.

Scenario:If User wants to increment a certain value by a certain number(Say to match the session ID with each iteration.)

__longSum(${tj_sessionid},65345,tj_sessionid)}

Explanation:

1)__longSum- Function Name

2)${tj_sessionid}- First argument

3)65345- Second Argument

4)tj_sessionid- Last Argument is the variable name where the addition value get stored and can be reused later.

Creating Rendezvous Point in JMeter

Rendezvous point in load testing is a point where an expected number of users wait till all of them are emulated, and then all virtual users send request at one time. This point is created to check the behavior of application where it might get a huge number of requests at a particular time. Its very important to test a Peak Load Scenario when approaching towards load testing a web application.

Jmeter, being the best alternative to commercial Load Testing Tools in the Open Source Arena, here is a way to find this "Rendezvous" point in Jmeter.

The tree elements for our sample test plan would be like

Test Plan
Thread Group - Lets give Number of Threads to be '200'
HTTP Request - Lets hit http://www.ourgoalplan.com with 200 users

Synchronizing Timer - Add this timer and enter '50' as the number of virtual users we want to send request to the server simultaneously
View Result Tree - Use this listener to monitor the performance of the application
Aggregate Report - Use this listener to see the overall performance

Now, as we wanted our application to be hit by 200 virtual users, with the pre condition that 50 users should hit the site in four sets i.e. 50, 50, 50 and 50 which makes 200. Press ctrl + R to run the script after saving.

We would see the users getting emulated and sending request in the same pattern as we wanted by creating a Rendezvous Point.

PS : Number of threads in the Thread Group should always be greater than the 'Number of Simultanous Users to Group By' to make sure that Jmeter doesn't throw any unhandled exception. Its always good to be on the safer side when going forward with Open Source Tools.

What are some of the challenges you faced with JMeter?

If a subsequent request rely on the cookie set by the previous request, the "cookie manager" element is required.



When setting up the "CSV Data Set Config", don't have any spaces in the variable names



Have you used any features of JMeter that gave you greater flexibility?

A. Yes. The JMeter supports BeanShell scripting for greater flexibility. The BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java.

If you want to output all the order ids extracted out of the response messages for the response messages shown below

//OrderResponse>
//rderId>50013914

//responseCode>SUCCESS
//OrderResponse>

An XPath Extractor can be used to extract the "orderId" from the response message and store it in a variable named "orderId" as shown below.





Now, the BeanShell PostProcessor can use the extracted "orderId" variable and write to a file (e.g. C:\\Temp\\order-processing\id.txt ) as shown below.





You could do a lot more powerful things by writing your own embedded scripting with the BeanShell. For example, You can create your own file named MyBeanShell.bshr and copy it to $JMETER_HOME\bin folder. The MyBeanShell.bshr will have functions like

getReportStartDate()
{

import java.text.SimpleDateFormat;

cal = Calendar.getInstance();
cal.add(Calendar.DATE, -10);
sdf = new SimpleDateFormat("dd-MMMM-yyyy");
return sdf.format(cal.getTime());

}

isTenth(int loopCounter)
{

returnValue = false;

if (loopCounter % 10 == 0)
{
returnValue = true;
}

return returnValue;

}

You could invoke these functions from your JMeter elements like

${__BeanShell(return getReportStartDate();)}



Also, note that pre-defined functions like __time can be used as shown above. There are also handy JMeter plugins from Google code at http://code.google.com/p/jmeter-plugins/ containing useful functions, listeners, samplers, etc. Just download the zip file and extract the "JMeterPlugins.jar" into $JMETER_HOME\lib\ext folder. This plugin features are prefixed with jp@gc.


 How do you ensure re-usability in your JMeter scripts?
Using config elements like "CSV Data Set Config", "User Defined Variables", etc for greater data reuse.
Modularizing shared tasks and invoking them via a "Module Controller".
Writing your own BeanShell functions, and reusing them.

What are Pre-Processor and Post-Processor elements? In what order does JMeter process various type of 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.


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.

A Regular Expression Extractor can be used as a Post-Processor element to extract values to be used elsewhere in subsequent requests. For example, if you are using JSF and Seam frameworks, the jsfViewStateand CID values can be extracted as shown below:






The elements are executed in the following order as per the JMeter documentation.

0. Configuration elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null) 
5. Assertions (unless SampleResult is null) 
6. 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.

How would you go about automatically recording the your browser actions into JMeter?

This can be achieved by 2 ways.

Use BadBoy Tool, which is a tool to record your Web interactions.The recorded script can be exported as a JMeter file with the extension .jmx to be imported into JMeter. The generated script will not be pretty, but it can be cleaned up and further extended within JMeter with user defined variables, CSV data config, HTTP defaults, etc. You can record the script as you use your application.








Use JMeter as an HTTP proxy server to record your browser actions.Firstly, set up your JMeter to act as a proxy server on an available port like say 9090 as shown below.




Configure the proxy server as shown below:




Port: 9090
Target Controller indicates where to record. In the above diagram indicates to capture it in theWorkBench under the proxy server itself. This allows you to later on move the captured elements one by one into the TestPlan.
You don't want to capture everything. So, filter it with include and exclude patterns. For example, Include: .*myapp.*, Exclude: .*\.jpg.
"Start" the proxy server.

You need to set up your browser to use this proxy server.



Finally, start using the browser to record your actions. For example, you could use the following URL

http://myhost:7001/myapp/home

Note: If you use localhost instead of myapp as the host, JMeter may not record your actions. To overcome this, type ipconfig on your DOS prompt and copy the local IP address and use that instead of localhost in your URL.

JMeter Realtime Scenario | Design JMeter Scenarios

XML/HTTP based RESTful Web Service calls are made against an order execution system. The system should be able to handle a basic load of 30 orders per 3 min. There will be 30 concurrent users. This means 600 orders per minute.
The test case should simulate at least 2 different account ids.
30 orders per 3 min x 60 minutes = 600 orders per hour.


For this problem, the solution is..

STEP 1: Relevant files.




OrderExecution.jmx is the JMeter script.
1-OrderRequest.xml and 2-OrderRequest.xml are the two sample XML payloads that will be sent via an HTTP POST (RESTful Web service).
TestData.csv is a data file used for retrieving values 1 & 2 to switch between 1-OrderRequest.xml and 2-OrderRequest.xml to simulate 2 different accounts.


1-OrederRequest.xml


//?xml version="1.0" encoding="UTF-8"?>
//OrderRequest>
//accountId>12345

//quantity>150
//unitPrice>12.50
//OrderRequest>

2-OrederRequest.xml

//?xml version="1.0" encoding="UTF-8"?>
//OrderRequest>
//accountId>6789

//quantity>200
//unitPrice>6.50
//OrderRequest>
TestData.csv

1
2

STEP 2: JMeter scripts
If you open the OrderExecution.jmx script file, you will see something like this.



Lets' go through each of the elements. Thread Groups are equivalent of virtual users in other performance testing system. You can add this element by right clicking on the test plan and then selecting Add --> Threads (Users) --> Thread Group. As per the requirements, the system should handle 30 concurrent users. The ramp up time is 180 seconds, which is 3 minutes. All 30 threads will get started in 3 minutes. The loop count is set to 20, to produce 600 orders (i.e. 30 threads * 20 loops) .



It is a good practice to define some variables as shown below, so that these variables can be used in downstream elements without having to hard code. If you want to run against a different host, you can just change it in spot as opposed to having to change it in a number of places. You can add this by right clicking on "Order Processing" and then selecting Add --> Config Element --> User Defined Variables.



The CSV Data Config is a very useful element to read test data from CSV file and then save the read values into some variable. In this example, the values 1 and 2 are read from the file TestData.csv, and stored in a variable named "account". The one iteration will set account to 1, and the next iteration will set it to 2, and then the same assigment repeats since "recycle on EOF" is set to true.



The HTTP Header manager sets the HTTP headers. In this example, the content type is set to application/xml because we are posting the XML files 1-OrderRequest.xml & 2-OrderRequest.xml .



The HTTP request defaults sets the default values so that you don't have to repeat it in each request. Also, note that the user defined variables in the first step are used within ${} as opposed to literal values.



The loop controller can be added to loop through the samplers a number of times. In this example, it is set to 1.



The samplers can be added by right clicking on the "Create Order" loop controller and then selecting Add --> Sampler --> HTTP Request. It shows the path, method, and the file to send. The actual RESTFul web service call will have the URL
http://localhost:8080/myapp/executionservices/execution/1.0/order/create

Also, note that in the File Path the ${DATA_PATH} is a user defined value, and ${account} is a variable that is assigned from the TestData.csv file via the CSV Data Config element. The account will be dynamically changed between 1 and 2 to retrieve the files 1-OrderRequest.xml and 2-OrderRequest.xml respectively for each iteration.



JMeter supports a number of samplers like SOAP request, FTP request, JDBC request, JMS publisher, JMS subscriber, etc to name a few.

The XPath assertions are used to assert the response for presence of responseCode="SUCCESS" and a valid orderId > 0. The response message will look like


//xml version="1.0" encoding="UTF-8" standalone="yes"?>
//OrderResponse>
//orderId>50045671
//responseCode>SUCCESS
//OrderResponse>



The other three elements are reporting elements. There are many reporting elements to choose from depending on the requirements. You can add reporting elements via Add --> Listener.


Finally the Gaussian Timer that will delay the execution by 3 minutes (i.e. 180000 ms) with a standard deviation of 10 seconds. This will ensure the throuput of 30 orders per 3 minutes.


JMter interview questions

What is Jmeter?Jmeter is one of the Java tools which is used to perform load testing client/server applications. It is open source software Designed to load test functional behavior and measure performance of the application.It was originally designed for testing Web Applications but has since expanded to other test functions

What are the other applications tested by Jmeter? JMeter may be used to test performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more)

What do you see when you open jmeter?By defaultTest Plan & Workbench are seen

What is Test Plan in Jmeter?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 conrollers, sample generating controllers, listeners, timers, assertions, and configuration elements.

What is Work bench?The Workbench is simply an area to store test elements while you are in the process of constructing a test.
The Workbench is a sandbox for any test or portion of a test that you are working on.
When you are ready to test what you have designed in the Workbench, you can copy or move the elements into the Test Plan.

It also contains Non- Test Elements
Http mirror sever
Http Proxy server {which is not available in the thread group & Test plan }

What is Thread Group?

Thread group elements are the beginning points of any test plan.
All controllers and samplers must be under a thread group.
Listeners, may be placed directly under the test plan, in which case they will apply to all the thread groups.
The controls for a thread group allow you to:
Set the number of threads
Set the ramp-up period
Set the number of times to execute the test

What are the parts of thread group?Sampler :Sends various types of requests to the server
Listeners : Results of the Run can be viewed & saved
Timer : Makes th erun more realistic by inserting delays between the requests
Controller : responsible for controlling the flow of the thread group.If we have defined request to be executed on some logic like if-then-else or loop structure in java
Config Element : Info about the requests are added to work with samplers using this.
Assertion : To check if the responses are within given time and containing expected data.

What are Controllers and its types? JMeter has two types of Controllers

  • Samplers Controllers 
  • Logical Controllers

Samplers Controllers
Samplers tell JMeter to send requests to a server.
For example, add an HTTP Request Sampler if you want JMeter to send an HTTP request. You can also customize a request by adding one or more Configuration Elements to a Sampler.

Logical Controllers
Logical Controllers let you customize the logic that JMeter uses to decide when to send requests.
Logic Controllers can change the order of requests coming from their child elements.
For example, you can add an Interleave Logic Controller to alternate between two HTTP Request Samplers.

What is Configuration element?A configuration element works closely with a Sampler

Configuration elements can be used to set up defaults and variables for later use by samplers.
Note that these elements are processed at the start of the scope in which they are found, i.e. before any samplers in the same scope.

Its elements:

CSV Data Set Config: Used to read lines from a file, and split them into variables.
HTTP Authorization Manager : You can specify one or more user logins for web pages that are restricted using server authentication
Java Request Defaults: You can set default values for Java testing
HTTP Cookie Manager: The Cookie Manager element has two functions:
It stores and sends cookies just like a web browser.
Second, 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: This element lets you set default values that your HTTP Request controllers use.
HTTP Header Manager : The Header Manager lets you add or override HTTP request headers

What are Listeners?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

The Graph Results listener plots the response times on a graph.
The “View Results Tree” Listener shows details of sampler requests and responses, and can display basic HTML and XML representations of the response.Other listeners provide summary or aggregation information.

Every listener in JMeter provides a field to indicate the file to store data to.They also provide means to view, save, and read saved test results.

How did you go about fixing a performance issue?Set up JMeter to reproduce the production like scenario to put through concurrent requests and put the system under heavy load. Used a profiling tool to monitor CPU times, memory usage, etc.

What are some of your recent accomplishments?Reduced the response time from 4 seconds to 2 seconds. Set up JMeter to put the system under peak load. Used a profiling tool to monitor CPU times, memory usage, etc. Identified the bottle neck, and improved the situation by fixing the offending database connection leak, back tracking regular expression, and a badly constructed SQL query with Cartesian joins.

What are Pre-Processor and Post-Processor elements? In what order does JMeter process various type of 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.

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.

A Regular Expression Extractor can be used as a Post-Processor element to extract values to be used elsewhere in subsequent requests.

How do you ensure re-usability in your JMeter scripts?
Using config elements like “CSV Data Set Config“, “User Defined Variables“, etc for greater data reuse.
Modularizing shared tasks and invoking them via a “Module Controller“.
Writing your own BeanShell functions, and reusing them.

Does Jmeter generate any scripts? How to use the Jmeter tool and also the How to analyze the results?
When you create a test in Jmeter, save the file. The file saves with the extension .jmx.
Open the .jmx file in an editor. There you can see script.

For what purpose Jmeter used?

Jmeter is a Performance Tool. It is used to test the performance of the application. Apache JMeter is a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

Can we Parametrize via Jmeter?
Yes, you can parametrize via CSV file, User define variables or XML sheet.

How did you go about fixing a performance issue?A. Set up JMeter to reproduce the production like scenario to put through concurrent requests and put the system under heavy load. Used a profiling tool to monitor CPU times, memory usage, etc.

 What are some of your recent accomplishments?A. Reduced the response time from 4 seconds to 2 seconds. Set up JMeter to put the system under peak load. Used a profiling tool to monitor CPU times, memory usage, etc. Identified the bottle neck, and improved the situation by fixing the offending database connection leak, back tracking regular expression, and a badly constructed SQL query with Cartesian joins.

What is distributed load testing? How can it be achieved in JMeter?Ans. Distributed load testing is the process using which multiple systems can be used for simulating load of large number of users. The reason of using more than one system for load testing is the limitation of single system to generate large number of threads (users).
In JMeter we can do distributed load testing using the master slave configuration.
[For complete steps to perform distributed load testing refer to the post- Distributed load testing in JMeter]

How can we reduce the resource requirement in JMeter?Ans. To make the best out of the available resources and in general as a practice, following practices should be incoroprated in the tests-

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.]
Don't use functional mode
Use CSV output rather than XML
Only save the data that you need
Use as few Assertions as possible
[ source: http://jmeter.apache.org/usermanual/best-practices.html]
What is Spike testing and how can we perform it in JMeter?Ans. Suddenly spiking or increasing the number of users at certain point of application and then monitoring the behavior at that intervals is spike testing.
In JMeter spike testing can be achieved using Synchronizing Timer. Synchronizing timer blocks the threads until a particular number of threads have been blocked, and then release them at once thus creating large instantaneous load.

What all activities are performed during performance testing of any application?Ans. Activities performed-
1. Create user scenarios
2. User Distribution
3. Scripting
4. Dry run of the application
5. Running a load test and analyzing the result

What is 90% line in JMeter?Ans. The aggregate report listener have 90% line as one of the metric. The Apache JMeter manual describes 90% line as- “90% of the samples took no more than this time”. It is actually the 90 percentile of the response times of the samples -
90 percentile = (90/100)*N+1/2 where N is the number of samples
So, if there are 10 samples then 90%line will be 9.5 or 9. It means the 9th value in the sorted list of samples (sorted according to ascending order of their response times) will be the 90%line value.

 What is BlazeMeter?Ans. BlazeMeter is a cloud based service compatible with Apache JMeter. It generates large amount of instant load and provide very comprehensive reporting and analysis features.
In Blazemeter we can just upload the JMeter script and run the load test on cloud with predefined number of users.
 What is correlation?Ans. Correlation is the most important aspect of scripting. It generally includes fetching dynamic data from preceding requests/calls and posting it to the subsequent requests.
[For more details, refer to the post- Correlation in JMeter]

Explain parameterization in JMeter?Ans. Parameterization is process of generalizing some user input, so as to use it for multiple users or executions.


What are the protocols supported by JMeter?A: The protocols supported by JMeter are:

Web: HTTP, HTTPS sites 'web 1.0' web 2.0 (ajax, flex and flex-ws-amf)
Web Services: SOAP / XML-RPC
Database via JDBC drivers
Directory: LDAP
Messaging Oriented service via JMS
Service: POP3, IMAP, SMTP
FTP Service
Q: List some of the features of JMeter.A: Following are some of the features of JMeter:

Its free. Its an open source software
It has simple and intuitive GUI.
JMeter can load and performance test many different server types: Web - HTTP, HTTPS, SOAP, Database via JDBC, LDAP, JMS, Mail - POP3
It is platform-independent tool. On Linux/Unix, JMeter can be invoked by clicking on JMeter shell script. On Windows it can be invoked by starting the jmeter.bat file.
It has full Swing and lightweight component support (precompiled JAR uses packages javax.swing.* ).
JMeter store its test plans in XML format. This means you can generate a test plan using a text editor.
It's full multi-threading framework allows concurrent sampling by many threads and simultaneous sampling of different functions by separate thread groups.
It is highly Extensible.
Can also be used to perform automated and functional testing of your application.
Q: What is a Test Plan in JMeter?A: A Test Plan defines and provides a layout of how and what to test. For example the web application as well as the client server application. It can be viewed as a container for running tests. A complete test plan will consist of one or more elements such as thread groups, logic controllers, sample-generating controllers, listeners, timers, assertions, and configuration elements. A test plan must have at least one thread group.
Q: List some of the test plan elements in JMeter.A: Following is a list of some of the test plan elements:
ThreadGroup
Controllers
Listeners
Timers
Assertions
Configuration Elements
Pre-Processor Elements
Post-Processor Elements
Q: What is Thread Group?A: Thread Group elements are the beginning points of your test plan. As the name suggests, the thread group elements control the number of threads JMeter will use during the test.
Q: What are Controllers and its types?
A: JMeter has two types of Controllers:
Samplers Controllers : Samplers allow JMeter to send specific types of requests to a server. They simulate a user's request for a page from the target server. For example, you can add a HTTP Request sampler if you need to perform a POST, GET, DELETE on a HTTP service

Logical Controllers : Logic Controllers let you control order of processing of Samplers in a Thread. Logic Controllers can change the order of request coming from any of their child elements. Some examples are: ForEach Controller, While Controller, Loop Controller, IF Controller, Run Time Controller, Interleave Controller, Throughput Controller, Run Once Controller.
Q: What is Configuration element?A: Configuration Elements allow you to create defaults and variables to be used by Samplers. They are used to add or modify requests made by Samplers.

They are executed at the start of the scope of which they are part, before any Samplers that are located in the same scope. Therefore, a Configuration Element is accessed only from inside the branch where it is placed.
Q: What are Listeners?A: Listeners let you view the results of Samplers in the form of tables, graphs, trees or simple text in some log files. They provide visual access to the data gathered by JMeter about the test cases as a Sampler component of JMeter is executed.

Listeners can be added anywhere in the test, including directly under the test plan. They will collect data only from elements at or below their level.
 What are Pre-Processor and Post-Processor elements?A: A Pre-Procesor is something that will happen before a sampler executes. They are often used to modify the settings of a Sample Request just before it runs, or to update variables that are not extracted from response text.

A Post Processor executes after a sampler finishes its execution. This element is most often used to process the response data, for example, to retrieve particular value for later use.
Q: What is the execution order of Test Elements
A: Following is the execution order of the test plan elements:

Configuration elements
Pre-Processors
Timers
Sampler
Post-Processors (unless SampleResult is null)
Assertions (unless SampleResult is null)
Listeners (unless SampleResult is null)
Q: How do you ensure re-usability in your JMeter scripts?A:Using config elements like "CSV Data Set Config", "User Defined Variables", etc for greater data reuse.

Modularizing shared tasks and invoking them via a "Module Controller".
Writing your own BeanShell functions, and reusing them.
Q: Are the test plans built using JMeter OS dependant?A: Test plans are usually saved in thr XML format, hence they have nothing to do with any particular OS. You can run those test plans on any OS where JMeter can run.
Q: What are the monitor tests?A: Uses of monitor tests are:
Monitors are useful for a stress testing and system management.
Used with stress testing, the monitor provides additional information about server performance.
Monitors makes it easier to see the relationship between server performance and response time on the client side.
As a system administration tool, the monitor provides an easy way to monitor multiple servers from one console.

What are JMeter Functions?
A: JMeter functions are special values that can populate fields of any Sampler or other element in a test tree. A function call looks like this:${__functionName(var1,var2,var3)}

Q: Where can functions and variables be used?A: Functions and variables can be written into any field of any test component.
Q: What are regular expressions in JMeter?A: Regular expressions are used to search and manipulate text, based on patterns. JMeter interprets forms of regular expressions or patterns being used throughout a JMeter test plan, by including the pattern matching software Apache Jakarta ORO.
Q: How can you reduce resource requirements in JMeter?A: Below are some suggestion to reduce resource requirements:
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.
Disable the “View Result Tree” listener as it consumes a lot of memory and can result in the console freezing or JMeter running out of memory. It is, however, safe to use the “View Result Tree” listener with only “Errors” checked.
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.
Don't use functional mode.
Use CSV output rather than XML.
Only save the data that you need.
Use as few Assertions as possible.
Disable all JMeter graphs as they consume a lot of memory. You can view all of the real time graphs using the JTLs tab in your web interface.
Do not forget to erase the local path from CSV Data Set Config if used.
Clean the Files tab prior to every test run.

Extract single string in regular expression extractor in Jmeter correlation

Extract single string

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

Note: without the ?, the .+ would continue past the first "> until it found the last possible "> - which is probably not what was intended.

Note: although the above expression works, it's more efficient to use the following expression: 

name="file" value="([^"]+)"> where
[^"] - means match anything except "
In this case, the matching engine can stop looking as soon as it sees the first " , whereas in the previous case the engine has to check that it has found "> rather than say " > .
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$


Do not enclose the regular expression in / /

The following variables would be set:
MYREF: file.namereadme.txt
MYREF_g0: name="file.name" value="readme.txt"
MYREF_g1: file.name
MYREF_g2: readme.txt


These variables can be referred to later on in the JMeter test plan, as ${MYREF}, ${MYREF_g1

Wednesday 19 March 2014

Correlation in JMeter

What is correlation and why it is required?Correlation is the most important aspect of scripting. It generally includes fetching dynamic data from preceding requests/calls and posting it to the subsequent requests.

Let’s take an example,Suppose we have recorded a scenario in which
  1. User enters login details and click OK button
  2. Home page opens and user take further actions
Now, if we just playback this script, the test will fail even for a single user. This is because of the authentication mechanism used. When we login to a website, session variables are dynamically created. These session variables are passed to the subsequent requests and help validation and authentication of the actions performed. So, one cannot just record and playback the requests having these variables. Here, we need to correlate the web requests with the dynamic variables. And for correlation, we need to use the “Regular Expression Extractor” which makes use of regular expressions.

A brief insight to regular expressions:

Regular expressions are used to fetch data from a string based on a search pattern. Basically, what we do is- in order to extract any value (generally a dynamically created value) from a string (text response), we define a left bound of the variable then some wildcard characters and then right bound-
(Left Bound)(Wildcard Characters)(Right Bound)
E.g. for if we have text response like-
.......__EVENTVALIDATION"value="weriudflsdfspdfusdjfsisdpfjpsdfohsdihffgdfgdfgdfgdfgdfgdfglsdjkfpjspdfjsdjfpj" />…..
And we need to extract the value of Event validation variable using regular expressions; the regular expression for the same will be-
__EVENTVALIDATION" value="(.+?)" /> where, Left Bound = __EVENTVALIDATION" value="
Wildcard characters = (.+?)
Right Bound = " />
If you do not want to get deeper into regular expressions, then the wildcard characters (.+?) would suffice in most of the cases. For more information on regular expressions and meaning of each wild card character visit http://www.regular-expressions.info/tutorialcnt.html.

Regular Expression Extractor:Coming back to JMeter, consider an example where we have two operations-
1. User launch website
2. User fill details and click on OK button
Now, the call user launch website creates a dynamic variable event validation that we can check in Response Data tab of “View Result Tree” listener for the call. The value of this variable is then passed to subsequent call related to “User fill details and click on OK button” as Http post parameter.

Steps for correlating the Event validation values:1. Run the script containing the both the above stated operations
2. Go to Response tab (Text mode) in “View Result Tree” listener of “User launch website” operation. BTW, we see the second operation “User fill details and click on OK button” in red because it is not yet correlated.




3. Create a Regular expression for extracting the value of Event validation variable’s value. As stated above the R.E. for this will be-
__EVENTVALIDATION" value="(.+?)" />

4. Go to http request under “User Launch Website” transaction controller-> Add -> Post Processor -> Regular Expression Extractor.


Adding “Regular Expression Extractor” control



R.E. Extractor Parameters Filled

5. The reference name inserted is the name of the variable created that will capture the value Event validation generated by the http request under “User launch website” operation.

6. Now pass this variable to the subsequent http request under “User fill details and click on OK button” as post request- overriding the already present hardcoded value of Event Validation variable.


Request without correlation (Hardcoded values)



Request with correlation (Dynamic values)

7. Run the Test plan again. All green? That's it.

This was all about correlation. In order to get good understanding of correlation (or scripting for that matter) we need to have a good understanding of two things- the dynamic variables generated by the programming languages and Regular expressions.