How to do API Load Testing With Jmeter ?

Published On: 11 February 2021.By .
  • Quality Engineering

Load Testing:-

Load Testing is a non-functional testing process in which performance of software is tested under a specific load. It determines how the software application behaves being accessed by multiple users simultaneously. The goal of Load Testing is to improve performance and to ensure stability.

API:- 

An Application programming interfaces is a set of programming code that enables data transmission between one software and another. It also contains the terms of this data exchange.

JMeter:- 

JMeter is software that can perform load, performance, regression test etc.

Apache Software Founder: – Stefano Mazzocchi developer of JMeter.

JMeter is a Java desktop graphical interface application uses graphical API.

Run on − Windows, Mac, Linux, etc.

JMeter Works:- 

JMeter is simulates a group of users sending requests to a server, and returns result that show the performance of the target application via tables, graphs, logs etc.

Steps to Install JMeter

Step1 Install Java

JMeter is a java desktop application, so it requires a JVM 6 or higher.

Firstly you can download and install latest version java from

https://www.oracle.com/java/technologies/javase-downloads.html

After installed successfully check java JDK is installed successfully or not.

see the output as the below figure.

Open CMD and run command # Java – Version

Step 2 Download Jmeter

Download the latest Apache JMeter 5.4 version of Jmeter is Apache JMeter from

http://jmeter.apache.org/download_jmeter.cgi

Choose the Binaries file (either zip or tgz) to download as shown in the below figure

Step 3 Installation

Installation of JMeter is easy and simple. You unzip the zip/tar file into the directory where you want JMeter to be installed.

Once the unzipping is done installation folder structure.

Step 4 Launch Jmeter

You can start JMeter in three modes

  • GUI Mode
  • Server Mode
  • Command Line Mode

Start JMeter in GUI Mode

If you are using Window, Then run the file bin>>jmeter.bat to start JMeter in GUI mode as below shown

Start JMeter from command line mode

In Jmeter GUI mode consumes large computer memory. Saving the resource, you can choose to run JMeter without the GUI. use following command options. Go to the particular path and run this command

#jmeter

Element of Jmeter

Test Plan: – is where add elements required for your JMeter Test script.

The following figure shows an example of Test Plan

Thread Group –Parallel a pool of virtual users.

Samplers – simulating different requests in JMeter.

Logic Controllers – customize the processing of sampler requests.

Listeners – view and analyze the load test results.

Timers – pause the execution of a test for a defined time.

Assertions – validate the sampler response received from server.

Config Element – modify the sampler requests made to the server.

Pre Processors – modify the sampler requests before its processing.

Post Processors – perform certain actions after the request processing.

Firstly create Tread Group under Test Plan.

Right click on “Test Plan”>>Add>>Threads>>Thread Group. According below picture.

After that create Http Request under Thread Group

Right click on Thread Group >>Add>>Sampler >>Http Request, According below picture.

Threads Group Properties

Number of Threads = No. of users

Ramp-up period (Seconds) = Ramp up speed during test is speed at which new simultaneous users are trying to access the application.

Loop Count = this property tells JMeter how many times to repeat your test. If you enter a loop count value of 1, then JMeter will run your test only one.

Call API with Jmeter

For Example we call login API for load testing and all parameter take from CSV file.

According below picture in Http request

  1. Set protocol according your server https or http.
  2. In “Server Name or IP” enter URL of API
  3. In “Path” enter path of API.
  4. In “Body Data” copy-paste body of API.
  5. If you user parameter from CSV file  then user “${Column Name of CSV file}”

For API Header user “HTTP Header Manager”.

Create HTTP Header Manager under Http Request.

Right click on HTTP Request>>Add>>Config Element >> HTTP Header Manager, According below picture.

Add all required header value for API in HTTP Header Manager.

Then Create “CSV Data Set Config” for use CSV file value in API.

Create CSV Data Set Config under Http Request or Thread Group.

Right click on HTTP Request>>Add>>Config Element >> CSV Data Set Config, According below picture.

In “Filename” Enter path of CSV file there from pick data of API parameters. According Shown in below picture.

Add Listener for see result/response in different format.

Create Listener under Http Request or Thread Group.

Right click on HTTP Request>>Add>>Listener>>View Result Tree/Summary Report/Graph Results add according your requirement, See below picture.

Run of Test plan in Graphical mode

For Run click on Green start button see in below image.

After Run shown summary report below

Throughput: – Basically, “Throughput” is the amount of proceedings produced over time during a test.

It’s also represent as the amount of volume that a website or application can handle Throughput = (number of requests) / (total time).

Error%:- Denotes the percent of errors request. 100% error means all requests sent from JMeter had failed.

Average: It is the average time taken by all the samples to execute particular label.

Min: The Minimum time taken by a sample for particular label

Label: It is the URL or label for the particular HTTP(s) Request.

Samples: Indicates the no. of virtual user per request.

Average: It is average time taken by the entire virtual user to execute particular label.

Min: The Minimum time taken by a sample for particular label

Max: The Maximum time taken by a sample for particular label

Std. Dev.: This shows the set of rare cases which were changing from the average value of virtual user response time.

The min. this value more stable the data.

Standard deviation should be <= to half of the average time for a label

Run Jmeter Script from Command Line Mode

# jmeter -n -t <Path and Name of Jmeter Script> -l  <Location of response csv file> -e -o  <Location of HTML Report>

Related content

That’s all for this blog