Blog

RESTful API Performance Testing Using JMeter

RestFul API

REST (Representational State Transfer) is a simple stateless architecture which uses HTTP protocol & RESTful are the web services that are developed based on the REST architecture. In a Client-Server Application, most of the web services use RESTful API so that clients and third party applications can access its resources using the URI (Uniform Resource Identifier). RESTful typically communicates over HTTP using methods like POST, GET, PUT and DELETE. Firstly, Oauth request can be used to create a token that will be passed on to other REST API’s for the sake of establishing a secure session.

Why JMeter is Preferred over Other Tools:

Quality should be ensured from API’s performance perspective. Performance can be measured using different proprietary or open source tools e.g. load UI, JMeter etc. as these two are available in the market that provide more support for API’s Performance testing than any other tool.

Before selecting a tool, keep in mind different parameters such as the tool should be cost effective, easy to use, easy to configure & easily available third party plug in, if needed. Here we will discuss JMeter as it has all the stated features in it as well as it has more support from well-established open source community as compared to Load UI. JMeter can be used to gather information related to API request, response time of server & resource utilization of server for a given number of threads in following ways:

  • Request/Response time of RESTful APIs

All below mentioned points would be the listeners in case you are using JMeter. All these will give output according to the required criteria.

TPS (transaction per second)
Aggregate time of all virtual users
Request-response time graph of APIs
Active thread in a given time
View results in tree (actual results will be shown here)

  • Resource Utilization of Server

All these can be achieved by using a standard plugin of JMeter. Add it to JMeter BIN directory where you are running your JMeter & place Server agent as the part of plugin anywhere on server, to get to know how much below mentioned resources are used in a given time, while sending request & receiving response. Here resources of server will be referred to the following points:

Memory consumption
CPU usage
Network I/O
Disk I/O etc

Steps required for Web Services Performance Testing:

Below is the sequence of steps that needs to be performed for conducting Performance testing of RESTful APIs.

1. Technical Requirement:

It is referred to as given URI (Uniform Resource Identifier) of all APIs that needs to be tested. Here first APIs can be of Oauth (used POST method) that will create token & need to pass on to other APIs to make a secure session for a defined period of time.

2. Requirement specific to Performance testing:

These requirements are referred to as, what should be the response of a request over a given method like POST, GET etc. how APIs will get Token from first Oauth APIs etc.

3. Select JMeter as tools:

After you have above two requirements in hands, open Jmeterw (Windows command script file) from BIN directory of JMeter and the JMeter interface will be opened.

4. Add Test Plan & HTTP Request Defaults:

Test Plan will already be created, if it’s not then create it and rename it as “RESTful Test Plan”. Add a Config Element of HTTP Request Default to Test Plan and give server name or IP that is common for all APIs.

5. Add Thread Group:

Add Thread Group to Test Plan. Rename it as “Oauth”. Here you can give no: of threads (virtual users) for defined period of time.

6. Add HTTP Header Manager:

Add it to the Thread Group. Header will be stored in this header manager as “Content-Type” and its Value will be “application/json”.

7. HTTP Request:

Add Sampler HTTP Request to the Thread Group. Here you will have to provide URI of Web services in PATH text field. Leave “Server name or IP” empty as it was already defined in HTTP Header Manager.

8. Add Listeners:

Add different listeners to the thread group according to the output type.

9. Repeat all of the above steps for other web services.

10. Add token to others’ HTTP Header Manager.

While conducting performance testing of APIs you are actually also performing load & stress testing, as load can be covered when you try different variations in number of threads and stress can be covered when threads are at peak.

Results of Performance testing of RESTful APIs can be counted in following ways:

  • It is ensured that how well were the requests, responses and their behavior under different loads and time.
  • It is checked that how much the server resources are utilized under different loads and time.