This content originally appeared on DEV Community and was authored by Alex John Chamba
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
- JMeter installed.
- A REST API to test (we will use https://restcountries.com/v3.1/translation/germany)
Configuring the Test Plan
1. Add a Thread Group
Open JMeter and right click on Test Plan -> Add -> Threads -> Thread Group
2. Add an HTTP Request
Right click on Thread Group -> Add -> Sampler -> HTTP Request
3. Fill in the necessary values
- Method: GET
- URL: https://restcountries.com/v3.1/translation/germany
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.
View results:
6. Update Thread properties
Adjust the thread properties according to the load level you want to simulate.
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 JMeterbin
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"
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
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/
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. 🚀
This content originally appeared on DEV Community and was authored by Alex John Chamba
Alex John Chamba | Sciencx (2025-01-30T03:14:58+00:00) REST API Load performance testing using JMeter. Retrieved from https://www.scien.cx/2025/01/30/rest-api-load-performance-testing-using-jmeter/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.