We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Lean Spring Boot Applications for the Cloud by Patrick Baumgartner
Learn essential techniques to optimize Spring Boot apps for cloud deployment: memory settings, startup time, container size, buildpacks, and Java 21 features like virtual threads.
-
Upgrading to newer Java versions (like Java 21) generally improves startup time and performance, with each minor version typically bringing optimizations
-
Using buildpacks instead of Dockerfile is recommended as they:
- Create more secure containers
- Handle dependencies automatically
- Are maintained by the community
- Make container creation easier
-
Spring Boot optimizations:
- Remove unused dependencies and starters
- Make Spring Beans lazy where possible
- Disable unnecessary actuators
- Use AOT (Ahead of Time) processing
- Configure proper memory settings
-
Class Data Sharing (CDS) can improve startup time by:
- Dumping loaded classes into a file
- Loading classes from the dump file on subsequent startups
- Reducing class loading overhead
-
Virtual threads (Java 21+) provide benefits:
- Better performance for web applications
- Improved response times
- More efficient resource usage
- Work well with 1-4 CPU cores
-
JVM runtime options that help:
- Using tiered compilation with stop level 1 for faster startup
- Proper garbage collector selection
- JLink to create custom minimal JVMs
- Configuring proper heap and memory settings
-
Container image size can be reduced by:
-
Using minimal base images (like
tiny
) - Removing unnecessary modules
- Using JLink to create custom JVMs
- Cleaning up dependencies
-
Using minimal base images (like
-
Benchmarking best practices:
- Do warm-up runs
- Test with different CPU/memory configurations
- Measure startup time, throughput and memory usage
- Consider your specific use case
- Don’t trust generic benchmarks
-
OpenJ9 can be a good alternative JVM when memory optimization is important
-
Application packaging recommendations:
- Deploy exploded (unzipped) applications for faster startup
- Use proper configuration locations
- Consider environment-specific optimizations