Slide 1

Slide 1 text

Moritz Halbritter Spring Engineering Team @ Broadcom Greening Java - Effiziente Deployments mit Spring Boot Copyright © 2024 Broadcom, Inc. or its affiliates.

Slide 2

Slide 2 text

Agenda Motivation Project CraC CDS / AOT Cache GraalVM native-image Q&A

Slide 3

Slide 3 text

Why do we care about runtime efficiency? Cheaper hosting Sustainability Optimized containers

Slide 4

Slide 4 text

Project CRaC

Slide 5

Slide 5 text

“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

Slide 6

Slide 6 text

Training run Snapshot Deployment run Startup Fast startup even on cheap servers or scale to zero Warmup Peak performance immediately

Slide 7

Slide 7 text

● java -XX:CRaCCheckpointTo=snapshot.crac -jar app.jar ● jps # to find the process id ● jmcd JDK.checkpoint ● java -XX:CRaCRestoreFrom=snapshot.crac

Slide 8

Slide 8 text

SECRETS!

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

CDS / AOT Cache

Slide 11

Slide 11 text

We’re going to take a look at 3 variants CDS AOT Cache AOT Cache with profiling and code compilation

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

java -Dspring.context.exit=onRefresh Start Exit on Refresh non-lazy singletons instantiated afterPropertiesSet invoked Lifecycle start invoked ContextRefreshedEvent published Running

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

CDS

Slide 16

Slide 16 text

Requirements for Spring Boot with CDS Java 17+ Spring Boot 3.3+

Slide 17

Slide 17 text

CDS Demo

Slide 18

Slide 18 text

Spring Petclinic startup time (seconds) 1.2x 1.9x 2.2x

Slide 19

Slide 19 text

Spring Petclinic RSS memory (MB) 3.3% 19.1% 19.6%

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Training run configuration for your database https://github.com/spring-projects/spring-lifecycle-smoke-tests/tree/main#training-run-configuration

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

AOT Cache

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

AOT Cache Demo

Slide 28

Slide 28 text

Spring Petclinic startup time (seconds) 1.2x 1.9x 2.2x 2.6x

Slide 29

Slide 29 text

Spring Petclinic RSS memory (MB) 3.3% 19.1% 19.1% 22.7%

Slide 30

Slide 30 text

Project Leyden

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Project Leyden Demo

Slide 35

Slide 35 text

Spring Petclinic startup time (seconds) 1.2x 2.2x 3.9x 4.4x

Slide 36

Slide 36 text

JVM warmup compared Time elapsed (s) Requests / s

Slide 37

Slide 37 text

GraalVM native-image

Slide 38

Slide 38 text

“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/

Slide 39

Slide 39 text

native-image Demo

Slide 40

Slide 40 text

Comparison Matrix

Slide 41

Slide 41 text

Comparing GraalVM, Project CRaC and AOT Cache

Slide 42

Slide 42 text

Q&A

Slide 43

Slide 43 text

Thank you mhalbritter.github.io Copyright © 2024 Broadcom, Inc. or its affiliates.