by João Esperancinha
2024/11/19
Start from the package!
Spring CDS Class Data Sharing
About me
João Esperancinha he/him/his
● Java
● Kotlin
● Groovy
● Scala
● Software Engineer 10+ years
● JESPROTECH YouTube Channel
Kong Champion/Java Professional/Spring Professional
Today’s agenda
● The problem
● The solutions
● What is Class Data Sharing
● How the JVM works with CDS
● A bit of history
● Benefits of CDS in Spring Applications
● Configuring CDS in Spring Projects
● Real-world use cases and benchmarks
● Best Practices
What problems do we face today?
● Startup times!
● Auto-Scaling
● Deploy Times
● Constant Initializations
The Solution?
Spring CDS!
Class Data Sharing
Other solutions available
● GraalVM
● CRaC
● CDS
When and how CDS started?
● Java 1.5
Yes! That long time ago!
Franz
Ferdinand
● 2004
Green Day
American
Idiot
Eternal
Sunshine
of
a spotless
mind
The day
after
tomorrow
● 2018 – AppCDS (Application Class Data Sharing)
● 2021 – Dynamic CDS Archiving
Billie Eilish
Happier
Than Ever
Ariana
Grande
Sweetener
Taylor
Swift
Red
(Taylor's
Version)
Florence
and the
machine
High as
Hope
The Guilty
Red
Sparrow
What is Class Data Sharing?
CDS is a JVM feature that
allows sharing of preloaded
class metadata among
multiple JVMs, reducing
startup time and memory
footprint.
Class metadata is stored in a
shared archive file, a .jsa file
Enabled by default
Types of CDS
Shared Archive with default
JDK Classes
App CDS where custom classes are
used in specific applications
JVM and CDS Performance
● JVM skips loading classes into memory by reusing preloaded data.
● Reduces the Just-In-Time (JIT) compilation overhead during startup.
● Multiple JVMs can share the same metadata archive.
● Decreases memory usage on systems running multiple JVM processes.
● Faster context and dependency injection processing.
Benefits of CDS in Spring Applications
● Faster application startup for microservices and serverless functions.
● Lower memory usage on resource-constrained environments like
Kubernetes.
● Supports efficient scaling of Spring applications with multiple JVM instances
Configuring CDS in Spring Projects
● Default for JDK classes in Java 12+. (2019)
● Use java -Xshare:on to explicitly enable.
● Use -XX:DumpLoadedClassList to generate a class list.
● Use -XX:SharedArchiveFile=<path> to store or load the shared archive.
Billie Eilish
When We
All Fall
Asleep,
Where Do
We Go?
Harry
Styles
Fine Line
The
Good Liar
Demo!
Property Java Application Spring Application
Startup wo/CDS (ms) 23.11 930
Startup wo/CDS unpacked (ms) NA 808
Startup w/CDS (ms) 29.27 430
Startup w/CDS + AOT (ms) NA 297
Committed memory wo/CDS 12.952 12.952
Committed memory wo/CDS unpacked(Mb) NA 12.952
Committed memory w/CDS (Mb) 8.080 55.640
Committed memory w/CDS + AOT (Mb) NA 53.880
Total classes wo/CDS 815 9209
Total classes wo/CDS unpacked NA 9096
Total classes w/CDS 818 8975
Total classes w/CDS + AOT NA 8704
Problem solved!
● Memory usage of Native Class Shared Space changes
● Faster application startup for microservices and serverless functions.
● Total memory of application usage can decrease with CDS
● Easy to use especially with Project Leyden and Buildpacks
● Kubernetes:
○ Reduce cold-start time for Spring
Boot applications in containers.
● Serverless:
○ Improve function invocation
times in environments like AWS
Lambda.
● Microservices:
○ Optimize startup for clustered
services in distributed systems.
Real-World Use Cases
Best Practices
● Keep Archives Updated:
○ Recreate AppCDS archives after
significant codebase changes.
● Containerized Applications:
○ Embed the shared archive in
container images for portability.
Conclusion
● Key Takeaways:
○ CDS is a powerful tool to enhance JVM-based
application performance.
○ Spring applications can significantly benefit
from faster startups and lower memory usage.
○ Implementing AppCDS is straightforward and
highly impactful.
Questions?
I am an inquisitive
cat
Resources
● https://blogs.vmware.com/tanzu/revolutionize-jvm-startup-times/
● https://spring.io/blog/2024/08/29/spring-boot-cds-support-and-project-leyden
-anticipation
● https://docs.spring.io/spring-framework/reference/integration/cds.html
● https://halilural5.medium.com/incredible-performance-increase-in-spring-bo
ot-applications-with-cds-5022ff81948f
Source code
https://github.com/jesperancinha/jeorg-spring-master-test-drives/
About me
● Homepage - https://joaofilipesabinoesperancinha.nl
● Threads - https://www.threads.net/@joaofisaes
● LinkedIn - https://www.linkedin.com/in/joaoesperancinha/
● YouTube - https://www.youtube.com/@jesprotech
● Bluesky - https://bsky.app/profile/jesperancinha.bsky.social
● Mastodon - https://masto.ai/@jesperancinha
● GitHub - https://github.com/jesperancinha
● Hackernoon - https://hackernoon.com/u/jesperancinha
● DevTO - https://dev.to/jofisaes
● Medium - https://medium.com/@jofisaes
Thank you!

