Q U A R K U S & G R A A L V M Q U A R K U S & G R A A L V M booting Hibernate at supersonic speed, subatomic size @SanneGrinovero
S A N N E G R I N O V E R O S A N N E G R I N O V E R O Dutch, Italian, now in London.
S A N N E G R I N O V E R O S A N N E G R I N O V E R O Dutch, Italian, now in London. • Red Hat : Middleware R&D Hibernate team lead ▪ Quarkus, engineering team ▪
S A N N E G R I N O V E R O S A N N E G R I N O V E R O Dutch, Italian, now in London. • Red Hat : Middleware R&D Hibernate team lead ▪ Quarkus, engineering team ▪ • Also contributing to: GraalVM, OpenJDK, WildFly, Apache Lucene, ▪ Infinispan, Elasticsearch, JGroups, Byteman, Maven, Gradle, PostgreSQL, JakartaEE, Thorntail, ANTLR, Asciidoctor, ...
A G E N D A A G E N D A • GraalVM & native images • Quarkus • Joy of live coding • How ?!?
N A T I V E I M A G E ? N A T I V E I M A G E ?
L E T ' S S E E O N E I N L E T ' S S E E O N E I N A C T I O N . . . A C T I O N . . . $ export GRAALVM_HOME= //path to your GraalVM download, unpacked $ export JAVA_HOME=$GRAALVM_HOME $ mvn package $ native-image -jar main.jar $ ./main
I N T E R E S T I N G . . . I N T E R E S T I N G . . . How about more complex apps?
used by Quarkus
A o T c o m p i l a t i o n w i t h G r a a l V M A o T c o m p i l a t i o n w i t h G r a a l V M JDK API Application SubstrateVM classes classes classes Staticaly linked executable
A o T c o m p i l a t i o n w i t h G r a a l V M A o T c o m p i l a t i o n w i t h G r a a l V M • Static analysis • Closed world assumption • Dead code elimination: classes, fields, methods, branches
L I M I T A T I O N S L I M I T A T I O N S O F G R A A L V M N A T I V E O F G R A A L V M N A T I V E I M A G E S I M A G E S
D Y N A M I N C D Y N A M I N C C L A S S L O A D I N G C L A S S L O A D I N G
D Y N A M I N C D Y N A M I N C C L A S S L O A D I N G C L A S S L O A D I N G Deloying jars, wars, etc. at runtime impossible
J V M T I , J M X J V M T I , J M X + other native VM interfaces
J V M T I , J M X J V M T I , J M X + other native VM interfaces No agents
J V M T I , J M X J V M T I , J M X + other native VM interfaces No agents JRebel, Byteman, profilers, tracers, ...
J V M T I , J M X J V M T I , J M X + other native VM interfaces No agents JRebel, Byteman, profilers, tracers, ... No Java Debugger
M I S C E L L A N E O U S M I S C E L L A N E O U S No: Security Manager No: finalize() (deprecated anyway) Limited: InvokeDynamic and MethodHandles
! limited R E F L E C T I O N R E F L E C T I O N Requires registration via native-image CLI/API
! limited M O R E . . . M O R E . . . Need to register in advance also: • Dynamic proxies • Resources being loaded • JNI, Unsafe Memory Access, ...
Very special S T A T I C I N I T S T A T I C I N I T Attempts to run them at build time
Very special S T A T I C I N I T S T A T I C I N I T Attempts to run them at build time • Resolve classes, run "safe" static initializers
Very special S T A T I C I N I T S T A T I C I N I T Attempts to run them at build time • Resolve classes, run "safe" static initializers • Take a snapshot of the produced instances - prune the unreachable ones
Very special S T A T I C I N I T S T A T I C I N I T Attempts to run them at build time • Resolve classes, run "safe" static initializers • Take a snapshot of the produced instances - prune the unreachable ones • Include them in the executable
Very special S T A T I C I N I T S T A T I C I N I T • not allowed: file handles, sockets, threads • careful with other state: timestamps, system dependent constants, capturing environment variables, etc..
H O W D O Y O U D I S A B L E A H O W D O Y O U D I S A B L E A F E A T U R E A N Y W A Y ? F E A T U R E A N Y W A Y ?
H O W D O Y O U D I S A B L E A H O W D O Y O U D I S A B L E A F E A T U R E A N Y W A Y ? F E A T U R E A N Y W A Y ? boolean jmxEnabled = parseConfiguration(...); if (jmxEnabled) { registerJMX(); }
H O W D O Y O U D I S A B L E A H O W D O Y O U D I S A B L E A F E A T U R E A N Y W A Y ? F E A T U R E A N Y W A Y ? boolean jmxEnabled = parseConfiguration(...); if (jmxEnabled) { registerJMX(); } static final JMX_ENABLED = false; if (JMX_ENABLED) { registerJMX(); }
O K L E T ' S A D A P T M Y O K L E T ' S A D A P T M Y C O D E . . . C O D E . . .
O K L E T ' S A D A P T M Y O K L E T ' S A D A P T M Y C O D E . . . C O D E . . . All your dependencies need to get compiled too!
O K L E T ' S A D A P T M Y O K L E T ' S A D A P T M Y C O D E . . . C O D E . . . All your dependencies need to get compiled too! ALL DEPENDENCIES
I M P A C T O N H I B E R N A T E I M P A C T O N H I B E R N A T E O R M ? O R M ?
I M P A C T O N H I B E R N A T E I M P A C T O N H I B E R N A T E O R M ? O R M ? Mindmap #3
W H A T I S Q U A R K U S W H A T I S Q U A R K U S
T O O L K I T T O O L K I T and F R A M E W O R K F R A M E W O R K for writing Java applications
T O O L K I T T O O L K I T and F R A M E W O R K F R A M E W O R K for writing Java 1 applications 1) and Kotlin
L I G H T , C L O U D F R I E N D L Y , L I G H T , C L O U D F R I E N D L Y , D E S I G N E D F O R G R A A L V M D E S I G N E D F O R G R A A L V M Helps overcome limitations of GraalVM Embraces them!
*.class QUARKUS Maven/Gradle plugin optimized jar JVM native executable
E X T E N S I O N S E X T E N S I O N S Each Java library gets a Quarkus extension Makes it compatible with GraalVM native-images And makes it much lighter to run on JVM
L I B R A R I E S Y O U A L R E A D Y K N O W L I B R A R I E S Y O U A L R E A D Y K N O W ECLIPSE VERT.X HIBERNATE RESTEASY APACHE CAMEL NETTY KUBERNETES JAEGER PROMETHEUS APACHE KAFKA INFINISPAN
Unifies I M P E R A T I V E I M P E R A T I V E and R E A C T I V E R E A C T I V E @Inject @Inject @Stream("kafka") SayService say; Publisher<String> reactiveSay @GET @GET @Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.SERVER_SEN public String hello() { public Publisher<String> stre return say.hello(); return reactiveSay; } }
C O N T A I N E R F I R S T C O N T A I N E R F I R S T
C O N T A I N E R F I R S T C O N T A I N E R F I R S T 💿 Small size on disk Small container images ✓
C O N T A I N E R F I R S T C O N T A I N E R F I R S T 💿 Small size on disk Small container images ✓ 🚁 Fast boot time Instant scale up ✓
C O N T A I N E R F I R S T C O N T A I N E R F I R S T 💿 Small size on disk Small container images ✓ 🚁 Fast boot time Instant scale up ✓ 🔭 Low RSS 1 memory More containers with ✓ the same RAM 1) Resident Set Size
M E A S U R I N G M E M O R Y M E A S U R I N G M E M O R Y RSS = all RAM consumed by the process $ ps -o pid,rss,command -p $(pgrep quarkus) PID RSS COMMAND 11229 12628 ./target/quarkus-hello
M E M O R Y ( R S S ) M E M O R Y ( R S S ) Quarkus + GraalVM Quarkus + OpenJDK Best of traditio
M E M O R Y ( R S S ) M E M O R Y ( R S S ) Quarkus + GraalVM Quarkus + OpenJDK Best of traditio REST 13 MB 74 MB 140 M REST 13 MB 74 MB 140 M
M E M O R Y ( R S S ) M E M O R Y ( R S S ) Quarkus + GraalVM Quarkus + OpenJDK Best of traditio REST 13 MB 74 MB 140 M REST 13 MB 74 MB 140 M REST+JPA 35 MB 130 MB 218 M REST+JPA 35 MB 130 MB 218 M
S T A R T U P T I M E S T A R T U P T I M E Often frameworks use lazy initialization "started" before all classes are initialized
S T A R T U P T I M E S T A R T U P T I M E Often frameworks use lazy initialization "started" before all classes are initialized T I M E T O F I R S T R E Q U E S T T I M E T O F I R S T R E Q U E S T
T I M E T O F I R S T R E Q U E S T T I M E T O F I R S T R E Q U E S T s + GraalVM 0.014 sec Quarkus + OpenJDK 0.75 sec Traditional Cloud-Native Stack 4.3 sec
T I M E T O F I R S T R E Q U E S T T I M E T O F I R S T R E Q U E S T s + GraalVM 0.014 sec Quarkus + OpenJDK 0.75 sec Traditional Cloud-Native Stack 4.3 sec JPA s + GraalVM 0.055 sec Quarkus + OpenJDK 2.5 sec Traditional Cloud-Native Stac
D E V E L O P E R ' S J O Y ? D E V E L O P E R ' S J O Y ?
Show me! Demo #2
H O W I T W O R K S H O W I T W O R K S
*.class QUARKUS Maven/Gradle plugin optimized jar JVM native executable
T R A D I T I O N A L A P P T R A D I T I O N A L A P P S E R V E R S E R V E R • Thousands of classes run only during the boot • Later unused • Still occupy memory XML parsers, annotation lookups, management model, ...
Recommend
More recommend