q u a r k u s & g r a a l v m
TRANSCRIPT
Q U A R K U S & G R A A L V MQ U A R K U S & G R A A L V Mbooting Hibernate at supersonic speed,
subatomic size
@SanneGrinovero
S A N N E G R I N O V E R OS A N N E G R I N O V E R ODutch, 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 OS A N N E G R I N O V E R ODutch, 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, ...
▪
L E T ' S S E E O N E I NL E T ' S S E E O N E I NA 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
A o T c o m p i l a t i o n w i t h G r a a l V MA o T c o m p i l a t i o n w i t h G r a a l V M
Applicationclasses
JDK APIclasses
SubstrateVMclasses
Staticaly linkedexecutable
A o T c o m p i l a t i o n w i t h G r a a l V MA o T c o m p i l a t i o n w i t h G r a a l V MStatic analysis•Closed world assumption•Dead code elimination: classes, fields, methods, branches
•
L I M I T A T I O N SL I M I T A T I O N SO F G R A A L V M N A T I V EO F G R A A L V M N A T I V E
I M A G E SI M A G E S
D Y N A M I N CD Y N A M I N CC L A S S L O A D I N GC 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 XJ V M T I , J M X+ other native VM interfaces
No agents
JRebel, Byteman, profilers, tracers, ...
J V M T I , J M XJ 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 SM I S C E L L A N E O U S
No: Security Manager
No: finalize() (deprecated anyway)
Limited: InvokeDynamic and MethodHandles
M O R E . . .M O R E . . .
Need to register in advance also:
! limited
Dynamic proxies•Resources being loaded•JNI, Unsafe Memory Access, ...•
S T A T I C I N I TS T A T I C I N I TAttempts to run them at build time
Very special
Resolve classes, run "safe" static initializers•
S T A T I C I N I TS T A T I C I N I TAttempts to run them at build time
Very special
Resolve classes, run "safe" static initializers•Take a snapshot of the produced instances -prune the unreachable ones
•
S T A T I C I N I TS T A T I C I N I TAttempts to run them at build time
Very special
Resolve classes, run "safe" static initializers•Take a snapshot of the produced instances -prune the unreachable ones
•
Include them in the executable•
S T A T I C I N I TS T A T I C I N I TVery special
not allowed: file handles, sockets, threads•careful with other state: timestamps, systemdependent constants, capturing environmentvariables, etc..
•
H O W D O Y O U D I S A B L E AH O W D O Y O U D I S A B L E AF 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 AH O W D O Y O U D I S A B L E AF 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 AH O W D O Y O U D I S A B L E AF 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 YO K L E T ' S A D A P T M YC 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 YO K L E T ' S A D A P T M YC O D E . . .C O D E . . .
All your dependencies need to get compiled too!
ALL DEPENDENCIES
T O O L K I TT O O L K I Tand
F R A M E W O R KF R A M E W O R Kfor writing Java1 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 MD E S I G N E D F O R G R A A L V M
Helps overcome limitations of GraalVM
Embraces them!
E X T E N S I O N SE X T E N S I O N SEach 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 WL 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 EI 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 SayService say; @GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return say.hello(); }
@Inject @Stream("kafka") Publisher<String> reactiveSay @GET @Produces(MediaType.SERVER_SENpublic Publisher<String> stre return reactiveSay; }
C O N T A I N E R F I R S TC 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 TC 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 1) Resident Set Size
More containers withthe same RAM
💾 ✓
🚀 ✓
🔬 ✓
M E A S U R I N G M E M O R YM E A S U R I N G M E M O R Y
= all RAM consumed by the processRSS$ 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
RESTREST 13 MB13 MB 74 MB74 MB 140 M140 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
RESTREST 13 MB13 MB 74 MB74 MB 140 M140 M
REST+JPAREST+JPA 35 MB35 MB 130 MB130 MB 218 M218 M
S T A R T U P T I M ES T A R T U P T I M EOften frameworks use lazy initialization
"started" before all classes are initialized
S T A R T U P T I M ES T A R T U P T I M EOften 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 TT 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 secQuarkus + 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 secQuarkus + OpenJDK 0.75 sec
Traditional Cloud-Native Stack 4.3 sec
JPAs + GraalVM 0.055 sec
Quarkus + OpenJDK 2.5 secTraditional Cloud-Native Stac
T R A D I T I O N A L A P PT R A D I T I O N A L A P PS E R V E RS E R V E R
XML parsers, annotation lookups, managementmodel, ...
Thousands of classes run only during the boot•Later unused•Still occupy memory•
Quarkus:
B U I L D T I M E B O O TB U I L D T I M E B O O TAs much work as possible done at build time
Output: recorded wiring bytecode
Application model validation•Configuration parsing•Annotation lookup and evaluation•...•
W i r i n g c o d e i n v o c a t i o nW i r i n g c o d e i n v o c a t i o nFlexible
static initializerOR
main()preferred access to files,
sockets, etc.
Q U A R K U S E X T E N S I O N SQ U A R K U S E X T E N S I O N SRequired for frameworks that hit GraalVMlimitations
•
Opportunity to highly optimise also for JVM•Code strictly separates build time analysis andruntime: extemely lean output!
•
W H A T C A N A NW H A T C A N A NE X T E N S I O N D O ?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 PQ U A R K U S W R A P U P
Makes Java the #1 choice for the cloud andserverless
Good old Java✓
More fun, less weight✓
Can go small as Go, works great on JVM too✓
T H A N K Y O U !T H A N K Y O U !Q & AQ & A
Docs & guides: ✓ quarkus.ioChat: ✓ quarkusio.zulipchat.comQuickstarts: ✓ github.com/quarkusio/quarkus-quickStack Overflow tag: ✓ quarkusTwitter: ✓ @quarkusio
Q U A R K U S C H E A T S H E E T SQ U A R K U S C H E A T S H E E T Shttps://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 EN A T I V Ehttps://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 ED E V M O D Ehttps://quarkus.io/guides/getting-started-guide
$ mvn compile quarkus:dev
T E S T I N GT E S T I N G
@QuarkusTest runner
JUnit 4 or 5
https://quarkus.io/guides/getting-started-guide#testing
$ mvn clean test
T E S T I N G N A T I V ET E S T I N G N A T I V E
@SubstrateTest runner
https://quarkus.io/guides/building-native-image-guide.html#testing-the-native-executable
$ mvn clean verify -Pnative
A D D A N E X T E N S I O NA D D A N E X T E N S I O Nhttps://quarkus.io/guides/maven-tooling.html
$ mvn quarkus:add-extension -Dextensions=hibernate-orm-panache
P A N A C H EP A N A C H E
Makes simple Hibernate ORM easy
https://quarkus.io/guides/hibernate-orm-panache-guide
@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 TP A N A C H E P E R S I S Thttps://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 SO T H E R E X T E N S I O N SDiscover 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 SO T H E R E X T E N S I O N SContribute them!https://github.com/quarkusio
ASL2✓
Open community✓