©2021 VMware, Inc.
Going Serverless
using the Spring Framework ecosystem
Timo Salm
Senior Specialist Solution Engineer VMware Tanzu
September 2021
©2021 VMware, Inc.
Agenda
2
▪ About me
▪ What is Serverless?
▪ Going Serverless with your Spring Boot applications
©2021 VMware, Inc. 3
About me
Timo Salm
Senior SpecialistSolutionEngineer for VMware Tanzu
▪ https://tanzu.vmware.com/
▪ Twitter: @salmto
▪ GitHub: https://github.com/tsalm-pivotal
4
©2021 VMware, Inc.
What Is Serverless?
©2021 VMware, Inc. 5
Serverless doesn’t mean there are no servers, it means you don’t care about them.
Serverless can be group into two areas:
▪ Backend as a Service (BaaS) Replacing server-side, self-managed components with off-the-shelf
services
▪ Functions as a Service (FaaS) A new way of building and deploying server-side software, oriented
around deploying individual functions
The key is that with both, you don't have to manageyour own server hosts or server processes and can
focus on business value!
What is Serverless?
©2021 VMware, Inc. 6
A Serverless service …
▪ … does not require managing a long-lived host or application instance
▪ … self auto-scales and auto-provisions, dependent on load
▪ … has implicit high availability
▪ … has performance capabilities defined in terms other than host size/count
▪ … has costs that are based on precise usage, up from and down to zero usage
Key characteristics
What is Serverless?
©2021 VMware, Inc. 7
▪ Shorter lead time
▪ Reduced packaging and deploymentcomplexity
▪ Increased flexibility of scaling
▪ Reduced resource cost
▪ Reduced labor cost
▪ Reduced risk
Why Serverless?
©2021 VMware, Inc. 8
▪ Unpredictable costs
▪ Spinning up machines takes time - from a few seconds to minutes
▪ Most Serverless applications are stateless and the managementof state can be somewhat tricky
▪ Higher latency due to inter-component communication over HTTP APIs and “cold starts”
▪ Problematic with downstream systems that cannot increase their capacity quickly enough
▪ Typically limited in how long each invocation is allowed to run
▪ Multitenancy problems
Part 1/2
Drawbacks / Limitations of Serverless
©2021 VMware, Inc. 9
▪ Debugging is more complicated (a single request can travel between several machines and some of
those machines disappear at times)
▪ Added work is needed to provide tracing and monitoring solutions, which can add complexity and cost
to the project
▪ Security can be more demanding in a serverless environment
▪ Loss of control over
▪ absoluteconfiguration
▪ the performance of Serverless components
▪ issue resolution
▪ security
▪ The difficulty of local testing
▪ Vendor lock-in unless you are using OSS projects like e.g. Knative
Part 2/2
Drawbacks / Limitations of Serverless
©2021 VMware, Inc. 10
An open-source community project which adds components for
deploying, running, and managing applicationson any Kubernetes
in a Serverless way.
What is Knative?
To primary components:
▪ Serving:Supports deploying and serving of serverless applications and functions
▪ Eventing: Enables developers to use an event-driven architecture with serverless
applications
©2021 VMware, Inc. 11
Summary
The primary drivers for the adoption of Serverless are:
Developer
productivity
Platform elasticity Cost savings
12
©2021 VMware, Inc.
Going Serverless
with your Spring Boot applications
13
©2021 VMware, Inc.
Demo
Running a Spring Boot application on Knative
©2021 VMware, Inc. 16
Unleash the full potential of Serverless for our application
Faster startup time Lower resource
consumption
(memory, CPU)
More cost savings
©2021 VMware, Inc. 17
Interpretation vs Compilation
Just-in-Time vs Ahead-of-Time
.java
Java Class
JIT @ Compile Time
Compiler
.class
Bytecode
JIT @ JVM Runtime
JIT
Compiler
Native
Code
.java
Java Class
AOT @ Compile Time
Compiler
.class
Bytecode
AOT @ Native Runtime
.jar
Archive
Executed
Native
Executable
Executed
.jar
Archive
©2021 VMware, Inc. 18
What are Native Images?
Smaller, faster and lower resource consumption
▪ Standaloneexecutableof ahead-of-time compiled Javacode
▪ Includes the applicationclasses, classes from its dependencies, runtime library classes, and statically linked
native code from JDK
▪ Runs without the need of a JVM, necessary componentsare includedin a runtime system, called“Substrate VM”
▪ Specific to the OS and machine architecture for which it was compiled
▪ Requires fewer resources than regular Javaapplicationsrunning on a JVM
©2021 VMware, Inc. 19
▪ Basic idea: One VM that can execute applications written in Java and other JVM languages while also
providing runtimes for JavaScript, Ruby, Python, and a number of other popular languages
▪ Started by Oracle: https://graalvm.org/
▪ GraalVM’s polyglot capabilities make it possible to mix multiple programming languages in a single
application while eliminating any foreign language call costs
▪ Still in “early adopter” mode, but
matures quickly
A high-performance JDKdistribution
What is GraalVM?
©2021 VMware, Inc. 20
Tradeoffs between JVM and Native Images
©2021 VMware, Inc. 21
▪ A static analysis of your application from the main entry point is performed at build time
▪ The unused parts are removed at build time
▪ Configuration is required for reflection, resources, and dynamic proxies
▪ Classpath is fixed at build time
▪ No class lazy loading: everything shipped in the executables will be loaded in memory on startup
▪ Some code will run at build time
▪ There are some limitations around some aspects of Java applications that are not fully supported
Key differences between JVM and GraalVM native image platform
©2021 VMware, Inc. 23
Spring Native provides incubating support
for compiling Spring applications to lightweight native executables using the
GraalVM native-image compiler.
The goal is to support compilation of existing or new Spring Boot
applications to native executables.
Unchanged.
©2021 VMware, Inc. 24
▪ Choose Spring Boot 2.5.4 as your
project’sparent for the Spring
Native0.10.3 release
▪ Java8 and Java11 supported for
NativeImages at this time in the
GraalVM
Get started with Spring Native
Create a new project on start.spring.io or use an existing one
©2021 VMware, Inc. 25
▪ Use Spring Boot 2.5.4 as your
project’sparent for the latest Spring
Nativerelease
▪ Add a dependencyto the latest
Spring Nativelibrary
e.g. spring-native version 0.10.3
▪ Leverage Paketo JavaNativeImage
Buildpack
▪ Configure the Spring Boot Maven
Plugin to build a nativeimage
▪ Add the Spring AOT plugin
Get started with Spring Native
Create a new project on start.spring.io or use an existing one
©2021 VMware, Inc. 26
▪ Add the nativebuild tools plugin
Get started with Spring Native
Create a new project on start.spring.io or use an existing one
©2021 VMware, Inc. 27
Two options to build a native image with Spring Native
Via Cloud-Native-Buildpacks
▪ Configure your build to use the Paketo Buildpacks
▪ Tell the buildpackto produce a native image
▪ The result is a small containerimage with the
compiled nativeexecutable inside
▪ No local GraalVM installationneeded
▪ Super easy to use
▪ Run mvn spring-boot:build-imageto create a
containerwith your application
Via GraalVM native image Mavenplugin
▪ Configure your build to compileto a native
executable
▪ Produces a native executable for the platform you are
running on
▪ Requires GraalVM locallyinstalled
▪ Also super easy to use
▪ Run mvn -Pnative -DskipTests package to buildthe
application.
28
©2021 VMware, Inc.
Demo
Running a Spring Boot application as Native Image
on Knative
©2021 VMware, Inc. 30
Performance expectations
Sample On the JVM Nativeapplication
spring-boot-hello-
world
Build: 19 s
Memory(RSS): 225M
Startup time: 2.367s
Build: 04:21 min +1374%
Memory(RSS): 68M -70%
Startup time: 0.119s -95%
actuator-r2dbc-
webflux
Build: 8s
Memory(RSS): 640M
Startup time: 3.0s
Build: 141s +1700%
Memory(RSS): 86M -87%
Startup time: 0.094s -97%
petclinic-jdbc Build: 9s
Memory(RSS): 417M
Startup time: 2.6s
Build: 194s +2050%
Memory(RSS): 101M -75%
Startup time: 0.158s -94%
©2021 VMware, Inc. 31
Ongoing improvements in reducing footprint
Sample Sep 2019 Mar 2021
commandlinerunner Build: 90s
Exec. size: 48M
Memory(RSS): 29M
Build: 50s
Exec. size: 21M
Memory(RSS): 22M
webflux-netty Build: 193s
Exec. size: 81M
Memory(RSS): 95M
Build: 79s
Exec. size: 47M
Memory(RSS): 48M
webmvc-tomcat Build: 203s
Exec size: 105M
Memory(RSS): 70M
Build: 67s
Exec. size: 45M
Memory(RSS): 51M
©2021 VMware, Inc. 32
▪ Delegate Native Imagebuilding to the CI/CD pipeline, leveraging Spring Native and Paketo
Buildpacks
▪ Unchanged Developer UX in your IDE, with the same JVM
Use JVM locally, delegate Native Builds to CI/CD…
Can I keep the great Spring UX when going Native?
©2021 VMware, Inc. 33
Spring Boot 3, based on Spring Framework 6, is expected to provide first-
class support for native application deployment, as well as an optimized
footprint on the JVM.
The road ahead
©2021 VMware, Inc. 34
▪ Documentation: https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/
▪ Spring Native project on Github: https://github.com/spring-projects-experimental/spring-native
▪ Workshop by my awesome colleague Dan Dobrin: https://github.com/ddobrin/native-spring-on-k8s-
with-graalvm-workshop
Resources
©2021 VMware, Inc.
Thank You

