DEV Community

Cover image for REST API Load performance testing using JMeter
Alex John Chamba
Alex John Chamba

Posted on

REST API Load performance testing using JMeter

Introduction

JMeter is the perfect tool to test the performance of your REST API. In this guide, I'll show you how to set it up and run a load test in minutes in a straightforward way. Let's get started! 🚀

Prerequisites

Configuring the Test Plan

1. Add a Thread Group

Open JMeter and right click on Test Plan -> Add -> Threads -> Thread Group

Add Thread Group

2. Add an HTTP Request

Right click on Thread Group -> Add -> Sampler -> HTTP Request

3. Fill in the necessary values

Fill HTTP values

4. Add a Listener to see the Request response

Right click on Thread Group -> Add -> Listener -> View Results Tree

5. Save and Run

Save the changes (this creates a .jmx file), then press the Start button to run a test.

Save

View results:

View Results

6. Update Thread properties
Adjust the thread properties according to the load level you want to simulate.

Update Thread


Running the Load Test

Optimizing JMeter 🛠️ (Optional)

To avoid JMeter consuming too many resources:

  • Use as few Listeners as possible.
  • Don't use "View Results Tree" or "View Results in Table" listeners during the load test, use them only during Test Plan creation and debugging. Disable the listener by right-clicking View Results Tree -> Disable.
  • Make sure you have Java 21 installed.
  • Increase Java Heap size to 2 GB or more, this depends on your test plan and number of threads you want to run. To do this, create a setenv.sh file in the JMeter bin directory:
# This is the example file jmeter/libexec/bin/setenv.sh

# Use a bigger heap, but a smaller metaspace, than the default
export HEAP="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=192m"
Enter fullscreen mode Exit fullscreen mode

Running JMeter in CLI Mode

Once everything is ready, you will use CLI mode (Previously called Non-GUI mode) to run it for the Load Test.

⚠️ Don't use GUI mode for Load Testing ! Use it only for Test Plan creation and Test Plan debugging.

Run JMeter in CLI mode:

jmeter -n -t ~/Documents/View-Results.jmx
Enter fullscreen mode Exit fullscreen mode

Run JMeter in CLI mode and generate a report:

jmeter -n -t ~/Documents/View-Results.jmx -l ~/Documents/logs/test-results.jtl -e -o ~/Documents/results/
Enter fullscreen mode Exit fullscreen mode

Parameters used:

-n, run JMeter in CLI mode
-t <argument>, name of .jmx file that contains the Test Plan to run
-l <argument>, name of .jtl file to log sample results
-e generate report dashboard
-o <argument> output folder where to generate the report dashboard (Folder must not exist or be empty)


Analyzing the Load Test

Once your Load Test is finished, you can use the HTML report to analyze your load test. To do this, you must open the results/index.html file.

Done! You now have a working load test. 🚀

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more