Start from the Package in Spring CDS - Basic course

  • 1.
    by João Esperancinha 2024/11/19 Startfrom the package! Spring CDS Class Data Sharing
  • 2.
    About me João Esperancinhahe/him/his ● Java ● Kotlin ● Groovy ● Scala ● Software Engineer 10+ years ● JESPROTECH YouTube Channel Kong Champion/Java Professional/Spring Professional
  • 3.
    Today’s agenda ● Theproblem ● The solutions ● What is Class Data Sharing ● How the JVM works with CDS ● A bit of history ● Benefits of CDS in Spring Applications ● Configuring CDS in Spring Projects ● Real-world use cases and benchmarks ● Best Practices
  • 4.
    What problems dowe face today? ● Startup times! ● Auto-Scaling ● Deploy Times ● Constant Initializations
  • 5.
  • 6.
    Other solutions available ●GraalVM ● CRaC ● CDS
  • 7.
    When and howCDS started? ● Java 1.5 Yes! That long time ago! Franz Ferdinand ● 2004 Green Day American Idiot Eternal Sunshine of a spotless mind The day after tomorrow ● 2018 – AppCDS (Application Class Data Sharing) ● 2021 – Dynamic CDS Archiving Billie Eilish Happier Than Ever Ariana Grande Sweetener Taylor Swift Red (Taylor's Version) Florence and the machine High as Hope The Guilty Red Sparrow
  • 8.
    What is ClassData Sharing? CDS is a JVM feature that allows sharing of preloaded class metadata among multiple JVMs, reducing startup time and memory footprint. Class metadata is stored in a shared archive file, a .jsa file Enabled by default
  • 9.
    Types of CDS SharedArchive with default JDK Classes App CDS where custom classes are used in specific applications
  • 10.
    JVM and CDSPerformance ● JVM skips loading classes into memory by reusing preloaded data. ● Reduces the Just-In-Time (JIT) compilation overhead during startup. ● Multiple JVMs can share the same metadata archive. ● Decreases memory usage on systems running multiple JVM processes. ● Faster context and dependency injection processing.
  • 11.
    Benefits of CDSin Spring Applications ● Faster application startup for microservices and serverless functions. ● Lower memory usage on resource-constrained environments like Kubernetes. ● Supports efficient scaling of Spring applications with multiple JVM instances
  • 12.
    Configuring CDS inSpring Projects ● Default for JDK classes in Java 12+. (2019) ● Use java -Xshare:on to explicitly enable. ● Use -XX:DumpLoadedClassList to generate a class list. ● Use -XX:SharedArchiveFile=<path> to store or load the shared archive. Billie Eilish When We All Fall Asleep, Where Do We Go? Harry Styles Fine Line The Good Liar
  • 13.
    Demo! Property Java ApplicationSpring Application Startup wo/CDS (ms) 23.11 930 Startup wo/CDS unpacked (ms) NA 808 Startup w/CDS (ms) 29.27 430 Startup w/CDS + AOT (ms) NA 297 Committed memory wo/CDS 12.952 12.952 Committed memory wo/CDS unpacked(Mb) NA 12.952 Committed memory w/CDS (Mb) 8.080 55.640 Committed memory w/CDS + AOT (Mb) NA 53.880 Total classes wo/CDS 815 9209 Total classes wo/CDS unpacked NA 9096 Total classes w/CDS 818 8975 Total classes w/CDS + AOT NA 8704
  • 14.
    Problem solved! ● Memoryusage of Native Class Shared Space changes ● Faster application startup for microservices and serverless functions. ● Total memory of application usage can decrease with CDS ● Easy to use especially with Project Leyden and Buildpacks
  • 15.
    ● Kubernetes: ○ Reducecold-start time for Spring Boot applications in containers. ● Serverless: ○ Improve function invocation times in environments like AWS Lambda. ● Microservices: ○ Optimize startup for clustered services in distributed systems. Real-World Use Cases
  • 16.
    Best Practices ● KeepArchives Updated: ○ Recreate AppCDS archives after significant codebase changes. ● Containerized Applications: ○ Embed the shared archive in container images for portability.
  • 17.
    Conclusion ● Key Takeaways: ○CDS is a powerful tool to enhance JVM-based application performance. ○ Spring applications can significantly benefit from faster startups and lower memory usage. ○ Implementing AppCDS is straightforward and highly impactful.
  • 18.
    Questions? I am aninquisitive cat
  • 19.
    Resources ● https://blogs.vmware.com/tanzu/revolutionize-jvm-startup-times/ ● https://spring.io/blog/2024/08/29/spring-boot-cds-support-and-project-leyden -anticipation ●https://docs.spring.io/spring-framework/reference/integration/cds.html ● https://halilural5.medium.com/incredible-performance-increase-in-spring-bo ot-applications-with-cds-5022ff81948f
  • 20.
  • 21.
    About me ● Homepage- https://joaofilipesabinoesperancinha.nl ● Threads - https://www.threads.net/@joaofisaes ● LinkedIn - https://www.linkedin.com/in/joaoesperancinha/ ● YouTube - https://www.youtube.com/@jesprotech ● Bluesky - https://bsky.app/profile/jesperancinha.bsky.social ● Mastodon - https://masto.ai/@jesperancinha ● GitHub - https://github.com/jesperancinha ● Hackernoon - https://hackernoon.com/u/jesperancinha ● DevTO - https://dev.to/jofisaes ● Medium - https://medium.com/@jofisaes
  • 22.