More Related Content

PDF
Spring Data JDBC: Beyond the Obvious
PDF
Spring Native and Spring AOT
PDF
Spring Boot Loves K8s
PDF
Full Steam Ahead, R2DBC!
PDF
Walking Through Spring Cloud Data Flow
PDF
Next-Generation Cloud Native Apps with Spring Cloud and Kubernetes
PDF
Spring Cloud Function: Where We Were, Where We Are, and Where We’re Going
PDF
Welcome to the Metrics
Spring Data JDBC: Beyond the Obvious
Spring Native and Spring AOT
Spring Boot Loves K8s
Full Steam Ahead, R2DBC!
Walking Through Spring Cloud Data Flow
Next-Generation Cloud Native Apps with Spring Cloud and Kubernetes
Spring Cloud Function: Where We Were, Where We Are, and Where We’re Going
Welcome to the Metrics

What's hot (20)

PDF
Spring Boot Whirlwind Tour
PDF
Spring: Your Next Java Micro-Framework
PDF
What Is Spring?
PDF
Introducing Spring Framework 5.3
PDF
Resilient and Adaptable Systems with Cloud Native APIs
PDF
Creating Polyglot Communication Between Kubernetes Clusters and Legacy System...
PDF
Security Patterns for Microservice Architectures - SpringOne 2020
PDF
Introducing Spring Cloud Gateway and API Hub for VMware Tanzu
PDF
Developers Are Users, Too
PDF
Spring Boot Observability
PDF
What’s New in Spring Data MongoDB
PDF
Connecting Spring Apps to Distributed SQL Clusters Running in Kubernetes
PDF
What Is Spring?
PDF
Spring Boot—Production Boost
PPTX
Micronaut: A new way to build microservices
PDF
How To Be a Java Automated Testing Superstar
PDF
Ingress? That’s So 2020! Introducing the Kubernetes Gateway API
PDF
Peering Inside the Black Box: A Case for Observability
PDF
The Path Towards Spring Boot Native Applications
PDF
“Sh*^%# on Fire, Yo!”: A True Story Inspired by Real Events
Spring Boot Whirlwind Tour
Spring: Your Next Java Micro-Framework
What Is Spring?
Introducing Spring Framework 5.3
Resilient and Adaptable Systems with Cloud Native APIs
Creating Polyglot Communication Between Kubernetes Clusters and Legacy System...
Security Patterns for Microservice Architectures - SpringOne 2020
Introducing Spring Cloud Gateway and API Hub for VMware Tanzu
Developers Are Users, Too
Spring Boot Observability
What’s New in Spring Data MongoDB
Connecting Spring Apps to Distributed SQL Clusters Running in Kubernetes
What Is Spring?
Spring Boot—Production Boost
Micronaut: A new way to build microservices
How To Be a Java Automated Testing Superstar
Ingress? That’s So 2020! Introducing the Kubernetes Gateway API
Peering Inside the Black Box: A Case for Observability
The Path Towards Spring Boot Native Applications
“Sh*^%# on Fire, Yo!”: A True Story Inspired by Real Events

