Q U A R K U S & G R A A L V M booting at supersonic speed, subatomic size

@SanneGrinovero 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 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 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 • GraalVM & native images • Quarkus • Joy of live coding • How ?!? N A T I V E I M A G E ? L E T ' S S E E O N E I 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 . . . 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

Application JDK API 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 • Static analysis • Closed world assumption • Dead code elimination: classes, fields, methods, branches 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 I M A G E S D Y N A M I N C C L A S S L O A D I N G D Y N A M I N C 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 + other native VM interfaces J V M T I , J M X + other native VM interfaces

No agents 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 + 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

No: Security Manager No: finalize() (deprecated anyway) Limited: InvokeDynamic and MethodHandles ! lim R E F L E C T I O N ited

Requires registration via native-image CLI/API ! lim M O R E . . . ited

Need to register in advance also: • Dynamic proxies • Resources being loaded • JNI, Unsafe Memory Access, ... Very spec S T A T I C I N I T ial Attempts to run them at build time Very spec S T A T I C I N I T ial Attempts to run them at build time • Resolve classes, run "safe" static initializers Very spec S T A T I C I N I T ial 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 spec S T A T I C I N I T ial 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 spec S T A T I C I N I T ial • 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 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 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 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 C O D E . . . O K L E T ' S A D A P T M Y 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 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 O R M ?

I M P A C T O N H I B E R N A T E O R M ?

Mindmap #3 W H A T I S Q U A R K U S T O O L K I T and F R A M E W O R K for writing Java applications

T O O L K I T and F R A M E W O R K for writing Java1 applications

1) and Kotlin 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 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 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

ECLIPSE VERT.X HIBERNATE RESTEASY NETTY

KUBERNETES JAEGER PROMETHEUS APACHE KAFKA INFINISPAN Unifies I M P E R A T I V E and R E A C T I V E

@Inject @Inject @Stream("kafka") SayService say; Publisher reactiveSay

@GET @GET @Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.SERVER_SEN public String hello() { public Publisher 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

 Small size on disk ✓ Small container images 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

 Small size on disk ✓ Small container images

 Fast boot time ✓ Instant scale up

 Low RSS1 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

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 )

Quarkus + GraalVM Quarkus + OpenJDK Best of traditio M E M O R Y ( R S S )

Quarkus + GraalVM Quarkus + OpenJDK Best of traditio

RESTREST 1313 MBMB 7474 MBMB 140140 MM M E M O R Y ( R S S )

Quarkus + GraalVM Quarkus + OpenJDK Best of traditio

RESTREST 1313 MBMB 7474 MBMB 140140 MM

REST+JPAREST+JPA 3535 MBMB 130130 MBMB 218218 MM 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 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 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 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 ?

Show me! Demo #2 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 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, ... Quarkus: B U I L D T I M E B O O T As much work as possible done at build time • Application model validation • Configuration parsing • Annotation lookup and evaluation • ... Output: recorded wiring bytecode W i r i n g c o d e i n v o c a t i o n Flexible static initializer main() OR preferred access to files, sockets, etc. C o r e + E x t e n s i o n s Q U A R K U S E X T E N S I O N S • Required for frameworks that hit GraalVM limitations • Opportunity to highly optimise also for JVM • Code strictly separates build time analysis and runtime: extemely lean output! W H A T C A N A N E X T E N S I O N D O ? Invoke Quarkus helpers to dynamically • Interact with the GraalVM compiler needs • Generate "Bootstrap at build" initializers • Much much more... and evolving Q U A R K U S W R A P U P

✓Good old Java ✓More fun, less weight ✓Can go small as Go, works great on JVM too Makes Java the #1 choice for the cloud and serverless V E R S I O N 0 . X . Y ? Early days! V E R S I O N 0 . X . Y ? Early days! Yet based on proven libraries T H A N K Y O U ! Q & A ✓Docs & guides: quarkus.io ✓Chat: quarkusio.zulipchat.com ✓Quickstarts: github.com/quarkusio/quarkus-quick ✓Stack Overflow tag: quarkus ✓Twitter: @quarkusio Q U A R K U S C H E A T S H E E T S https://quarkus.io/get-started/

$ mvn io.quarkus:quarkus-maven-plugin:0.13.3:create \ -DprojectGroupId=org.acme \ -DprojectArtifactId=quarkus-hello \ -DclassName="org.acme.quickstart.GreetingResource" \ -Dpath="/hello" $ mvn package $ java -jar target/*-runner.jar INFO [io.quarkus] (main) Quarkus 0.11.0 started in 0.729s. INFO [io.quarkus] (main) Installed features: [cdi, resteasy] N A T I V E https://quarkus.io/guides/building-native-image-guide

$ mvn package -Pnative $ ls -lh target/*-runner -rwxrwxr-x. 1 sanne sanne 17M Mar 20 14:39 target/quarkus-hello $ ./target/*-runner INFO [io.quarkus] (main) Quarkus 0.13.3 started in 0.003s. INFO [io.quarkus] (main) Installed features: [cdi, resteasy] D E V M O D E https://quarkus.io/guides/getting-started-guide

$ mvn compile quarkus:dev T E S T I N G https://quarkus.io/guides/getting-started-guide#testing

@QuarkusTest runner JUnit 4 or 5

$ mvn clean test T E S T I N G N A T I V E https://quarkus.io/guides/building-native-image-guide.html#testing-the-native- executable @SubstrateTest runner

$ mvn clean verify -Pnative A D D A N E X T E N S I O N https://quarkus.io/guides/maven-tooling.html

$ mvn quarkus:add-extension -Dextensions=hibernate-orm-panache P A N A C H E https://quarkus.io/guides/hibernate-orm-panache-guide

Makes simple Hibernate ORM easy

@Entity public class Person extends PanacheEntity { public String name; public LocalDate birth; public PersonStatus status; } P A N A C H E P E R S I S T https://quarkus.io/guides/hibernate-orm-panache-guide

// Create a person Person person = new Person(); person.name = "Stef";

// Persist and delete person.persist(); person.delete(); O T H E R E X T E N S I O N S Discover them

https://quarkus.io/guides/maven-tooling.html

$ mvn quarkus:list-extensions ... Available extensions: ... * Hibernate ORM (io.quarkus:quarkus-hibernate-orm) * Hibernate ORM with Panache (io.quarkus:quarkus-hibernate-orm-panache) * Hibernate Validator (io.quarkus:quarkus-hibernate-validator) ... O T H E R E X T E N S I O N S Contribute them!

https://github.com/quarkusio

✓ASL2 ✓Open community