Java 17 & 21 & Embedded Server Comparisons
As a traditional way most of developers use default embedded server in spring applications. You know what it is. Tomcat! But what about if we want to change the server? How the performance metrics change? Is it worth replacing? And also what happens when using virtual threads?
There are several questions about replacing and results. Let’s dive in deeper and see the benchmark results.
This post is not about
- What is virtual thread?
- What is embedded servers?
- How the servers are working?
- How to change servers?
- How to upgrade from previous versions to Java 21?
Which components compared?
- In this post we compared Java 17 and Java 21 with virtual thread enabled.
- Three embedded servers -> Tomcat, Undertow and Jetty
Test Cases
- 100 iterations with 100 ms interval and 3 times repeat without restarting server.
- 300 API calls totally.
- API call from local environment to remote applications.
- Postman for load tests.
- VisualVM for profiling.
- 3 different applications to create benchmark results.
Let’s get results for all applications.
Application-1
Application-2
Application-3
Now time to get profile results.
Application-1 for Undertow
Application-3 for Jetty
Application-3 for Tomcat
What We Learned?
- Virtual threads must be used in applications. But there is a pitfull. VT are useful when your application has much blocking/external operations like file IO, API call, database queries, elasticsearch, kafka, redis and so on.
- If you want to change server and get more performance, details of server should be examined.
- Full pom.xml based support of Undertow will come with Spring 3.3.x. If want use in 3.2.x versions, you need to add some Bean definitions.
- Tomcat is slow at startups but getting more performance in later iterations.
- Jetty uses more memory than others.
- If want to use Spring Reactive Netty, development costs occurred.
- If your codebase has server specific lines, more detailed tests neccessary.
- You need to read release notes if upgrade Spring from very old versions.
See you in next post.