Matheus Cruz, matheuscruz.dev
Desbravando o Quarkus: Criando extensões para a sua aplicação nativa de nuvem
JUG Vale
1
Quarkus?
3
An Open Source
stack to write Java apps
Cloud Native,
Microservices/Monolithic,
Serverless
4
Quarkus Extensions
RESTEasy
Netty
Hibernate ORM
Hibernate Validator
MP OpenAPI
MP JWT
Eclipse Vert.X
Agroal (conn pool)
Narayana JTA
MP Reactive Messaging
Apache Camel
...
Quarkus Core
Arc (DI)
Jandex
Gizmo
Graal SDK
JDK JIT - HotSpot
AOTC - GraalVM Native Image
Quarkus Extensions
Integrar com outras extensōes
DevUI
Suportar o uso da sua biblioteca em imagens nativa
DevService
6
Por que criar uma extensão?
Framework
Framework
Build time augmentation toolkit
9
Como isso funciona?
Maven/Gradle
plugin
Native Executable & Image
JDK Hotspot Runnable & Image
AOT Native Compilation
Bytecode
Runnable java app
native-app
Enhanced Byte
10
📦
🔎
📄
⚙️
Build
Other frameworks
Read configuration, classpath scanning, …, start
11
🔎
📄
⚙️
🚀
Quarkus
Read configuration, classpath scanning, …, package
📦
start
12
DEMO
Download books for free!
Obrigado.
14
15
Agenda
16
Agenda
17
Agenda
18
Agenda
Emmanuel Bernard
Dr. Clement Escoffier
19
Who are we?
A cohesive platform for optimized developer joy:
20
Benefit No. 1: Developer Joy
21
Benefit No. 2: Supersonic Subatomic Java
*Memory (RSS) in Megabytes, tested on a single-core machine
Quarkus + Native
(via GraalVM)
12 MB
Quarkus + JVM
(via OpenJDK)
73 MB
Traditional �Cloud-Native Stack
136 MB
REST*
22
Benefit No. 2: Supersonic Subatomic Java
Quarkus + Native
(via GraalVM)
12 MB
Quarkus + JVM
(via OpenJDK)
73 MB
Traditional �Cloud-Native Stack
136 MB
Quarkus + Native (via GraalVM) 0.016 Seconds
Quarkus + JVM (via OpenJDK) 0.943 Seconds
Traditional Cloud-Native Stack 4.3 Seconds
23
Benefit No. 2: Supersonic Subatomic Java
REST + CRUD*
Quarkus + Native
(via GraalVM)
28 MB
Quarkus + JVM
(via OpenJDK)
145 MB
Traditional �Cloud-Native Stack
209 MB
*Memory (RSS) in Megabytes, tested on a single-core machine
24
Benefit No. 2: Supersonic Subatomic Java
Boot + First Response Time (in seconds)
Quarkus + Native (via GraalVM) 0.016 Seconds
REST
REST + CRUD
Quarkus + JVM (via OpenJDK) 0.943 Seconds
Quarkus + Native (via GraalVM) 0.042 Seconds
Quarkus + JVM (via OpenJDK) 2.033 Seconds
Traditional Cloud-Native Stack 9.5 Seconds
Traditional Cloud-Native Stack 4.3 Seconds
Time to first response
25
Benefit No. 3: Unifies Imperative and Reactive
@Inject
SayService say;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return say.hello();
}
@Inject @Channel(”kafka”)
Publisher<String> reactiveSay;
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public Publisher<String> stream() {
return reactiveSay;
}
26
Benefit No. 4: Best of Breed Frameworks & Standards
Quarkus provides a cohesive, fun to use, full-stack framework by leveraging a growing list of over fifty best-of-breed libraries that you love and use. All wired on a standard backbone.
27
Quarkus Extensions
RESTEasy
Netty
Hibernate
Spring Compat.
MP OpenAPI
MP JWT
Eclipse Vert.X
Agroal (conn pool)
Narayana JTA
MP Reactive Messaging
Apache Camel
...
Quarkus Core
Arc (DI)
Jandex
Gizmo
Graal SDK
JDK JIT - HotSpot
AOTC - GraalVM Native Image
Developer Joy
Supersonic Subatomic Java
Unifies
imperative and reactive
Best of breed
libraries and standards
28
Quarkus Benefits
29
DEMO
30
Quarkus Extensions
RESTEasy
Netty
Hibernate ORM
Hibernate Validator
MP OpenAPI
MP JWT
Eclipse Vert.X
Agroal (conn pool)
Narayana JTA
MP Reactive Messaging
Apache Camel
...
Quarkus Core
Arc (DI)
Jandex
Gizmo
Graal SDK
JDK JIT - HotSpot
AOTC - GraalVM Native Image
31
Full stack
Conclusion
including JPA, Transaction Manager etc
Both in live reload and native executable
Massive productivity wins
Simplified configuration
Microscopic code->test loop
80% common usages made easy
Supersonic. Subatomic. Java.
32
A Kubernetes Native Java stack tailored for GraalVM & OpenJDK HotSpot,
crafted from the best of breed Java libraries and standards
33
Supersonic
Fast.
Blazing fast to start.
Millisecond fast!
34
Subatomic
Improve memory consumption.
Increase deployment density.
35
Java
Based on a framework and spec you love
Blazing fast-hot-reload
WHY QUARKUS?
QUARK: elementary particle / US: hardest thing in computer science
WHY QUARKUS?
INTRODUCTION
WHAT IS CLOUD-NATIVE?
Evolving Java for Serverless
and Containers
Java and its limits
How is this possible?
43
Monolith, Microservices, & Serverless
44
Event Driven & Reactive
Introduction to Quarkus
&
Kube-Native Java
Developing native applications�for SubstrateVM is painful
Quarkus enables Java developers to easily use the most popular frameworks and standards directly on SubstrateVM without any hassle
47
How to build an ecosystem
Network effect in complexity
QUARKUS MAKES JAVA RUN BETTER IN CONTAINER AND SERVERLESS ENVIRONMENTS
49
1. Showing a response to a stimulus.
2. Acting in response to a situation rather than creating or controlling it.
“
~ Oxford English Dictionary
From monolith to...
50
MONOLITH
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
MICRO
SERVICE
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
Agility, Scalability, Faster Business Reactivity
51
Why go through this pain?
Container platform
App 1
Data
App 2
Data
App 3
Data
App 4
App 5
Data
52
The hidden truth about Java + containers
RSS
Java Heap
Metaspace
Direct
Code
Internal
53
Container platform
Node
NodeJS
NodeJS
NodeJS
NodeJS
NodeJS
NodeJS
NodeJS
Node
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Node
HotSpot
Heap
HotSpot
Heap
HotSpot
Heap
HotSpot
Heap
The hidden truth about Java + containers
54
Container orchestration
Node
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Node
Traditional Cloud-Native Java Stack
Traditional Cloud-Native Java Stack
Traditional Cloud-Native Java Stack
Traditional Cloud-Native Java Stack
Quarkus native deployment
55
The hidden truth about Java + containers
CONTAINER ORCHESTRATION
Node
Node
Traditional Cloud-Native Java Stack
Traditional Cloud-Native Java Stack
Traditional Cloud-Native Java Stack
Traditional Cloud-Native Java Stack
Node
NodeJS
NodeJS
NodeJS
NodeJS
NodeJS
NodeJS
NodeJS
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Go
Node
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
Quarkus
https://developers.redhat.com/blog/2017/03/14/java-inside-docker/
56
Operating System
HTML
Inventory
Promo
Data Access
Enterprise Java was Designed for 3-Tier Architecture
Application Server / JVM
Presentation Logic
Business Logic
Data Access Logic
Javascript
Catalog
Ratings
Web
Cart
Orders
57
Operating System
HTML
Inventory
Promo
Data Access
How Application Services Deployed Java Apps
Application Server / JVM
Javascript
Catalog
Ratings
Web
Cart
Orders
HTML
Inventory
Promo
Data Access
Javascript
Catalog
Ratings
Web
Cart
Orders
58
Container Orchestration
Microservices Changed How We Deploy Apps
HTML
Javascript
HTML
Javascript
Java EE
Data Store
Order
NodeJS
Web
Micro
Profile
Promo
Reactive
Data Grid
Ratings
Spring Boot
Data Grid
Cart
Micro Profile
Data Store
Inventory
Spring Boot
Data Access
Catalog
59
Function as a Service
FaaS & Serverless Changes How We Deploy Apps
In the Future
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Service
Standards
Runtimes
Hardware architectures
Ahead of time compilation
OpenJDK
60
Java on cloud native: a Red Hat journey
QUARK: elementary particle / US: hardest thing in computer science
WHAT IS QUARKUS?
You keep using that word.
I do not think it means what you think it means.
GraalVM
The Enabler
Paradigm Shift
64
The red pill...
Or the blue pill?
Polyglot, Native of JVM, Embeddable
GraalVM
66
JVM CI
Sulong (LLVM)
Truffle
Graal Compiler
Substrate VM
Java HotSpot VM
Closed-world assumption
67
AOTC - GraalVM native image - Dead code elimination
Substrate
VM
Classes
JDK
Classes
JDK
Classes
Substrate
VM
Classes
Java
Application Classes
Java
Application Classes
Native Executable
Not supported
OK with caveats in usage
68
The Dark Side
Not supported
OK with caveats in usage
The interesting parts
69
The Dark Side
JIT - OpenJDK HotSpot
High memory density requirements
High request/s/MB
Fast startup time
Best raw performance (CPU)
Best garbage collectors
Higher heap size usage
Known monitoring tools
Compile Once, Run anywhere
Libraries that only works in standard JDK
AOT - GraalVM native image
Highest memory density requirements
Highest request/s/MB
for low heap size usages
Faster startup time
10s of ms for Serverless
70
When to use which VM with Quarkus
The Cloud Platform
Correlated Terms
71
Some (arbitrary) definition
The communication complexity
72
Consequence of node explosion
12-Factor
Microservices
Service Mesh
(traffic, security, observability)
Messaging
DB
API gateway
Cache
Shared state
(~ session)
APP
73
How can I be Cloud-Native?
HOW QUARKUS WORKS
Optimizations benefit both GraalVM (SVM) and HotSpot
75
Framework Optimizations
76
Serverless Adoption
6.1% Java
https://serverless.com/blog/2018-serverless-community-survey-huge-growth-usage/
62.9% Node.js
20.8% Python
6.4% Go
6.1% Java
3.8% C#
What does a framework do at startup time
77
Move startup time to build time
Do the work once, not at each start
All the bootstrap classes are no longer loaded
Less time to start, less memory used
Less or no reflection nor dynamic proxy
78
Build time benefits
Drives the gathering of metadata needed by GraalVM
Minimize dependencies
Help dead code elimination
100% of the ecosystem supported on GraalVM
79
GraalVM specific benefits
One server to run them all
80
JVM: Build in a different context
Lots of classes to be loaded (SDK and app)
Bytecode verification
JIT warm up time
(*) Has been vastly optimized over time
81
“Slow” to start?(*)
Lots of classes loaded
Class metadata
Statistics for the JIT
Compilation in memory
Disproportionately high for small apps
(*) Has been vastly optimized over time
82
Memory overhead (*)
83
An ahead-of-time, build-time, runtime
Compile
Provision
(curate)
Wiring & Assemble
(augment)
AOT Native Compilation
JDK Hotspot Runnable & Image
Native Executable & Image
app.jar
frameworks
Runnable java app
native-app
84
Substrate VM
Compile
Provision
(curate)
Wiring & Assemble
(augment)
app.jar
native-app
Native
Executable
More is better
MORE QUARKUS
Fast start
Full start
Injection
Mock
GraalVM native image tests
86
@QuarkusTest
public class HelloResourceTest {
@Inject HelloService service;
@Test
public void testService() {
assertEquals( "Hello Quarkus",
service.greeting("Quarkus") );
}
@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then().statusCode(200).body(is("hello"));
}
}
Testing is running
87
@Entity
public class Todo extends PanacheEntity {
// id is inherited
public String title;
public boolean completed;
public String url;
@Column(name = "ordering")
public int order;
public static List<Todo> search(String query) {
return list("completed = ?1 and title like ?2", false, query);
}
public static List<Todo> findNotCompleted() {
return list("completed", false);
}
public static long deleteCompleted() {
return delete("completed", true);
}
}
Define entity with Panache
Convenient methods for lazy people
(aka good devs)
88
@GET
public List<Todo> getAll() {
return Todo.listAll(Sort.by("order"));
}
@POST @Transactional
public void addTodo(@Valid Todo todo) {
return todo.persist();
}
@GET @Path("/search/{query}")
public List<Todo> search(@PathParam("query") @NotBlank String query) {
return Todo.search(query);
}
Accessing entities with Panache
Pagination
Simplified query language
Sorting
89
More Hibernate with Panache
90
ActiveRecord or Repository pattern
@Entity
public class Todo extends PanacheEntity {
// id is inherited
public String title;
public boolean completed;
public String url;
public static List<Todo> findNotCompleted() {
return list("completed", false);
}
}
@Path("/api")
public class TodoResource {
@GET
public List<Todo> getAll() {
return Todo.listAll(Sort.by("order"));
}
}
@Entity
public class Todo {
@Id @GeneratedValue public Long id;
public String title;
public boolean completed;
public String url;
}
@ApplicationScoped
public class TodoRepo extends PanacheRepository<Todo> {
public List<Todo> findNotCompleted() {
return list("completed", false);
}
}
@Path("/api")
public class TodoResource {
@Inject TodoRepo repo;
@GET
public List<Todo> getAll() {
return repo.listAll(Sort.by("order"));
}
}
91
[
{
"name" : "java.lang.Class",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true
},
{
"name" : "java.lang.String",
"fields" : [
{ "name" : "value", "allowWrite" : true },
{ "name" : "hash" }
],
"methods" : [
{ "name" : "<init>", "parameterTypes" : [] },
{ "name" : "<init>", "parameterTypes" : ["char[]"] },
{ "name" : "charAt" },
{ "name" : "format", "parameterTypes" : ["java.lang.String", "java.lang.Object[]"] }
]
},
{
"name" : "java.lang.String$CaseInsensitiveComparator",
"methods" : [
{ "name" : "compare" }
]
}
]
native-image -H:ReflectionConfigurationFiles=/path/to/reflectconfig
-H:IncludeResources=/path/to/resourceconfig
-H:DynamicProxyConfigurationResources=/path/to/proxyconfig
-H:JNIConfigurationFiles=...
--delay-class-initialization-to-runtime=com.amazonaws.services.s3.model.CryptoConfiguration
--no-server
-cp lib/dep.jar,lib/dep2.jar
-jar my-app.jar
The Dark Side
Open API and Swagger UI
Metrics
Health
92
Observability
93
Messaging: Kafka, AMQP, etc
JWT
Keycloak
Secret store
...
94
Security: OIDC, JWT, Keycloak...
@Path(“api”) @Produces(MediaType.TEXT_PLAIN)
public class UsersResource {
@PermitAll
@NoCache
public String publicStuff() {
return “Hello world”;
}
@GET @Path("/admin")
@RolesAllowed("admin")
public String admin() {
return "Secret handshake baby!";
}
}
95
Spring compatibility extensions
Add your own dependency
Write your own extension
YES
96
Can I add my dependencies?
The best way to predict it is to invent it
FUTURE
Developer Joy
Cloud Native
98
Developer Joy and Cloud Native
Serverless
Foundation Layer
99
Foundation Layer and Serverless
Thank you.
100
@quarkusio
https://quarkusio.zulipchat.com
https://quarkus.io
101
Please paste slides to the end that you would like to have edited into this style.
OK FINE, EDIT THIS DECK
Be advised: changes made to slides in this deck will also change linked slides in other decks.
!
102
NEUTRON BLUE
ELECTRON GREEN
PROTON RED
#4695EB
#FF004A
#9AFF2D
Emmanuel Bernard, Red Hat
Dr. Clement Escoffier, Red Hat
The “Ops” side
103
Emmanuel Bernard, Red Hat
Dr. Clement Escoffier, Red Hat
Conclusion
104