Hey, I am Sébastien Deleuze, I work at VMware as a Spring Framework committer. Today, I would like to talk about the path towards Spring Boot native applications.
GraalVM is a project started several years ago by Oracle, it allows among other things to perform ahead-of-time compilation of a Java or Kotlin application, in order to generate a native executable that can run on its own without the need for a Java virtual machine. Such native executable can then be used to create a lightweight container image.
There are two main benefits in doing that: instant startup with peak performance available immediately, and lower memory consumption
Project Leyden, recently announced by Oracle, will introduce this kind of native ahead-of-time compilation to the Java platform, and to the JDK.
While those new capabilities are exciting, we need to keep in mind that they offer different trade-offs compared to the JVM.
While native executables really shine on startup time and runtime memory footprint, they offer lower throughput and higher latency because they use a more basic garbage collector and can’t optimize hot paths during runtime, as the JVM can. Compilation takes much longer and consumes more resources. The platform is also less mature, even if it evolves and improves quickly.
So let’s talk about the current status of Spring support for native applications.
Spring and GraalVM teams have been collaborating intensively to make it possible to run Spring Boot native applications.
Here is a quote from Thomas Wuerthinger, the GraalVM founder and project lead, who said:
“We are excited about the great partnership between the Spring and GraalVM engineering teams to support native ahead-of-time compilation for millions of Spring Boot applications. This is a game changer enabling low memory footprint and instant startup for these workloads.”I would like to thank Thomas and the whole GraalVM team for the huge progresses we have made together.
As a result, most of the GraalVM bug fixes and improvements required to run Spring Boot native applications have already been done.
It is currently possible to compile Spring Boot applications to native executables thanks to the incubating spring-graalvm-native project:
- We have just released the 0.8 milestone
- The compatibility is (for now) limited to a subset of Spring Boot starters
- We observe between 3x and 5x reduction of the memory footprint compared to the JVM
- It is available for you to try with your application and start to flush out any issues early
Notice we are also contributing GraalVM native related improvements to other open source projects where we are involved like Tomcat.
Upcoming Spring Boot 2.4 release, based on Spring Framework 5.3, already integrates improvements originally incubated in spring-graalvm-native.
We have also incubating support for Spring Boot native applications in Paketo buildpacks, since they enable to build lightweight containers.
On this slide, you can see that we are using a minimal Ubuntu-based image, consisting of only seven packages optimized for security and size.
I am now going to show you a quick demo of the famous Petclinic sample, compiled to a Spring Boot native application, and deployed as a container.
Let’s now talk about the next steps ...
The Spring team is on a journey to optimize the cost of running Spring Boot applications by supporting native ahead-of-time compilation, in order to achieve scale-to-zero capabilities and reduced memory consumption.
Combined with Kubernetes-based platforms like KNative, that means you can run your regular web applications in a serverless fashion, and only pay when your application is used.
There has been a hidden gem in Spring Framework since 5.0: functional bean registration, which allows to register beans using lambdas.
With this mechanism and some related changes we are working on, it is possible to achieve out-of-the-box Spring Boot native application support with a 5x memory footprint reduction without changing the Spring Boot programming model that you all love and use.
Spring Boot 3, based on Spring Framework 6, is expected to provide first-class support for native applications, to give you more options when it comes to deploying your Spring Boot applications as containers on Kubernetes.
We intend to adapt Spring to GraalVM native as well as project Leyden. The related changes will optimize the footprint of Spring Boot applications on the JVM as well.
What is unique about our effort is that we not only target new Spring Boot applications, but also the millions of existing ones.
Thanks for your attention.