Cadec2023 Spring
Cadec2023 Spring
SPRING FRAMEWORK 6
MAGNUS LARSSON
• Overview
• Migration
• Native Compile
• Observability
• Summary
OVERVIEW
New Requirements
• Faster startup
- Shorten warmup
APP APP
APP APP APP APP • Less memory #1 #2
#1 #2 #3 #4 JVM JVM
• Scalability APP
JAVA EE #4
- Scale to zero
APP
JVM
JAVA VM • Observability #3
JVM
2000
2023
OVERVIEW Emerging OpenJDK projects:
- CRaC, Amber, Valhalla, Leyden, and Panama
• Overview
• Migration
• Native Compile
• Observability
• Summary
MIGRATION
• Java 17 baseline
• Jakarta EE: Package rename: javax à jakarta
• E.g. JPA: javax.persistence.* à jakarta.persistence.*
• Overview
• Migration
• Native Compile
• Observability
• Summary
NATIVE COMPILE For details on GraalVM Native
Image, see this presentation
• Problem definition from Cadec 2021 - GraalVM Native Image
NATIVE COMPILE
• Is it better now?
NATIVE COMPILE
• Benefits
- Shorter startup times
- No warm-up required
- Less memory required
- Fit for scaling up and down
» Even to zero
NATIVE COMPILE
• Spring AOT
- Creates and inspects an ApplicationContext
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(ProductServiceApplication.class, args);
• Spring AOT
- Generates native configuration
• Spring AOT
- Generates native configuration
- Sample of generated native configuration
https://spring.io/blog/2021/12/09/new-aot-engine-brings-spring-native-to-the-next-level
NATIVE COMPILE
- AOT tests
» Builds a native image and runs tests inside it
./gradlew nativeTest
» Detects missing Spring Beans and Reflection metadata
» Best to run in a CI/CD build pipeline
» Log output
... Starting AOT-processed ProductServiceApplication using Java 17.0.5 …
NATIVE COMPILE
• How?
- Add GraalVM’s build plugin:
plugins {
id 'org.graalvm.buildtools.native' version '0.9.18'
• Ongoing work
- GraalVM - Cross-compilation support
- Paketo buildpacks - Add support for ARM64
- Paketo buildpacks - 2023 Roadmap
- Callista blog post - Docker images on ARM64
TEST: NATIVE COMPILE
Product MongoDB
[microservice]
Review
The microservice landscape [microservice]
MySQL
[System boundary]
TEST: NATIVE COMPILE TIMES
- Not fast enough for a TDD – loop, but sufficient for a CI/CD build pipeline
• Java VM microservices
- Started ProductServiceApplication in 4.988 seconds
- Started ProductCompositeServiceApplication in 5.495 seconds
- Started ReviewServiceApplication in 5.442 seconds
- Started RecommendationServiceApplication in 4.886 seconds
• Java VM microservices
- review-1 239.2MiB
- product-composite-1 216.5MiB
- product-1 212.6MiB
- recommendation-1 215.5MiB Native image app
requires less memory
to startup.
• Native image microservices
- product-1 78.53MiB But what happens over time?
- recommendation-1 78.55MiB
- product-composite-1 55.84MiB
- review-1 70.14MiB
TEST: RESOURCE USAGE OVER TIME
• Test scope
getProduct
Product MongoDB
[microservice]
getCompositeProduct getRecommendations
getReviews
Review
The microservice landscape [microservice]
MySQL
[System boundary]
TEST: RESOURCE USAGE OVER TIME
• Test setup
• 10 000 users
• 2-3 sec getProduct
Product MongoDB
sleep time [microservice]
• ≈ 4000 req/s Gatling
Heap sizes tested 10 000 000
• 2 min warmup • 512 MB products
• 10 min test run • 256 MB
• ≈ 2 160 000 requests
• Test results
Test case No of calls RSS mem CPU time Threads 50 % 95 %
(MB) (min:sec) (ms) (ms)
Native, 256 MB 2 159 056 206 20:54 42 2 11
JVM, 256 MB 2 162 800 235 15:43 54 2 5
Native, 512 MB 2 158 443 220 20:23 42 2 9
JVM, 512 MB 2 163 090 347 15:52 54 2 5
NATIVE COMPILE
• Summary
- Concerns from Cadec 2021 mitigated with Spring Boot 3
• Overview
• Migration
• Native Compile
• Observability
• Summary
?
OBSERVABILITY
APP APP
#1 #2
JVM JVM
APP
#4
APP
#3 JVM
JVM
OBSERVABILITY
APP APP APP
#1 #2 #3
• Observability = Logging + Tracing + Metrics WHAT HAPPENED?
OBSERVABILITY
APP APP APP
#1 #2 #3
• Observability = Logging + Tracing + Metrics PROCESSING TIME?
OBSERVABILITY
APP APP APP
#1 #2 #3
• Observability = Logging + Tracing + Metrics RESOURCE USAGE?
OBSERVABILITY
Report to a Zipkin
» Support for alternative Tracer Implementations compatible tracer
getProduct
Product MongoDB
[microservice]
getCompositeProduct getReviews
getRecommendations
Recommendation
The microservice landscape [microservice]
MongoDB
[System boundary]
DEMO: OBSERVABILITY
getCompositeProduct getReviews
LOGS
TRACES
METRICS
DEMO: OBSERVABILITY
CONTEXT NAME
CONTEXT KEY VALUE
DEMO: OBSERVABILITY
AGENDA
• Overview
• Migration
• Native Compile
• Observability
• Summary
SUMMARY
• Migration
- Upgrade to Java 17 and jakarta package names
- Remove deprecated code
• Native Compile
- Use if start-up time is important
- Test and build native images in CI/CD build pipeline
- Reduce startup times running Java VM in AOT-mode
• Observability
- Built-in auto-configuration for tracing
- One interface, Observation, to abstract them all
- One dashboard to observe them all
QUESTIONS?
LEGACY WARNING
BASED ON
[email protected]
SPRING BOOT 2
MAGNUSLARSSONCALLISTA
QUESTIONS?
3.0
Mid-year 2023
(hopefully…)
THIRD
[email protected]
MAGNUSLARSSONCALLISTA