6. Spring WebFlux: Load testing using JMeter

George Gatheca
5 min readSep 15, 2021

--

For this tutorial we are going to learn how to use Jmeter to perform load test on out API.

You can download Jmeter from their official website https://jmeter.apache.org/. It is a java application meaning it will require java to run and can run in all environments where java is installed.

Full source code can be downloaded from this repository if you have not been following up with previous tutorials.

Once you have the code, created the database and imported the SQL file in repository “db.sql”, changed the database connection details in “application.properties” file, then you can run the application.

To test one endpoint, you can invoke “http://localhost:8080/students/1” and expect to see such a response meaning API is working.

Sample response from API

Load Test

Start jmeter and follow steps below.

  1. Jmeter will launch with a new Test Plan already created. You need to add a “thread group” to the test plan as shown below. This will allow us to simulate the number of users who are accessing the website simultaneously. After added change number of thread(concurrent users) to 200, ramp up period(all users access concurrently) to 0, and Loop count to 10.

2. Add a http request to thread group as shown below. This will allow us to make HTTP requests to the api endpoints that we want to test.

3. To configure HTTP request, you need to fill all this information.

  • Protocol is http, if you are testing on a server with SSL then you can use https.
  • Server is localhost or where API is running
  • Port is 8080 in localhost or 80 depending on how you are running application
  • For HTTP request method we can test any endpoint. Eg get all students which is a HTTP GET method endpoint so we select GET and path put “students”.

4. Add a POST http request. For this just add another http request to thread group. For this choose post method and under “Body Data” add the following JSON from Line 1 to 3.

Our post endpoint expects request to have header “Content-Type” with value “application/json” otherwise cannot perform the action. For this right click the http request that is post and add Config Element -> HTTP Header Manager then add t header “Content-Type” to it with above value.

5. We are almost done. Now we need to be able to visualise the output of both the requests *GET students and *POST students. For this on each HTTP request right click and add listener “View Results Tree”. This will help us view every request sent for each endpoint. We also need aggregate report for both so on Thread Group add a listener “Aggregate Report”. At the end you should have the following structure.

Once all of this is done, we can now execute test plan and view results. Click on run button and wait for results. Below you can see sample results of the GET and POST endpoints.

Aggregated results summary
Results for post method

Understanding the results:

The key values from above test are:

  • Error % — This will tell us the percentage of request that are getting dropped or encountering an error. In our case you can see all requests are successful as error is 0%. You can increase the number of concurrent users in Thread Group and each time observe the error rate to determine the threshold hold of the API; ie the point where requests starts getting errors. If you have a non reactive API doing the same thing, you will observe that threshold is much lower than reactive meaning reactive is better at handling more users.
  • Min/Maximum/Average — This will tell us minimum, maximum and average response time for a single request. You can also compare with a non reactive API doing same thing and observe that its much lower for reactive meaning API is much more responsive. Even with simulated pause of 2 seconds on GET endpoints for each student in DB, we can see no request is getting dropped.

Summary

Well this has been a rather long tutorial about spring reactive API development. I know it can be hard and challenging to learn a new method of programming when used to sequential design but as you have seen, the benefits are many. While this is not a comprehensive tutorial, it will form a very strong foundation for exploring and using reactive programming on your day to day activities.

Finally am really grateful for you taking your time to learn with me. There are always ways to improve and if you have any feedback, compliments or suggestions for new things you might want to learn then reach out via the following channels and will be sure to respond.

LinkedIn: https://www.linkedin.com/in/gathecageorgenjoroge/

Medium: @gatheca-george

Twitter: https://twitter.com/gatheca_george

Happy Learning

Happy Learning

WHATS NEXT

So what’s next after this? Well checkout for the next articles on the series.

  1. Spring WebFlux: Reactive micro service Introduction
  2. Spring WebFlux: Reactive micro service Practical guide Intro
  3. Spring WebFlux: Using Relational Database (MySQL & PostgreSQL)
  4. Spring WebFlux: Unit testing your REST API (Continuation)
  5. Spring WebFlux: Tips & Tricks, Common mistakes
  6. Spring WebFlux: Load testing using JMeter (You are here)

Want to learn more, have a topic in JAVA you might need articles on or have questions? Reach out to me on my profile or via LinkedIn here.

Hello👋, Did you find this tutorial helpful, please click the clap 👏 button below to show your support for the author 👇. Also this will help the algorithm for others who are learning to see this story.

--

--

George Gatheca
George Gatheca

Written by George Gatheca

Senior Software Engineer; Spring Java enthusiast; Building scalable solutions; Reducing compute waste.

No responses yet