Project Loom with Spring boot: performance tests
4 min readDec 3, 2022
--
Today I would like to test if Project Loom is ready to replace Spring WebFlux(the most popular efficient reactive framework) for writing high-throughput concurrent applications
Problems of Reactive/Non-blocking services
WebFlux is great, the performance is fantastic, but:
- Functional code is difficult
- Difficult to debug
- Bad stack trace
- Clients/libs should be async/reactive as well
A few facts about Project Loom:
- Preview feature since Java 19, implementation was started in 2017
- Virtual threads: lightweight threads that dramatically reduce the effort of writing, maintaining, and observing applications.
- Can create millions of virtual threads
- Context switching is fast
- Code changes are minimum
- The virtual thread stack is stored in JVM heap
Looks like Project Loom can solve all main problems of Reactive/Non-blocking code. But what about performance?
Test scenario
We are going to test the performance of the service which just proxies the request to one more service that replays with the expected 500ms delay.
The all source code is here
We are going to test 3 implementations:
- Spring Boot (Tomcat)+Project Loom
- Spring Webflux
- Spring Webflux + Project Loom
Hardware:
- All tests will be processed in AWS
- Our service uses t2.micro node (1 CPU, 1 GB)
- Third-party service is using t2.medium node (2 CPU, 4GB)
- Load is made from external one more EC2
Tomcat + Loom implementation
Customization of Spring Boot with Tomcat application to support Project Loom:
@Configuration
public class Config {
@Bean
AsyncTaskExecutor applicationTaskExecutor() {
// enable async servlet support…