JMeter Tips and Tricks Part-1

In this part I will share some finding of mine using Jmeter. I have not done all on purposely. Some of them are from different blogs that I have read so far.

-Always use latest Version(for maximum support for low resource uses)
-Always use latest jre
- It is better to use 4gb+ RAM for high load execution(with quad core CPU)[more user , more resource]

Test Plan

-Use JMeter GUI for Test Plan and Test Debugging.
 -Davide your test plan into different Thread Group based on User Type
-Use Transaction Controller for measuring time specifically for a request as well as whole set of request..
-Use Simple Controller and Random Order Controller to send request differently under a thread group
-Try to avoid un-necessary uses of Post-Processor and Assertions.
- Avoid Body(unescaped) if you use Regular Expression Extractor. Try to use it efficiently.
-Use Response Assertion and Size Assertion (or Duration assertion)
-Avoid Xpath/XML/XML Schema Assertions (high memory and CPU hungry)
-It is good to use script(I am using perl, Groovy is also good)
-It is better to use recording by http proxy than manually entry of http request(time saver). Use filter for excluding and including necessary requests.
-Use parametrize values and separate text file[with CSV Data Set Config ] to reading those value for testing(Ex- Username and password or search text)
-Use variables in test plan to use it all over test plan.
-Use test action (a sampler) to apply time specific behavior.
-It is better to use thread group using from plugin. If you use default thread group, try to parametrize that, so that it can be run-time configurable.[This is commandline user and loop count parameter jmeter test plan run command  jmeter -t TestPlan.jmx -Jusers=10 -Jcount=50]

Test Debugging 
-Debug you test case using View Results Tree listener.
-Disable view result size limit by enabling this line from can see any of my configuring jmeter for basic idea)

 Custom Coding(using extension) 
..(Coming Soon, I have not done yet)

Test Execution
-Run JMeter in Non GUI mode on Test Execution.
-Unless you need on purpose, try to avoid executing test in distributed way. It is very resource hungry.
-if we need Remote testing, Try to run jmeter in StrippedBatch mode(You can see this post for how to run jmeter in this mode)
-Remove all Listener while execution , save only the test results.We can extract reports from result file.
-Use .CSV format to save results. either you can edit or for enabling CSV file result saving options(For help,you can see this post)
-Best to use Aggregate Graph, Response Time Graph, and  plugin graphs(see this post for plugin installation)

...To be continued. ....(I will add more on time to time)


What is HTTP Request Defaults? Why we use it

In this following article we are going to see what is HTTP Request Defaults in JMeter and why we use it.

HTTP Request Defaults is the default configuration set for each http request in a fragment/thread/plan which are under it. This is one king of Configuration element that controls the HTTP Request .

When we add a  HTTP Request Defaults(Thread group->(right click)add->Config Element-> HTTP Request Defaults) we will find these

Server:Domain name /IP of server [Exclude http:// prefix]
Port: Port of server.
Connect Timeout(ms): Time to wait for a connection to open
Response Timeout(ms):Time to wait for a response.
Implementation:Java/HttpClient3.1/HttpClient4.[If blank, the default will be activated that is in]
Protocol :HTTP/HTTPS
Path: The path to resource.
[Note:Path is the default for the full path, not a prefix to be applied to paths specified on the HTTP Request screens.
Send Parameters With the Request -The query string will be generated from Name and Value.The query string will be generated depending on the choice of "Method"(In the http request sampler)
[If we send a file by multipart form, it will be created using the multipart form specification].
Press Add to add row for parameter.  We can enable encoding if we need(spatially for https)
Server (proxy): Hostname/IP [Exclude http:// prefix.]   
Port: Proxy Port
UserName/Password for Proxy
Retrieve All Embedded Resources from HTML Files: Enabling this, Jmeter will parse the HTML file and send HTTP/HTTPS requests for all images/Java applets/JavaScript /CSS etc
Use concurrent pool: Use concurrent connections to get embedded resources.
Size(byte):Pool size for concurrent connection
Embedded URLs must match: Filter option(Perl regular expression)

Why we use HTTP Request Defaults?
1. When we need to categorize http request under single configuration
2. When we need to use a configuration for multiple fragment( test request segments)
3. When we need to dedicate a particular sampler set following a specific http/https request settings.

-It is best practice to use HTTP Request Defaults in test planning so that we can track the configurations and requests easily.


What is JDBC Connection Configuration? Why we use this.

In this following article we are going to see what is JDBC Connection Configuration in JMeter and why we use it.

By naming, we can understand it is one king of Connection Configuration element that controls the JDBC connection. It will control the the communication to any Data Base used by JDBC. And, it will be present in side a config element.

When we add a  JDBC Connection Configuration(Thread group->(right click)add->Config Element)-> JDBC Connection Configuration) we will find These

Variable Name*: Connection settings will be stored in this variable. Use unique names for Multiple connections Configuration as JDBC Samplers will select any one to use. If two configuration elements using the same name, only one will be saved.
Max Number of Connections* : Number of threads allowed in the pool the connection.
[0=the connection is not shared between thread,
any number = The max count of thread share this connection.(to ensure threads don't wait on each other)[Note: on sharing, thread number = this number]
Pool timeout(m)*: Time to retrieve a Connection Pool (Throws an error when the timeout period is exceeded in the process)
Idle Cleanup Interval (ms)*: Time to Clean a connection pool when it is Idle.( need more experiment on exact functionality)
Auto Commit* Enable/Disable auto commit for connections.
Transaction Isolation* : Transaction Behavior for a connection pool.
Keep-alive*: Logically, connection behavior for validation query( need more experiment on exact functionality). Default true.
Max Connection Age (ms)*: Logically, connection life time for the validation query.( need more experiment on exact functionality). Default 5000.
Validation Query*: A simple query to know the database response.
Database URL*: JDBC DB Connection string
JDBC Driver class*: Fully qualified(including package) name of driver class(Include .jar to \lib)

*= Mandatory

Why we use this ? As it is the configuration for database connection. It will be used for any request that needs a database.Different database's JDBC driver should be located in \lib or should be added to class path(of test plan).
We can see more with the example from my jmeter database related posts.


What is HTTP Header Manager? Why we use it

In this following article we are going to see what is HTTP Header Manager in JMeter and why we use it.

By naming, we can understand it is one king of element that controls the header. And, it will be present in side a config element(as it holds all type of configurable elements)

So, When ever we add a HTTP Header Manager(Thread group->(right click)add->Config Element)->HTTP Header Manager). We can see a section "Headers Stored in the Header Manager". This section contains all header. We can either add or load(previously saved) a header list.
So, When we add a header we have provide type of http header as name and the string of the header as value.
Ex- If we want to add a opera User-Agent in header, we will add a blank row, we will write "User-Agent" in the name section and value "Opera/12.80 (Windows NT 5.1; U; en) Presto/2.10.289 Version/12.02"

Note: When we add headers in the manager, those headers are append to the request. For a whole thread group, one header manager should be present(multiple supported). If one header added to multiple manager , latest one(or specific one) will be use.

Some useful headers are
-Cookie    [preciously set cookie, (different from cookie manager)]

We can see the full list in this here.

Why we use HTTP Header Manager? When we need to send http request with specific header( that may define the http response because of that header). For example,
-when we need specify user agent/browsers
-When we need to specify language
-When we need to specify Date/Time
-When we need to specify Date
-When we need to specify Content Length/type
-When we need to specify conditions of response to server
-When we need to specify proxy

... Thanks..:)