Slide 1

Slide 1 text

JCON 2023 Moritz Halbritter / Spring Boot @ VMware https://mhalbritter.github.io/ From Spring Native to Spring Boot 3 Copyright © 2020 VMware, Inc. or its affiliates.

Slide 2

Slide 2 text

What’s a GraalVM native-image? Java Bytecode Native executable binary There’s a lot more stuff in it!

Slide 3

Slide 3 text

Why compile to native?

Slide 4

Slide 4 text

Why compile to native? Instant startup Milliseconds for native instead of seconds for the JVM No warmup Peak performance available immediately Low resource usage Lower memory footprint and no JIT compilation Reduced attack surface Closed world of dependencies with explicit reflection and serialization Compact packaging Smaller container easier to deploy

Slide 5

Slide 5 text

Use cases for native images JVM likely better Assess Recommended Low memory and CPU Scale to zero Function as a Service Microservices Backoffices Container image distribution Very frequent deployment High traffic website Unsupported dependency Big monolithic application Huge memory and CPU Agent-based observability Kubernetes

Slide 6

Slide 6 text

A little bit of history 2021-03-11

Slide 7

Slide 7 text

It got official with Spring Boot 3 Spring Boot 3 introduces official support for compiling applications to native executables and supersedes Spring Native

Slide 8

Slide 8 text

Demo: How to get started

Slide 9

Slide 9 text

GraalVM 22.3 and 23.0 is supported ● GraalVM versions support policy: ● GraalVM 22.3 ● GraalVM 23.0 (... for JDK 17 / 20), released 2023-06-13 ○ Better performance ○ Compatibility improvements ○ Bundles ○ Experimental JMX support ○ Previous EE only features releases as “Oracle GraalVM” ■ G1, PGO, Compressed Object headers and pointers, …

Slide 10

Slide 10 text

VMware Spring Runtime adds end-to-end native support ● VMware and Bellsoft now have a support agreement that provides end-to-end native support to VMware Spring Runtime customers ● Bellsoft Liberica NIK (based on the GraalVM Community Edition) and Liberica JDK are used in native Buildpacks ● Consistent with the JVM side where Liberica JDK is used ● Fixes and enhancements will be contributed upstream to GraalVM

Slide 11

Slide 11 text

Library support based on GraalVM reachability metadata ● Native image configuration for JVM libraries ● Initially a GraalVM and Spring driven effort ● Guidelines on how to craft native configuration ○ Runtime initialization by default ○ No build-time initialization ○ Reachability based native configuration ○ Mandatory native testing

Slide 12

Slide 12 text

Zero substitutions Fix the upstream libraries instead

Slide 13

Slide 13 text

No explicit build time initialization Only runtime initialization

Slide 14

Slide 14 text

RuntimeHints API No more fiddling with JSON

Slide 15

Slide 15 text

Demo: Migrating PetClinic

Slide 16

Slide 16 text

A peek under the covers

Slide 17

Slide 17 text

Spring Boot 3 AOT and native support overview Native Build Tools GraalVM Spring Boot 3 AOT and native integration in Boot plugins AOT transformation engine Spring Framework 6 Paketo Buildpacks Native Buildpack AOT plugins Native documentation Spring portfolio (Data, Security, etc.) AOT transformations Native hints native-image compiler Reachability metadata repository

Slide 18

Slide 18 text

Native compilation with Spring App compiled Compiled sources Resources AOT is done Compiled sources Resources AOT sources Native image config Compiled AOT sources Native binary Native application :generateAotSources + :aotClasses :nativeCompile Application Jar AOT optimized app :bootJar AOT classes

Slide 19

Slide 19 text

Demo: A peek under the covers

Slide 20

Slide 20 text

Conditions (e.g. Profiles) are possible

Slide 21

Slide 21 text

Two way of building native executables Native Build Tools ● Started as a collaboration between Spring and GraalVM team, and recently the Micronaut team has joined ● Application compilation and testing support ● Requires local GraalVM native-image compiler ● Produces a native executable ○ Linux (x64, ARM) ○ MacOS (x64, ARM) ○ Windows (x64)

Slide 22

Slide 22 text

Two way of building native executables Buildpacks ● Container based native builds based on Buildpacks ● Application compilation support ● Requires Docker but no local GraalVM installation ● Produces a Linux container image ○ x64 is supported ○ Official ARM support work in progress

Slide 23

Slide 23 text

Data points

Slide 24

Slide 24 text

Startup time (GraalVM 22.3)

Slide 25

Slide 25 text

Scale to zero your Cloud deployments

Slide 26

Slide 26 text

Performance (GraalVM 22.3)

Slide 27

Slide 27 text

Simple webapp memory consumption (GraalVM 22.3)

Slide 28

Slide 28 text

Petclinic container size (MiB, GraalVM 22.3)

Slide 29

Slide 29 text

GraalVM 23.0 https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5

Slide 30

Slide 30 text

GraalVM 23.0 https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5

Slide 31

Slide 31 text

GraalVM 23.0 https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5

Slide 32

Slide 32 text

GraalVM 23.0 https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5

Slide 33

Slide 33 text

Observability

Slide 34

Slide 34 text

Two ways of adding observability Using JVM agents ● Some agents work, when using the agent at build time ○ Fixed configuration! Using Micrometer Tracing ● First class support in (native) Spring

Slide 35

Slide 35 text

Actuator is working in a native image > curlie :8080/actuator/prometheus process_cpu_usage 0.0 process_files_max_files 524288.0 executor_queued_tasks{name="applicationTaskExecutor",} 0.0 jvm_classes_unloaded_classes_total 0.0 tomcat_sessions_active_current_sessions 0.0 tomcat_sessions_created_sessions_total 0.0 executor_pool_core_threads{name="applicationTaskExecutor",} 8.0 process_uptime_seconds 43.158 system_load_average_1m 4.39404296875 jvm_threads_peak_threads 18.0 disk_free_bytes{path="/home/moe/Downloads/demo/.",} 1.24508004352E11 executor_pool_size_threads{name="applicationTaskExecutor",} 0.0 tomcat_sessions_rejected_sessions_total 0.0 tomcat_sessions_expired_sessions_total 0.0 executor_pool_max_threads{name="applicationTaskExecutor",} 2.147483647E9

Slide 36

Slide 36 text

And tracing, too

Slide 37

Slide 37 text

The Future Spring continues to follow and shape the GraalVM native image evolution

Slide 38

Slide 38 text

Thank you! © 2020 Spring. A VMware-backed project. https://mhalbritter.github.io/