Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CDS - Class Data Sharing with Spring Tutorial

CDS - Class Data Sharing with Spring Tutorial

In this video we are discussing the possible benefits and caveats of using Spring CDS. The video has an introduction, goes through some myths and misconceptions about Spring CDS and then it moves on to a fully fledged, no boundaries DEMO about using CDS via the command line and purely on the bases of commands and switches. Just to make it clear, the video purposely ignores the usage of maven, build packs and project Leyden, becaus they are not specifically a part of CDS itself. The video is intented to educate on the intricasies of using CDS from a startup-time perspective. With CDS we can also save memory in applicable cases, but this video isn't about memory. It is more about finding out how and if CDS can help us starting applciations faster and going through some hypothetical and practical examples of it very quickly. Hope you enjoy the video and have a good one everyone!

More Decks by João Filipe Sabino Esperancinha

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. What problems do we face today? • Startup times! •

    Auto-Scaling • Deploy Times • Constant Initializations
  4. 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
  5. 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
  6. Types of CDS Shared Archive with default JDK Classes App

    CDS where custom classes are used in specific applications
  7. 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.
  8. 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
  9. 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
  10. 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
  11. 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
  12. • 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
  13. Best Practices • Keep Archives Updated: ◦ Recreate AppCDS archives

    after significant codebase changes. • Containerized Applications: ◦ Embed the shared archive in container images for portability.
  14. 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.
  15. 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