Similar to Going Serverless Using the Spring Framework Ecosystem (20)

PDF
Spring Boot Native written by software developers
PDF
Pivotal Platform - December Release A First Look
PDF
Building Event-Driven Workflows with Knative and Tekton
PPTX
Knative goes
 beyond serverless | Alexandre Roman
PDF
VMworld 2013: Part 1: Getting Started with vCenter Orchestrator
PDF
Cloudy in Indonesia: Java and Cloud
PDF
Reactive Amsterdam - Maxim Burgerhout - Quarkus Intro
PDF
Pure Systems Patterns of Expertise - John Kaemmerer and Gerry Kovan, 11th Sep...
PDF
The path to a serverless-native era with Kubernetes
PPTX
Using Nano Server for Hyper-V Training 0
PPTX
Vmware Tanzu Kubernetes Connect(Spanish)
PDF
VMworld Europe 204: Technical Deep Dive on EVO: RAIL, the new VMware Hyper-Co...
PDF
Nebulaworks Docker Overview 09-22-2015
PPTX
Kubernetes Storage Webinar.pptx
PDF
Continuous Delivery with Grails and CloudBees
PPTX
JavaLand_To InstantOn and Beyond.pptx
PDF
Backroll: Production Grade KVM Backup Solution Integrated in CloudStack
PDF
OSv presentation from Linux Foundation Collaboration Summit
PPTX
COP_RoR_QuArrk_Session_Oct_2022.pptx
PDF
Packaging tool options
Spring Boot Native written by software developers
Pivotal Platform - December Release A First Look
Building Event-Driven Workflows with Knative and Tekton
Knative goes
 beyond serverless | Alexandre Roman
