Crossing the chasm: Native Images

  • Estefania Castro Vizoso
  • Juan Antonio Breña Moral

Agenda

  1. Who I am
  2. Context
  3. Product life cycle
  4. Starting hypothesis
  5. How to compile native images with Spring?
  6. Design of experiments
  7. Benchmark results
  8. Key takeaways
  9. Sources
  10. References

Who I am

Estefania Castro Vizoso

Technical expert &
Innovation @ VASS

@Fany_CV | Github | Linkedin

Who I am

Juan Antonio Breña Moral

Technical Architect & Innovation Estratego @ VASS
Associate Professor @ ICAI
JVM Builder for ARM5 @ Eclipse Adoptium
@juanantoniobm | Github | Linkedin

Context

GraalVM is the next Java Virtual Machine Generation and it includes multiple new features but in this presentation, we will put the focus on: Native Images


Traditionally, Java applications are called WORA (Write Once Run Anywhere).

Context

Context

But in some scenarios, 147MB is Ok, but in others is so much...

Product life cycle

It is the amount of time a product goes from being introduced into the market until it is taken off the shelves.

Crossing the chasm

In the book Crossing the Chasm, Geoffrey A. Moore begins with the diffusion of innovations theory from Everett Rogers, and argues there is a chasm between the early adopters of the product (the technology enthusiasts and visionaries) and the early majority (the pragmatists).

Crossing the chasm

In what stage is GraalVM and Native Images?

Crossing the chasm

Types of Innovation:

Crossing the chasm

Is this feature, compatible with your Evolutionary architecture?

Starting hypothesis

  1. Is Java HotSpot Virtual Machine at the end of the product life cycle?
  2. Microservices running as Native images from a GraalVM compilation have better performance than Microservices running on Java HotSpot Virtual Machine?

🤔

Starting hypothesis

Is Java HotSpot Virtual Machine at the end of the product life cycle?

Starting hypothesis

Is Java HotSpot Virtual Machine at the end of the product life cycle?

In 2021, exist so much interest in Java HotSpot Virtual Machine.

Starting hypothesis

Is Java HotSpot Virtual Machine at the end of the product life cycle?

JVM Builders:

  • OpenJDK, AdoptOpenJDK
  • Corretto, Amazon
  • OpenJDK, Oracle
  • Liberica, Bellsoft
  • SapMachine, SAP
  • Zulu, Azul Systems

Starting hypothesis

Is Java HotSpot Virtual Machine at the end of the product life cycle?

Open JDK Projects:

Starting hypothesis

Is Java HotSpot Virtual Machine at the end of the product life cycle?

"I don´t know Rick, it seems false."

Starting hypothesis

Microservices running as Native images from a GraalVM compilation have better performance than Microservices running on Java HotSpot Virtual Machine?

Source: https://blogs.oracle.com/javamagazine/pedal-to-the-metal-high-performance-java-with-graalvm-native-image

Starting hypothesis

Microservices running as Native images from a GraalVM compilation have better performance than Microservices running on Java HotSpot Virtual Machine?


"How to verify that hypothesis?"

How to compile native images with Spring?

Is it easy or complex to create native images from your Spring Boot applications?

Quarkus was designed with that feature in mind.

How to compile native images with Spring?

1. We add the Spring Native dependency

How to compile native images with Spring?

2. We added the plugin to compile Native images

How to compile native images with Spring?

3. Enable native image support (using Spring Boot’s Cloud Native Buildpacks support)

How to compile native images with Spring?

4. Added a maven profile to compile Native images

How to compile native images with Spring?

Install GraalVM:


sdk use java 21.1.0.r11-grl
Gu install native-image

Generate the native image from Spring Boot:


mvn clean package -pl imperative-api -P native-image

How to compile native images with Spring?

After few minutes compiling...

How to compile native images with Spring?

Git repository tour:

"Rick, show me the project!"

Design of experiments

Experiment: Develop a Microservice which connect with a Database (PostgreSQL) and the logic use ORM Features (In the cases that it is possible) and SQL (Native Query) but in a non trivial queries trying to test the performance of that dependencies.

Design of experiments

We implemented the experiment with:

  1. Spring Imperative JPA (Native)
  2. Spring Imperative JPA (ORM)
  3. Spring Imperative JDBC (Native)
  4. Spring Imperative JDBC (ORM)
  5. Spring Reactive
  6. Quarkus Imperative JPA (Native)
  7. Quarkus Imperative JPA (ORM)
  8. Quarkus Imperative JDBC
  9. Quarkus Reactive

Design of experiments

And... We added Node.js in the salad too...

😃 🥗

Because we can do it!

