Load Testing Published APIs With JMeter

DZone 's Guide to

Load Testing Published APIs With JMeter

How to use the WSO2 API Cloud and JMeter to effective test your published APIs.

· Performance Zone ·
Free Resource

Today we will describe how you can use Apache JMeter to load-test your APIs in WSO2 API Cloud and see these limits enforced.

1. Start by publishing your API and subscribing to it as explained in API Cloud tutorials.

2. Download Apache JMeter here, extract the files, navigate to /apache-jmeter-2.11/bin folder, and start it by running:

  • sh jmeter.sh on Linux or Mac,
  • jmeter.bat on Windows.

You can find more information on JMeter on their Getting Started page.

3. To add your test, in JMeter window, right-click the Test Plan node and click the Add / Threads (Users) / Thread Group on the shortcut menu:

JMeter add thread group

4. Now to add API call request, right-click the Thread Group that you have just added and click the Add / Sampler / HTTP Request on the shortcut menu:

JMeter add HTTP request

5. Provide API call details: Server Name and Path. You can easily see them on your API’s API Console page in API Store in Request URL when you invoke the API:

Getting API Server Name and Path from Subscriber Portal's API Console

Server Name is the domain of the API URL. If you have not assigned your own custom URL, this would be gateway.api.cloud.wso2.com.

Path is the rest of the URL. For example, in my case this is /t/wso2new/wb/1.0.0/countries/us.

Put your parameters in the corresponding fields of JMeter:

JMeter API server name and path

6. Now we need to add the authorization header. Right-click the HTTP Request node and, on the shortcut menu, click Add / Config Element / HTTP Header Manager:

JMeter Add HTTP Header

In the HTTP Header Manager, click the Add button. A new row will get added to the table of Headers Stored in the Header Manager.

Set Name to Authorization. And copy the Bearer part from the API Console:

JMeter Add Authorization Header

7. To be able to view results, add a listener. For that, right-click the Thread Group node and, on the shortcut menu, click Add / Listener / View Results Tree.

JMeter View Results Tree Listener

8. Now you can click the Run button and verify that the API call was successful. If prompted to save the configuration, do so.

JMeter single test

9. To be able to test at larger load, go back to the Thread Group node, and increase the Number of Threads and Loop Count:

JMeter increase load

10. You will see that some of the messages are now getting blocked by the API Gateway. Check out the Response data tab to see why.

The limits imposed on the subscriber by the Subscription Tier that you set for the API – for example, 20 calls / minute – will result in “You have exceeded your quota” response:

JMeter failing subscriber limits

The transactions per second (TPS) limits that are based on your API Cloud subscription level will lead to “Your request was blocked due to exceeding the allocated quota. Please contact the API Store owner to resolve this.”:

JMeter failing organization limits

11. If you want to simulate multiple subscribers, you can create another subscriber account in API Cloud and create another HTTP Request in JMeter with this new subscriber’s authorization header.

12. To run the tests from multiple machines using commandline, you can use the saved plan file and run:
sh jmeter.sh -n -t TestPlan.jmx -l Test1.jtl
where -t specifies the saved Test Plan file and -l specifies the output file for the responses, or the corresponding .bat command on Windows.

That is it! Try it today in WSO2 API Cloud!

About Dmitry Sotnikov

Dmitry Sotnikov is Vice President of Cloud solutions at WSO2. Prior to WSO2, Dmitry worked at Quest Software (now part of Dell) as Director of Cloud Solutions, and later co-founded Jelastic PaaS and led Jelastic's sales, marketing, customer and partner relationships. Dmitry has been a featured speaker at multiple industry events including Microsoft TechEd, VMware VMWorld, Parallels Summit, Quest Innovate, and Technology Experts Conference (TEC). View all posts by Dmitry Sotnikov →

api, api cloud, jmeter, load testing, performance

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}