This repo has the code for modern java.
- Java Installation
- Spring Boot using Virtual Threads
- Install "ab - Apache HTTP server benchmarking tool"
- Benchmarking with "ab - Apache HTTP server benchmarking tool"
- Download the latest java from the below link
- Follow the instructions in the below link to install sdkman in your mac.
- Run the below command to view the different version of supported Java
sdk list java
sdk list java | grep '21'
- Running the below command will install Java 20.
sdk install 21.0.1-tem
- Add the below config in the application.yml
spring:
threads:
virtual:
enabled: true
- Run the below command to check the thread executing the request
curl -i http://localhost:8080/currentThread
curl -i http://localhost:8085/remote/2
curl -i http://localhost:8080/blocking/1
- Follow the instructions in the below link to understand more.
- https://www.inmotionhosting.com/support/edu/wordpress/performance/stress-test-with-apachebench/#test
- We are just going to have 10 tomcat threads to handle our requests
- This is to simplify our testing and comparison will be straightforward with this config
server:
tomcat:
threads:
max: 10
- This command will run ten requests with the concurrency of 10.
- This means all the 10 requests will be run in parallel.
- Since we are passing 2, then it should take approximately 2 seconds to complete.
ab -n 10 -c 10 http://localhost:8080/blocking/2
- This command will run ten requests with the concurrency of 10.
- This means all the 10 requests will be run in parallel.
- Since we are passing 2, then it should take approximately 4 seconds to complete.
ab -n 20 -c 10 http://localhost:8080/blocking/2
- It took 6.055 seconds to complete
- Ideally it should have completed in ~4 seconds, but the benchmarking tool adds a little bit of delay to the overall time to complete.
- It took 6.199 seconds to complete
ab -n 60 -c 20 http://localhost:8080/blocking/2
- Each batch we will send 20 requests and wait for it to complete.
- So in this case, there will be 3 batches of 20 concurrent requests will be sent.
- It took 8.078 seconds to complete
- Ideally it should have completed in ~6 seconds, but the benchmarking tool adds a little bit of delay to the overall time to complete.
- The Average time for each request is ~2 seconds
Percentage of the requests served within a certain time (ms) 50% 2022 66% 2023 75% 2023 80% 2024 90% 2025 95% 2026 98% 2026 99% 2026 100% 2026 (longest request)
- It took 14.179 seconds to complete
- The Average time for each request is ~4 seconds
Percentage of the requests served within a certain time (ms) 50% 4037 66% 4037 75% 4038 80% 4039 90% 4040 95% 4040 98% 4041 99% 4041 100% 4041 (longest request)
- The results above prove virtual-threads are far better in handling blocking IO calls better than the platform threads.