Recently, one of the big customers asked if we can integrate light-4j middleware handlers to address cross-cutting concerns to Spring Boot applications. They want to leverage the light-4j middleware handlers as they are faster, smaller and easier to customize. Most importantly, these handlers work with Light infrastructure to form an ecosystem to support microservices architecture. In this way, they can migrate their thousands of Spring Boot applications to Light without changing the existing controllers and business logic. The different development teams welcome the idea as they can still use Spring Boot to develop or maintain their applications without knowing the light-4j middleware injections as the DevOps team handles it in the pipeline.
The customer realizes the performance difference between Light-4j and Spring Boot as they have compared both with their typical applications. While we are working on the integration in light-spring-boot project, we can easily inject Light-4j handlers to the Spring Boot application in the same process. So we did a simple performance test to figure out what is the difference between the Light-4j implementation vs. Spring Boot controller.
If you want to watch a video walk through.
We first generated a Spring Boot application with https://start.spring.io/ with Web dependency with Spring Boot 2.1.3 version. Once the project is downloaded to the local, we switch the default Tomcat embedded server to Undertow
We have updated the pom.xml to exclude the Tomcat server and added Undertow to the dependency.
As you can see, we have added a customizer to handle the /light-4j with an Undertow HttpHandler, and Spring Boot still handles other paths. Light-4j handler is the same with externalized configuration and other enterprise-level features. When you are using light-spring-boot, this injection will be done transparently with the pom.xml dependency and Spring @component scanning.
Start the Server
To build the server, run the following maven command.
mvn clean install
To start the server, run the following command.
java -jar target/performance-0.0.1-SNAPSHOT.jar
Now you can test the two paths by issue the following curl commands. The response will be the same OK.
We are using the wrk to test the perforamnce and a wrk pipeline.lua to generate as many requests as possible. To learn how to use wrk on Linux and Mac, please visit https://doc.networknt.com/tool/wrk-perf/. If you don’t want to create the pipeline.lua file manually, then you can checkout the microservices-framework-benchmark which has the file in the root folder.
Now, let’s test the performance of these two different paths.
In comparing the two results, we can see that the light-4j path achieves about 20 times the throughput of spring-boot path and the latency is 0.93ms vs. 19.89ms. Imagine if you wanted to reach the same throughput and same latency of light-4j path: how many Spring Boot instances would be needed? We have one customer who switched from Spring Boot to Light-4j for their service that collects data from IoT devices and they reduced from 250 medium size AWS VMs to only 4 small size AWS VMs with much better performance.
The test was done on my desktop computer with AMD 2700X and 32GB memory. The source code can be found at Github and you can run it locally.