😎 💪

Design of experiments

That developments was implemented and included in a Docker compose running the microservices with Postgresql (One database container per microservice to avoid possible side effects)

Design of experiments

Design of experiments

Design of experiments

With the Docker compose running with the microservices connected with their databases, we running a JMeter script pointing for:

  • Microservices running with JVM Hotspot
  • Microservices running with Native images

We run the JMeter 10x to collect some reports to analyze later.

Design of experiments

Hardware used in the experiments:


iMac 4.2 GHz 4-core Intel Core i7 processor
32 GB 2400 MHz DDR4

Benchmark results

Throughput results:


HTTP Request - Spring Imperative JDBC (Native) jvm 21.2766
HTTP Request - Spring Reactive jvm 18.53912
HTTP Request - Spring Imperative JDBC (Native) jvm 18.02127
HTTP Request - Spring Imperative JDBC (Native) jvm 17.96945
HTTP Request - Spring Imperative JDBC (Native) jvm 16.28664
HTTP Request - Spring Imperative JDBC (Native) jvm 15.37752
HTTP Request - Spring Reactive jvm 15.03986
HTTP Request - Spring Reactive jvm 14.9723
HTTP Request - Spring Imperative JDBC (Native) jvm 14.56876
HTTP Request - Nodejs native 13.95868

Benchmark results

Compare the best Throughput result between JVM Hotspot and Native image:


HTTP Request - Spring Imperative JDBC (Native) jvm 21.2766
HTTP Request - Spring Imperative JDBC (Native) native 13.40123

The Throughput from JVM Hotspot is about 63% greater than using Native Images generated by GraalVM CE.

Benchmark results

Compare the best Throughput result among different Spring options:


Spring Imperative JDBC (Native) jvm 21.2766
Spring Imperative JPA (ORM) jvm 1.90494
Spring Reactive jvm 18.53912

Benchmark results

Compare the best Throughput result among different event-loop options:


Spring Reactive jvm 18.53912
Quarkus Reactive jvm 12.32894
Nodejs native 13.95868

Benchmark results

Maybe the graph should be upgraded because it is greather the performance with JVM Hotspot.

Benchmark results

Throughput results:

"Rick, show me your sources!"

Benchmark results

Start up times:

| SERVICE | START UP TIME | FIRST REQUEST TIME |---------------------------------------|-------------------|-----------------------| | Springboot reactive Native | 0.177 seconds | 0.000 seconds | | Springboot reactive JVM | 9.117 seconds | 0.000 seconds | | Quarkus reactive Native | 0.014 seconds | 0.000 seconds | | Quarkus reactive JVM | 2.127 seconds | 0.000 seconds |
| SERVICE | START UP TIME | FIRST REQUEST TIME |---------------------------------------|-------------------|-----------------------| | Spring imperative JPA Native | 0.275 seconds | 0.000 seconds | | Spring imperative JPA Native JVM | 12.414 seconds | 0.000 seconds | | Spring imperative JDBC Native | 0.172 seconds | 0.000 seconds | | Spring imperative JDBC Native JVM | 9.224 seconds | 0.000 seconds |
| SERVICE | START UP TIME | FIRST REQUEST TIME |---------------------------------------|-------------------|-----------------------| | Quarkus imperative JPA Native | 0.069 seconds | 0.000 seconds | | Quarkus imperative JPA Native JVM | 3.924 seconds | 0.000 seconds | | Quarkus imperative JDBC Native | 0.011 seconds | 0.000 seconds | | Quarkus imperative JDBC Native JVM | 2.759 seconds | 0.000 seconds |

Key takeaways

  • Java code runs with better Throughput on JVM Hotspot than GraalVM CE
  • GraalVM CE is not ready to replace JVM Hotspot
  • Leyden Project will improve the Startup time on JVM Hotspot
  • Compile for Native Images requires mountains of RAM
  • Native images are more suitable for Serverless than Microservices solutions

Key takeaways

Dev notes:
  • Spring Boot & Quarkus has an easy configuration to compile Native Images
  • Spring Data JDBC has better performance than Spring Data JPA
  • Invest time to improve SQL Skills

Sources

The whole project, performance data are here:

https://github.com/EstefaniaExamples/crossing-the-chasm-native-images

References

  • Crossing the Chasm
  • Announcing Spring Native Beta!
  • GraalVM Native Image Reference
  • Spring Native documentation
  • Thoughtworks Radar: GraalVM
  • InfoQ Architecture trends 2021
  • InfoQ JVM trends 2020
  • Paketo Build Packs
  • Spring Native Example
  • 🙏 🙏 🙏

    Thanks