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

Greening Java - Effiziente Deployments mit Spri...

Avatar for Moritz Halbritter Moritz Halbritter
June 11, 2025
80

Greening Java - Effiziente Deployments mit Spring Boot

Meine These – 99% aller Spring Boot Anwendungen werden nicht optimal deployt. Es gibt diverse Methoden, um die Startup-Performance von Spring Boot zu verbessern: exploded JARs, Project CRaC, CDS, Project Leyden, GraalVM’s Native Image und noch mehr. Die Frage ist nur: Wann nimmt man was? Was sind die Vorteile, was die Nachteile? Und lohnt sich der ganze Aufwand überhaupt? In diesem Talk stellt Moritz verschiedene Techniken vor, die zu Scale to Zero führen können. Damit ihr eure Anwendungen optimal und ressourcenschonend deployen könnt – für eine grünere Zukunft und nebenbei mehr Geld in eurem Geldbeutel. Klingt nach einem Win-Win.

Avatar for Moritz Halbritter

Moritz Halbritter

June 11, 2025
Tweet

Transcript

  1. Moritz Halbritter Spring Engineering Team @ Broadcom Greening Java -

    Effiziente Deployments mit Spring Boot Copyright © 2024 Broadcom, Inc. or its affiliates.
  2. “Coordinated Restore at Checkpoint is an OpenJDK feature that provides

    a fast start and immediate performance for Java applications.” https://wiki.openjdk.org/display/crac/Main
  3. Training run Snapshot Deployment run Startup Fast startup even on

    cheap servers or scale to zero Warmup Peak performance immediately
  4. • java -XX:CRaCCheckpointTo=snapshot.crac -jar app.jar • jps # to find

    the process id • jmcd <pid> JDK.checkpoint • java -XX:CRaCRestoreFrom=snapshot.crac
  5. Project CraC requirements OS Only Linux is supported, and CRIU

    must be available. JVM A CRaC-enabled JVM must be used. No open handles All file descriptors (files, sockets, etc.) must be closed while checkpointing and restored afterwards. Training run When/how to do the training run? Application may try to connect to remote services like databases. https://docs.spring.io/spring-framework/reference/integration/checkpoint-restore.html
  6. We’re going to take a look at 3 variants CDS

    AOT Cache AOT Cache with profiling and code compilation
  7. Training run Cache Deployment run Startup Fast startup even on

    cheap servers or scale to zero Memory More applications on less servers Warmup Peak performance immediately
  8. java -Dspring.context.exit=onRefresh Start Exit on Refresh non-lazy singletons instantiated afterPropertiesSet

    invoked Lifecycle start invoked ContextRefreshedEvent published Running
  9. Self-extracting executable JARs my-app.jar 35 MB java -Djarmode=tools -jar my-app.jar

    extract my-app/ lib/ my-app.jar 0.7 MB Library jars as files for optimized class loading Application classes + manifest file defining the classpath java -jar my-app/my-app.jar
  10. CDS

  11. CDS requirements JVM The same JVM must be used. Classpath

    Must be specified as a list of jars. No directories, no wildcard, no nested jars. Deployment classpath must be a superset of the training one. Files The timestamps of the jars must be preserved. Training run When/how to do the training run? Application may try to connect to remote services like databases. https://docs.spring.io/spring-framework/reference/integration/cds.html
  12. CDS support in Buildpacks Spring Boot Buildpacks + mvn spring-boot:build-image

    gradle bootBuildImage = The CDS training run is performed transparently when building the container image, ensuring that the same JVM is used
  13. AOT Cache and Spring AOT are different - but combine

    well AOT Cache JVM feature developed via Project Leyden to improve the efficiency of the JVM. It supersedes CDS. Spring AOT Spring feature mandatory for GraalVM native images support. Can also be used on the JVM to speed up the startup process and lower the memory consumption. Precomputes the bean arrangement for specific Spring profiles [1]. [1] https://github.com/sdeleuze/demo-profile-aot
  14. Requirements for Spring Boot with AOT Cache Java 24+ Spring

    Boot 3.3+ https://docs.spring.io/spring-framework/reference/7.0/integration/aot-cache.html
  15. “Native Image is a technology to compile Java code ahead-of-time

    to a binary—a native executable. A native executable includes only the code required at run time, that is the application classes, standard-library classes, the language runtime, and statically-linked native code from the JDK.” https://www.graalvm.org/latest/reference-manual/native-image/
  16. Q&A