Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Native Image, AOT, or JIT: When to use in your Java Architecture

Native Image, AOT, or JIT: When to use in your Java Architecture

Over the years the JVM was built for applications that run for days, months to years, but with the adoption of distributed architectures, such as microservices and serverless, this requirement has changed and we no longer need a JVM to support long-term applications, but a Most effective JVM in the computational resource requirement.

With this in mind, support for modularity was launched in Java 9, but we have other fronts that are improving compilation techniques, such as Ahead of time compilation (AOT), Just in time compilation (JIT) and Native Image (GraalVM).

Therefore, in this lecture I will discuss each alternative, providing you with the necessary inputs to make more assertive decisions in your architectures.

Ef3b48913ea26665c25b2ad78e449d16?s=128

Luram Archanjo

August 26, 2020
Tweet

Transcript

  1. Native Image, AOT, or JIT When to use in your

    Java Architecture Luram Archanjo
  2. Software Engineer at Zup Innovation MBA in Java projects Java

    and Microservice enthusiastic Who am I?
  3. Agenda Goal Types of Architectures Ahead of time (AOT) compilation

    Native Image Just in time (JIT) compilation Questions
  4. Goal

  5. Types of Architectures Distributed • Microservices • Event Driven •

    Serverless Centralized • Monolithic • Data Centric
  6. But Architecture X is better than Y

  7. Find the balance of your Architecture

  8. All Architecture has finite resources!

  9. How to use less resources using Java language?

  10. Java Module? Microframeworks? Quarkus? Micronaut?

  11. None of them! First, we need to find the Root

    Cause!
  12. The villain of Java’s resources is the Reflection

  13. How Spring and Jakarta EE work? Spring is an amazing

    technical achievement and does so many things, but does them at Runtime. • Reads the byte code of every bean it finds. • Synthesizes new annotations for each annotation on each bean method, constructor, field etc. to support Annotation metadata. • Builds Reflective Metadata for each bean for every method, constructor, field etc.
  14. The use of Reflection!

  15. Is it possible to have the same productivity but without

    Reflection?
  16. Yes, with Ahead Of Time (AOT) Compilation

  17. Ahead of Time (AOT) Compilation Ahead-of-time compilation (AOT compilation) is

    the act of compiling a higher-level programming language, or an intermediate representation such as Java bytecode, into a native machine code so that the resulting binary file can execute natively. Web Android Java Google Dagger 2
  18. What are the results of using Ahead Of Time (AOT)

    Compilation?
  19. Source: https://micronaut.io/blog/2020-04-28-performance-comparison-spring-boot-micronaut.html

  20. What about the native machine code?

  21. None
  22. GraalVM • Native Image • Ahead-of-Time Compilation • For existing

    Java applications, GraalVM can provide benefits by running them faster, providing a faster Just In Time (JIT) Compilation
  23. GraalVM GraalVM Native Image allows you to ahead-of-time compile Java

    code to a standalone executable, called a native image. Source: https://www.graalvm.org/docs/reference-manual/native-image/
  24. GraalVM - Limitations Dynamic Class Loading: Deploying jars, wars, etc.

    at runtime impossible. Reflection: Requires registration via native-image CLI/API. Dynamic Proxy: No agents: JMX, JRebel, Byteman, profilers, tracers, etc.
  25. What are the results of using Native Image?

  26. Source: https://www.graalvm.org/docs/why-graal/

  27. Source: https://www.graalvm.org/docs/why-graal/

  28. Early Adopter Technology!

  29. I don’t use Quarkus, Micronaut and Helidon! How can I

    improve my current system?
  30. What about the Just In Time (JIT) Compilation?

  31. Just In Time (JIT) Compilation Just In Time (JIT) compilation

    is a way of executing computer code that involves compilation during execution of a program. It runs complex optimizations to generate high-quality machine code System.out.prin tln("Hello World"); Source code 6a 61 76 61 20 c3 a9 20 66 6f 64 61 Byte code 01101010 01100001 0100000 Machine code JIT
  32. What are the results of using Just In Time (JIT)

    Compilation?
  33. Twitter Every company is constantly looking into ways to increase

    availability of the platform while keeping an eye on costs. Twitter saw Oracle GraalVM, a language-independent compiler engine and virtual machine, and decided to try it. Average CPU savings for compiler innovation are in the 1–2 percent range, but using Oracle GraalVM, Twitter realized between 8 and 11 percent CPU savings, depending on the microservice ported. Source: https://www.constellationr.com/research/how-oracle-graalvm-supercharged-twitter-s-microservices-platform
  34. What are the results of using Just In Time (JIT)

    Compilation?
  35. A lot of cool initiatives! Let us recap?

  36. 2º Place 1º Place 3º Place Ahead of Time (AOT)

    Compilation • Low memory footprint • Fast Startup • IoC & SQL Native Image • Low memory footprint 5x lower • Fast Startup 50x lower • Early Adopter Technology Just in Time (JIT) Compilation • Latency • Throughput Summary
  37. Native Image, AOT, or JIT? When to use in your

    Java Architecture?
  38. Native Image, AOT, or JIT? When to use in your

    Java Architecture? Existent Application New Application Serverless & CLI Ahead Of Time Compilation • Spring* • Quarkus • Micronaut • Helidon Just In Time Compilation • GraalVM ◦ Java 8 ◦ Java 11 • Community • Enterprise Native Image • GraalVM
  39. Java is dying?

  40. Thanks a million! Questions? /larchanjo /luram-archanjo