VMworld 2013: Part 1: Getting Started with vCenter Orchestrator
Cloudy in Indonesia: Java and Cloud
Reactive Amsterdam - Maxim Burgerhout - Quarkus Intro
Pure Systems Patterns of Expertise - John Kaemmerer and Gerry Kovan, 11th Sep...
The path to a serverless-native era with Kubernetes
Using Nano Server for Hyper-V Training 0
Vmware Tanzu Kubernetes Connect(Spanish)
VMworld Europe 204: Technical Deep Dive on EVO: RAIL, the new VMware Hyper-Co...
Nebulaworks Docker Overview 09-22-2015
Kubernetes Storage Webinar.pptx
Continuous Delivery with Grails and CloudBees
JavaLand_To InstantOn and Beyond.pptx
Backroll: Production Grade KVM Backup Solution Integrated in CloudStack
OSv presentation from Linux Foundation Collaboration Summit
COP_RoR_QuArrk_Session_Oct_2022.pptx
Packaging tool options

More from VMware Tanzu (20)

PDF
Spring into AI presented by Dan Vega 5/14
PDF
What AI Means For Your Product Strategy And What To Do About It
PDF
Make the Right Thing the Obvious Thing at Cardinal Health 2023
PPTX
Enhancing DevEx and Simplifying Operations at Scale
PDF
Spring Update | July 2023
PPTX
Platforms, Platform Engineering, & Platform as a Product
PPTX
Building Cloud Ready Apps
PDF
Spring Boot 3 And Beyond
PDF
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
PDF
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
PDF
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
PPTX
tanzu_developer_connect.pptx
PDF
Tanzu Virtual Developer Connect Workshop - French
PDF
Tanzu Developer Connect Workshop - English
PDF
Virtual Developer Connect Workshop - English
PDF
Tanzu Developer Connect - French
PDF
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
PDF
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
PDF
SpringOne Tour: The Influential Software Engineer
PDF
SpringOne Tour: Domain-Driven Design: Theory vs Practice
Spring into AI presented by Dan Vega 5/14
What AI Means For Your Product Strategy And What To Do About It
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Enhancing DevEx and Simplifying Operations at Scale
Spring Update | July 2023
Platforms, Platform Engineering, & Platform as a Product
Building Cloud Ready Apps
Spring Boot 3 And Beyond
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
tanzu_developer_connect.pptx
Tanzu Virtual Developer Connect Workshop - French
Tanzu Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
Tanzu Developer Connect - French
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: Domain-Driven Design: Theory vs Practice

