Performance testing using Jmeter

jayesh jamindar
7 min readDec 18, 2020

Jmeter is an open-source java application developed by Apache software. Jmeter is used to capture the performance statistics of an application by sending load to the target server.
Jmeter has been extended to load test Web application (using HTTP/HTTPS protocols), Webservices (using SOAP and REST), Database (using JDBC), and many more. Jmeter comes with an intutive GUI which can be very handy to add and configure various elements like Samplers, Config elements, Listeners, Controllers, Assertions, etc.

Jmeter can be downloaded from the official site:
Download Jmeter

Download the binary from the above location and extract. Run the setup. Once the setup is completed, the jmeter can be launched by clicking the jmeter.bat residing in the bin folder.

Difference between Load, Stress, Spike, and Endurance testing:

Performance testing has been categorized into various types. Some of the common types are described as below:

A. Load testing: Load testing is giving a fixed set of load to the application server and measure whether the application can bear the specified load or not.

B. Stress testing: Stress testing is stretching the system beyond its limit to find the threshold or breakeven point of the application.

C. Spike testing: Spike testing is giving an intermittent load to the application server. A sudden hike and a sudden drop in the given load to verify application behavior under intermittent load.

D. Endurance Testing: The load is given to the application server and the load remains persistent for a significant time to check the application behavior under sustained load.

Load test a web application through Jmeter

A website can be load tested by sending multiple HTTP requests at a time or at an interval of the specified time. The response is then captured, analyzed, and validated by applying an assertion. The intuitive GUI helps us to create a — Test Plan, Thread Group, HTTP Request sampler, Listeners, assertions, and so on.

As we know that the Jmeter works at the protocol level and not at the browser level i.e. we cannot perform or mimic exact web operations like clicking buttons, selecting dropdown values, entering values into the fields etc. like we do in selenium automation.

But we can capture the HTTP requests and their parameters while these operations are being performed. Now if we need to give the different loads to different pages of the web app, we need to add multiple “HTTPRequest” to our test plan, each representing a particular page. The load specified in the thread group config element will be sent to these HTTPRequests. You can add a “Timer” to put a delay to the load generation in subsequent pages (HTTPRequests) without which the load will be generated simultaneously at all the pages.

In the below image, I’ve created a simple load test plan on an static site.

Here the Thread group defines the number of concurrent users (Threads) you want to put on the pages underneath it.

Here “POM design pattern”,”Getting started with selenium”,”test planning and test strategy” are the HTTPRequest samplers which I renamed after the pages of the site. Each HTTPRequest sampler represents an http request to a particular page. Here in this case, we are targetting three pages.

If I run this project, the thread group will generate as many http requests on these three pages as there are number of threads specified in the thread count.
In this case, I’ve specified 4 thread (user) count in the thread group, therefore this thread group will generate 4 http requests to each of these three pages concurrently.

But in the real-world, load testing a website may be way more complex. A website may require you to login before performing any operations. The user must be a registered user and the operations can only be performed once the user gets logged into the web application. Proper authorization and authentication are required before any operation can be performed. Moreover, any user operation may require inputs from previous actions like session id, cookie id, token id and so on. To handle this, you need to pass appropriate request parameters and header parameters in the HTTP request of each page.

In such cases, you can start with recording the user actions using a “Recording sampler”. A recording sampler will capture the HTTP requests, and parameters of every user's actions and store them into the respective HTTPRequest sampler created under the recording sampler during recording activity. Later you can edit the respective HTTPRequest samplers as per the requirement. The user actions are recorded, respective HTTPRequest config elements gets created for every page the user has navigated. The request parameters, cookies, token, session id etc. everything is captured in the request parameter of the corresponding HTTPRequest element. Once this is done, you need to apply the correlation using Regular expression extractor to make the request parameters dynamically available to the subsequent requests. We’ll see the correlation in next tutorial.

But there are some prerequisites before using Recording sampler. These prerequisites are:

1. Importing the Jmeter root certificate in the browser in which recording will be performed.

2. Setting the port of the system which should match the port number specified in the recording sampler.

Importing the Jmeter certificate and port setting

Before you begin the recording for user actions, you need to set the port through which the Recording sampler can listen through i.e. the browser port should be same as the port which is set in the Recording sampler. Secondly, you need to import the Jmeter certificate (ApacheJMeterTemporaryRootCA.crt) into the browser.
From the template, select “Recording” template and click create. This action will create a skeleton architecture that contains “User defined variables”, HTTPRequest, Thread count, Recording sampler, etc. Now edit the default port specified in the recording sampler or change it as per your wish.

Steps to import Jmeter certificate

Assuming you are using chrome browser for recording the user actions, follow the below steps:
1. Go to browser setting
2. Go to advance setting
3. Select Manage certificates
4. Now at the Certificate popup, click the import button.
5. Browse to the location where Jmeter certificate is kept (You’ll find Jmeter certificate under Jmeter’s bin directory)

Steps to set the proxy

The recording sampler will start a Jmeter proxy server which will listen from the port which you have specified in the port field of the recording sampler. Therefore the browser’s port must be same as specified in recording sampler.

1. Go to the browser setting
2. Go to proxy, set the port.
3. This will open the systems, network setting window.
4. Go to proxy tab, and disable Automatically detect settings
5. Enable “Use a proxy server”
6. Enter “localhost” in the Address field, and enter port “8888”(same as specified in the port field of recording sampler) in the port field
7. Press save button

Recording user actions in Jmeter using Recording Sampler

Once the certificate has been imported into the target browser (the one which will be used for recording),
1. Launch the Jmeter
2. click template
3. Select “Recording” from the dropdown.

4. Enter recording parameters and click create button.

5. A recording template will be created, which will contain skeleton architecture of the test plan, having user defined variables, http request samplers, recording sampler, and so on.

6. Under the “Test Script Recorder”, select the target controller under which the recording samplers will be saved,

7. Click start button and launch the browser and start navigating through the application and perform the actions for which you want the performance test.
In this case, I’ve launched techno-geeks.co.in and navigated through three pages- “Getting started with selenium”, “testNg”, and “Grid”.

8. Press stop button once the user actions are performed.

9. Observe the recording sampler. The recording sampler is populated with the http request samplers for these pages.

10. Now copy the HTTPRequest samplers from recording sampler and paste them in Thread group, and remove the recording sampler.

11. Run the project.

The request and response status can be seen in the tree view listener.
Other KPIs can be seen in “Summary Report” listener.

Alternate way to perform recording in Jmeter- Blazemeter plugin:

There is an easy and convenient way for recording the steps than using recording sampler. This is Blazemeter plugin. You can add this plugin in chrome browser, there won’t be any need to set the proxy and importing the certificate. Just start recording, perform the steps you need to record, stop the recording. The Blazemeter plugin will generate a JMX file of the recording. Open this JMX file in the jmeter and perform the changes as per your need.

Some key Performance Indicators in Jmeter

Throughput: Throughput is the number of requests sent to the server per unit of time. It is measured as the time taken by all the HTTPRequest samplers together divided by the total amount of time taken.

Latency: Latency in Jmeter is measured as a delay between the first request sent to the server and the first response received.

NEXT:Correlation in Jmeter

--

--