DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Spring Boot: Test Restful Web Service Using Curl Client
  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service

Trending

  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 1
  • Kullback–Leibler Divergence: Theory, Applications, and Implications
  • A Complete Guide to Modern AI Developer Tools
  • Building Resilient Networks: Limiting the Risk and Scope of Cyber Attacks
  1. DZone
  2. Coding
  3. Frameworks
  4. SpringBoot: Performance War

SpringBoot: Performance War

A closer look at SpringBoot and its role in performance.

By 
Santhosh Krishnan user avatar
Santhosh Krishnan
·
Updated Mar. 11, 20 · Analysis
Likes (14)
Comment
Save
Tweet
Share
21.5K Views

Join the DZone community and get the full member experience.

Join For Free

Performance Matrix of Reactive APIs With WebFulx and Redis

Reactive Systems are designed to address challenges posed by modern software systems - the challenges related to a large number of users and high throughput. Reactive systems are expected to be highly responsive, resilient, elastic and message-driven.

In this article we will:

  • Build a set of fully non-blocking REST API using SpringBoot 2.0, WebFlux and Reactive Redis.
  • Performance test the above Reactive APIs against the traditional non-reactive APIs

The code used in this example can be downloaded from  GitHub

Step One: Create a Skeleton Reactive WebFlux SpringBoot Project

Create a SpringBoot maven project using - https://start.spring.io

Add the following dependencies:

  •  spring-boot-starter-web 
  •  spring-boot-starter-data-redis 
  •  spring-webflux 
  •  spring-boot-starter-data-redis-reactive 

Refer to the dependencies in pom.xml

You may also like: All About Spring Boot [Tutorials and Articles].

Step Two: Create Domain Objects

The demo project uses the domain objects Customer and Account. A customer can have multiple accounts.

Creating two domain objects

Creating two domain objects

Step Three: Create Non-Blocking Reactive REST APIs Using WebFlux

Create a REST controller CustomerControllerRx for the purpose of serving the following reactive no-blocking APIs.

  • Add/update a Customer
  • findById a Customer

The code snippet uses Mono which is an implementation of Reactive streams Publisher interface and ReactiveRedisTemplate and ReactiveValueOperations to interact with Redis in a non-blocking way.

Reactive Redis Template

Reactive Redis Template

ReactiveRedisTemplate is configured in  RedisConfigRx

Step Four: Create Synchronous (Blocking) REST API

Create a REST controller CustomerController for the purpose of serving non-reactive blocking APIs. We are using CustomerRepository which extends a CurdRepository to interact with the Redis database.

Creating a REST controller

Creating a REST controller

Step Five: Connecting to Redis Using Docker

  • Redis doesn’t officially support Windows. However, the easiest way to get Redis up and running for UNIX or Windows is by using Docker.
  • Use the following steps to pull a redis image from docker hub and to start on port 6379 in detached mode.
Java
 




xxxxxxxxxx
1


 
1
$ docker pull redis $ docker run -d -p 6379:6379 --name redis1 redis $ docker ps -a // make sure redis is up and running.



Refer to application.yml for Redis connection properties.

Step Six: Set Up JMeter for Testing

  • Install Apache JMeter https://jmeter.apache.org/
  • Install the following graph plugins from the plugin downloads site https://jmeter-plugins.org/
    • Basic Graphs
    • Additional Graphs

The above plugins are zip files and can be extracted to the lib folder of the JMeter installation folder. Once the plugins are installed, JMeter can be started from the bin folder.

The next step is to create Test Plans for the APIs that are required to be benchmarked. I have the following Test Plans for the APIs.

GetCustomers.jmx

  • To performance test non-reactive CustomerController : findById () method.
  • Get Mapping

SaveCustomers.jmx

  • To performance test non-reactive CustomerController : add () method.
  • PostMapping

GetCustomersRx.jmx

  • To performance test reactive CustomerControllerRx : findById () method.
  • Get Mapping

SaveCustomersRx.jmx

  • To performance test reactive CustomerControllerRx : Add () method.
  • PostMapping

The above Test Plans can be opened in JMeter and configured for a different number of concurrent users — E.g.  5, 50, 100, 400, 500 and so on. Now, JMeter test cases can be executed in a non-UI mode as below.

Shell
 




xxxxxxxxxx
1


 
1
jmeter -n -t <TestPLan.jmx> -l <TestPlan.jtl> -e -o <output folder>



Where:

              -n           run in non-GUI mode

              -t            provide the name of the test file

              -l            name of the output report file

              -e           jMeter to follow post-processing specified in the jmx file.

              -o           dashboard folder.

Step Seven: Benchmark Reactive REST APIs vs. Blocking REST APIs

Start SpringRedisReactiveApplication 

  • Make sure the application starts without errors by connecting to the Redis DB on Docker.
  • Set no of users (threads) and loops (iterations) for the Test Plans.

Open the TestPlan using JMeter UI and change the number of users (threads) and set the number of loops. Save the test plan. Exit JMeter UI.

  • Execute Test Plans

Go to JMeter\bin folder and execute:

Shell
 




xxxxxxxxxx
1


 
1
jmeter -n -t <path>\SaveCustomers.jmx -l <path>\SaveCustomers.jtl -e -o <path>\SaveCustomersOutput-5Users



The above command will run SaveCustomers.jmx TestCases creates a reporting folder named SaveCustomersOutput-5Users

  • Repeat step 6 (b) and 6 (c) for the other test plans, every time changing the output folder name.
    • SaveCustomersRx.jmx
    • GetCustomers.jmx
    • SaveCustomersRx
  • Repeat step 6 (b), (c) and (d) for 10, 50, 100, 200 and 400 users.

Performance Metrics

Image title

Image title

Image title

Image title


Small no of concurrent users

  • The performance of Blocking APIs is perfectly fine.
  • Performance is affected when the no of users is increased.

A large no of concurrent users

  • non-blocking asynchronous Spring WebFlux APIs performs significantly better.
  • 30 to 40% increase in response times with Reactive components.
  • A threshold is reached when the number of users is about 300.


Further Reading

  • Top 10 Spring Boot Interview Questions.
  • Microservices Architecture: Introduction to Auto Scaling.
  • Microservices Architecture With Spring Boot and Spring Cloud.
Spring Framework Testing Redis (company) Spring Boot REST Web Protocols WAR (file format)

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot: Test Restful Web Service Using Curl Client
  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!