Recently uploaded (20)

PPTX
Foundations of Marketo Engage: Nurturing
PDF
Top AI Tools for Project Managers: My 2025 AI Stack
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PPTX
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PPTX
Why 2025 Is the Best Year to Hire Software Developers in India
PDF
Difference Between Website and Web Application.pdf
PPT
3.Software Design for software engineering
PDF
solman-7.0-ehp1-sp21-incident-management
PPTX
AI Tools Revolutionizing Software Development Workflows
PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PPTX
ESDS_SAP Application Cloud Offerings.pptx
PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PDF
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
PPTX
Lesson-3-Operation-System-Support.pptx-I
Foundations of Marketo Engage: Nurturing
Top AI Tools for Project Managers: My 2025 AI Stack
Folder Lock 10.1.9 Crack With Serial Key
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Comprehensive Guide to Digital Image Processing Concepts and Applications
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
Why 2025 Is the Best Year to Hire Software Developers in India
Difference Between Website and Web Application.pdf
3.Software Design for software engineering
solman-7.0-ehp1-sp21-incident-management
AI Tools Revolutionizing Software Development Workflows
Presentation - Summer Internship at Samatrix.io_template_2.pptx
ESDS_SAP Application Cloud Offerings.pptx
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
Lesson-3-Operation-System-Support.pptx-I

Going Serverless Using the Spring Framework Ecosystem

  • 1. ©2021 VMware, Inc. Going Serverless using the Spring Framework ecosystem Timo Salm Senior Specialist Solution Engineer VMware Tanzu September 2021
  • 2. ©2021 VMware, Inc. Agenda 2 ▪ About me ▪ What is Serverless? ▪ Going Serverless with your Spring Boot applications
  • 3. ©2021 VMware, Inc. 3 About me Timo Salm Senior SpecialistSolutionEngineer for VMware Tanzu ▪ https://tanzu.vmware.com/ ▪ Twitter: @salmto ▪ GitHub: https://github.com/tsalm-pivotal
  • 4. 4 ©2021 VMware, Inc. What Is Serverless?
  • 5. ©2021 VMware, Inc. 5 Serverless doesn’t mean there are no servers, it means you don’t care about them. Serverless can be group into two areas: ▪ Backend as a Service (BaaS) Replacing server-side, self-managed components with off-the-shelf services ▪ Functions as a Service (FaaS) A new way of building and deploying server-side software, oriented around deploying individual functions The key is that with both, you don't have to manageyour own server hosts or server processes and can focus on business value! What is Serverless?
  • 6. ©2021 VMware, Inc. 6 A Serverless service … ▪ … does not require managing a long-lived host or application instance ▪ … self auto-scales and auto-provisions, dependent on load ▪ … has implicit high availability ▪ … has performance capabilities defined in terms other than host size/count ▪ … has costs that are based on precise usage, up from and down to zero usage Key characteristics What is Serverless?
  • 7. ©2021 VMware, Inc. 7 ▪ Shorter lead time ▪ Reduced packaging and deploymentcomplexity ▪ Increased flexibility of scaling ▪ Reduced resource cost ▪ Reduced labor cost ▪ Reduced risk Why Serverless?
  • 8. ©2021 VMware, Inc. 8 ▪ Unpredictable costs ▪ Spinning up machines takes time - from a few seconds to minutes ▪ Most Serverless applications are stateless and the managementof state can be somewhat tricky ▪ Higher latency due to inter-component communication over HTTP APIs and “cold starts” ▪ Problematic with downstream systems that cannot increase their capacity quickly enough ▪ Typically limited in how long each invocation is allowed to run ▪ Multitenancy problems Part 1/2 Drawbacks / Limitations of Serverless
  • 9. ©2021 VMware, Inc. 9 ▪ Debugging is more complicated (a single request can travel between several machines and some of those machines disappear at times) ▪ Added work is needed to provide tracing and monitoring solutions, which can add complexity and cost to the project ▪ Security can be more demanding in a serverless environment ▪ Loss of control over ▪ absoluteconfiguration ▪ the performance of Serverless components ▪ issue resolution ▪ security ▪ The difficulty of local testing ▪ Vendor lock-in unless you are using OSS projects like e.g. Knative Part 2/2 Drawbacks / Limitations of Serverless
  • 10. ©2021 VMware, Inc. 10 An open-source community project which adds components for deploying, running, and managing applicationson any Kubernetes in a Serverless way. What is Knative? To primary components: ▪ Serving:Supports deploying and serving of serverless applications and functions ▪ Eventing: Enables developers to use an event-driven architecture with serverless applications
  • 11. ©2021 VMware, Inc. 11 Summary The primary drivers for the adoption of Serverless are: Developer productivity Platform elasticity Cost savings
  • 12. 12 ©2021 VMware, Inc. Going Serverless with your Spring Boot applications
  • 13. 13 ©2021 VMware, Inc. Demo Running a Spring Boot application on Knative
  • 14. ©2021 VMware, Inc. 16 Unleash the full potential of Serverless for our application Faster startup time Lower resource consumption (memory, CPU) More cost savings
  • 15. ©2021 VMware, Inc. 17 Interpretation vs Compilation Just-in-Time vs Ahead-of-Time .java Java Class JIT @ Compile Time Compiler .class Bytecode JIT @ JVM Runtime JIT Compiler Native Code .java Java Class AOT @ Compile Time Compiler .class Bytecode AOT @ Native Runtime .jar Archive Executed Native Executable Executed .jar Archive
  • 16. ©2021 VMware, Inc. 18 What are Native Images? Smaller, faster and lower resource consumption ▪ Standaloneexecutableof ahead-of-time compiled Javacode ▪ Includes the applicationclasses, classes from its dependencies, runtime library classes, and statically linked native code from JDK ▪ Runs without the need of a JVM, necessary componentsare includedin a runtime system, called“Substrate VM” ▪ Specific to the OS and machine architecture for which it was compiled ▪ Requires fewer resources than regular Javaapplicationsrunning on a JVM
  • 17. ©2021 VMware, Inc. 19 ▪ Basic idea: One VM that can execute applications written in Java and other JVM languages while also providing runtimes for JavaScript, Ruby, Python, and a number of other popular languages ▪ Started by Oracle: https://graalvm.org/ ▪ GraalVM’s polyglot capabilities make it possible to mix multiple programming languages in a single application while eliminating any foreign language call costs ▪ Still in “early adopter” mode, but matures quickly A high-performance JDKdistribution What is GraalVM?
  • 18. ©2021 VMware, Inc. 20 Tradeoffs between JVM and Native Images
  • 19. ©2021 VMware, Inc. 21 ▪ A static analysis of your application from the main entry point is performed at build time ▪ The unused parts are removed at build time ▪ Configuration is required for reflection, resources, and dynamic proxies ▪ Classpath is fixed at build time ▪ No class lazy loading: everything shipped in the executables will be loaded in memory on startup ▪ Some code will run at build time ▪ There are some limitations around some aspects of Java applications that are not fully supported Key differences between JVM and GraalVM native image platform
  • 20. ©2021 VMware, Inc. 23 Spring Native provides incubating support for compiling Spring applications to lightweight native executables using the GraalVM native-image compiler. The goal is to support compilation of existing or new Spring Boot applications to native executables. Unchanged.
  • 21. ©2021 VMware, Inc. 24 ▪ Choose Spring Boot 2.5.4 as your project’sparent for the Spring Native0.10.3 release ▪ Java8 and Java11 supported for NativeImages at this time in the GraalVM Get started with Spring Native Create a new project on start.spring.io or use an existing one
  • 22. ©2021 VMware, Inc. 25 ▪ Use Spring Boot 2.5.4 as your project’sparent for the latest Spring Nativerelease ▪ Add a dependencyto the latest Spring Nativelibrary e.g. spring-native version 0.10.3 ▪ Leverage Paketo JavaNativeImage Buildpack ▪ Configure the Spring Boot Maven Plugin to build a nativeimage ▪ Add the Spring AOT plugin Get started with Spring Native Create a new project on start.spring.io or use an existing one
  • 23. ©2021 VMware, Inc. 26 ▪ Add the nativebuild tools plugin Get started with Spring Native Create a new project on start.spring.io or use an existing one
  • 24. ©2021 VMware, Inc. 27 Two options to build a native image with Spring Native Via Cloud-Native-Buildpacks ▪ Configure your build to use the Paketo Buildpacks ▪ Tell the buildpackto produce a native image ▪ The result is a small containerimage with the compiled nativeexecutable inside ▪ No local GraalVM installationneeded ▪ Super easy to use ▪ Run mvn spring-boot:build-imageto create a containerwith your application Via GraalVM native image Mavenplugin ▪ Configure your build to compileto a native executable ▪ Produces a native executable for the platform you are running on ▪ Requires GraalVM locallyinstalled ▪ Also super easy to use ▪ Run mvn -Pnative -DskipTests package to buildthe application.
  • 25. 28 ©2021 VMware, Inc. Demo Running a Spring Boot application as Native Image on Knative
  • 26. ©2021 VMware, Inc. 30 Performance expectations Sample On the JVM Nativeapplication spring-boot-hello- world Build: 19 s Memory(RSS): 225M Startup time: 2.367s Build: 04:21 min +1374% Memory(RSS): 68M -70% Startup time: 0.119s -95% actuator-r2dbc- webflux Build: 8s Memory(RSS): 640M Startup time: 3.0s Build: 141s +1700% Memory(RSS): 86M -87% Startup time: 0.094s -97% petclinic-jdbc Build: 9s Memory(RSS): 417M Startup time: 2.6s Build: 194s +2050% Memory(RSS): 101M -75% Startup time: 0.158s -94%
  • 27. ©2021 VMware, Inc. 31 Ongoing improvements in reducing footprint Sample Sep 2019 Mar 2021 commandlinerunner Build: 90s Exec. size: 48M Memory(RSS): 29M Build: 50s Exec. size: 21M Memory(RSS): 22M webflux-netty Build: 193s Exec. size: 81M Memory(RSS): 95M Build: 79s Exec. size: 47M Memory(RSS): 48M webmvc-tomcat Build: 203s Exec size: 105M Memory(RSS): 70M Build: 67s Exec. size: 45M Memory(RSS): 51M
  • 28. ©2021 VMware, Inc. 32 ▪ Delegate Native Imagebuilding to the CI/CD pipeline, leveraging Spring Native and Paketo Buildpacks ▪ Unchanged Developer UX in your IDE, with the same JVM Use JVM locally, delegate Native Builds to CI/CD… Can I keep the great Spring UX when going Native?
  • 29. ©2021 VMware, Inc. 33 Spring Boot 3, based on Spring Framework 6, is expected to provide first- class support for native application deployment, as well as an optimized footprint on the JVM. The road ahead
  • 30. ©2021 VMware, Inc. 34 ▪ Documentation: https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/ ▪ Spring Native project on Github: https://github.com/spring-projects-experimental/spring-native ▪ Workshop by my awesome colleague Dan Dobrin: https://github.com/ddobrin/native-spring-on-k8s- with-graalvm-workshop Resources