1 of 104

Matheus Cruz, matheuscruz.dev

Desbravando o Quarkus: Criando extensões para a sua aplicação nativa de nuvem

JUG Vale

1

2 of 104

Quarkus?

3 of 104

3

An Open Source

stack to write Java apps

Cloud Native,

Microservices/Monolithic,

Serverless

4 of 104

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

5 of 104

Quarkus Extensions

6 of 104

Integrar com outras extensōes

DevUI

Suportar o uso da sua biblioteca em imagens nativa

DevService

6

Por que criar uma extensão?

7 of 104

Framework

8 of 104

Framework

Build time augmentation toolkit

9 of 104

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 of 104

10

📦

🔎

📄

⚙️

Build

Other frameworks

Read configuration, classpath scanning, …, start

11 of 104

11

🔎

📄

⚙️

🚀

Quarkus

Read configuration, classpath scanning, …, package

📦

start

12 of 104

12

DEMO

13 of 104

Download books for free!

14 of 104

Obrigado.

14

15 of 104

15

  • Insert your agenda items
    • And sub-items
  • Here
  • And Here
  • And here
    • Microservices
    • Container Platforms
    • Serverless
  • Go get ‘em, Tiger

Agenda

16 of 104

16

  • Insert your agenda items
    • And sub-items
  • Here
  • And Here
  • And here
    • Microservices
    • Container Platforms
    • Serverless
  • Go get ‘em, Tiger

Agenda

17 of 104

17

  • Insert your agenda items
    • And sub-items
  • Here
  • And Here
  • And here
    • Microservices
    • Container Platforms
    • Serverless
  • Go get ‘em, Tiger

Agenda

18 of 104

18

  • Insert your agenda items
    • And sub-items
  • Here
  • And Here
  • And here
    • Microservices
    • Container Platforms
    • Serverless
  • Go get ‘em, Tiger

Agenda

19 of 104

Emmanuel Bernard

Dr. Clement Escoffier

19

Who are we?

20 of 104

A cohesive platform for optimized developer joy:

  • Zero config, live reload in the blink of an eye
  • Based on standards, but not limited
  • Unified configuration
  • Streamlined code for the 80% common usages, flexible for the 20%
  • No hassle native executable generation

20

Benefit No. 1: Developer Joy

21 of 104

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 of 104

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 of 104

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 of 104

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 of 104

  • Combine both Reactive and imperative development in the same application
  • Use the technology that fits your use-case
  • Key for reactive systems based on event driven apps

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 of 104

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 of 104

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

28 of 104

Developer Joy

Supersonic Subatomic Java

Unifies

imperative and reactive

Best of breed

libraries and standards

28

Quarkus Benefits

29 of 104

29

DEMO

30 of 104

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 of 104

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

32 of 104

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 of 104

33

Supersonic

Fast.

Blazing fast to start.

Millisecond fast!

34 of 104

34

Subatomic

Improve memory consumption.

Increase deployment density.

35 of 104

35

Java

Based on a framework and spec you love

Blazing fast-hot-reload

36 of 104

WHY QUARKUS?

37 of 104

QUARK: elementary particle / US: hardest thing in computer science

WHY QUARKUS?

38 of 104

INTRODUCTION

39 of 104

WHAT IS CLOUD-NATIVE?

40 of 104

Evolving Java for Serverless

and Containers

41 of 104

Java and its limits

42 of 104

How is this possible?

43 of 104

43

Monolith, Microservices, & Serverless

44 of 104

44

Event Driven & Reactive

45 of 104

Introduction to Quarkus

&

Kube-Native Java

46 of 104

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 of 104

47

How to build an ecosystem

Network effect in complexity

48 of 104

QUARKUS MAKES JAVA RUN BETTER IN CONTAINER AND SERVERLESS ENVIRONMENTS

49 of 104

49

1. Showing a response to a stimulus.

2. Acting in response to a situation rather than creating or controlling it.

~ Oxford English Dictionary

50 of 104

From monolith to...

  • 1 monolith ≈ 20 microservices ≈ 200 functions
  • Scale to 1 vs scale to 0
  • Communication pattern

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

51 of 104

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 of 104

  • Startup overhead
    • # of classes, bytecode, JIT
  • Memory overhead
    • # of classes, metadata, compilation

52

The hidden truth about Java + containers

RSS

Java Heap

Metaspace

Direct

Code

Internal

53 of 104

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 of 104

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 of 104

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 of 104

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 of 104

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 of 104

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 of 104

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

60 of 104

Standards

  • Java EE streamlining
  • Eclipse MicroProfile

Runtimes

  • WildFly on OpenShift

Hardware architectures

  • Raspberry Pi and Plug Computer
  • Android

Ahead of time compilation

  • Lead gcj
  • Looked at Dalvik, Avian, Excelsior JET

OpenJDK

  • Container ergonomics
  • JVM metadata reduction

60

Java on cloud native: a Red Hat journey

61 of 104

QUARK: elementary particle / US: hardest thing in computer science

WHAT IS QUARKUS?

62 of 104

You keep using that word.

I do not think it means what you think it means.

GraalVM

The Enabler

63 of 104

Paradigm Shift

64 of 104

64

The red pill...

Or the blue pill?

65 of 104

Polyglot, Native of JVM, Embeddable

GraalVM

66 of 104

66

JVM CI

Sulong (LLVM)

Truffle

Graal Compiler

Substrate VM

Java HotSpot VM

67 of 104

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

68 of 104

Not supported

  • Dynamic classloading
  • InvokeDynamic & Method handles
  • Finalizer
  • Security manager
  • JVMTI, JMX, native VM Interfaces

OK with caveats in usage

  • Reflection (manual list)
  • Dynamic proxy (manual list)
  • JNI (manual list)
  • Static initializers (eager)
  • Lambda, Threads (OK, pfff!)
  • References (similar)

68

The Dark Side

69 of 104

Not supported

  • Dynamic classloading
  • InvokeDynamic & Method handles
  • Finalizer
  • Security manager
  • JVMTI, JMX, native VM Interfaces

OK with caveats in usage

  • Reflection (manual list)
  • Dynamic proxy (manual list)
  • JNI (manual list)
  • Static initializers (eager)
  • Lambda, Threads (OK, pfff!)
  • References (similar)

The interesting parts

69

The Dark Side

70 of 104

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

71 of 104

The Cloud Platform

  • Opinionated platform
  • Unreliability (kill and restart)
  • Infinite & auto scalability
  • Instant resource access
  • Shifting resource location

Correlated Terms

  • Microservices
  • 12-Factor app
  • Container platforms
  • DevOps

71

Some (arbitrary) definition

72 of 104

The communication complexity

  • Blocking calls
  • Non-blocking API calls
  • Messages
  • Messages with data
  • Back pressure

72

Consequence of node explosion

73 of 104

12-Factor

  • Delegate tasks to backend services
  • Externalized env configuration

Microservices

  • Independence
  • Apps opened to input/output
  • App focuses on how not where

Service Mesh

(traffic, security, observability)

Messaging

DB

API gateway

Cache

Shared state

(~ session)

APP

73

How can I be Cloud-Native?

74 of 104

HOW QUARKUS WORKS

75 of 104

Optimizations benefit both GraalVM (SVM) and HotSpot

  • Moved as much as possible to build phase
  • Minimized runtime dependencies
  • Maximize dead code elimination
  • Introduced clear metadata contracts
  • Spectrum of optimization levels�(all some no runtime reflection)

75

Framework Optimizations

76 of 104

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#

77 of 104

What does a framework do at startup time

  • Parse config files
  • Classpath & classes scanning
    • for annotations, getters or other metadata
  • Build framework metamodel objects
  • Prepare reflection and build proxies
  • Start and open IO, threads etc

77

Move startup time to build time

78 of 104

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

79 of 104

Drives the gathering of metadata needed by GraalVM

  • based on framework knowledge
  • Classes using reflection, resources, etc
  • No need for agent + prerun, long JSON metadata or manual command lines

Minimize dependencies

Help dead code elimination

100% of the ecosystem supported on GraalVM

79

GraalVM specific benefits

80 of 104

One server to run them all

  • Throughput >> CPU >> Memory
  • Multi-thread / Multi-core

80

JVM: Build in a different context

81 of 104

Lots of classes to be loaded (SDK and app)

Bytecode verification

JIT warm up time

  • Interpreted is ~10 to 20x slower
  • Until adaptive compilation kicks in

(*) Has been vastly optimized over time

81

“Slow” to start?(*)

82 of 104

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 of 104

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 of 104

84

Substrate VM

Compile

Provision

(curate)

Wiring & Assemble

(augment)

app.jar

native-app

Native

Executable

85 of 104

More is better

MORE QUARKUS

86 of 104

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 of 104

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

88 of 104

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

89 of 104

Pagination

Simplified query language

Sorting

89

More Hibernate with Panache

90 of 104

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 of 104

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

92 of 104

Open API and Swagger UI

Metrics

Health

92

Observability

93 of 104

93

Messaging: Kafka, AMQP, etc

94 of 104

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 of 104

95

Spring compatibility extensions

96 of 104

Add your own dependency

  • Works on the JVM (OpenJDK)
  • May work on AOT (GraalVM)

Write your own extension

  • Like add your dependency plus…
  • Build time startup and memory improvements
  • Better dead code elimination
  • Developer Joy

YES

96

Can I add my dependencies?

97 of 104

The best way to predict it is to invent it

FUTURE

98 of 104

Developer Joy

  • Start from nothing
    • Download CLI and go
    • Download Image
  • Remote dev mode
  • S2I chains
  • Built in tooling to deploy and setup OpenShift

Cloud Native

  • Easy to use client APIs for
    • RDG service
    • RH-SSO service
    • AMQ Streams
  • MicroProfile
  • Reactive

98

Developer Joy and Cloud Native

99 of 104

Serverless

  • Function framework
  • Tool chain to help deploy functions

Foundation Layer

  • Foundational layer
  • “The Application Environment”
  • Camel-K
  • Automation
    • Project Submarine
  • Infinispan
  • Keycloak

99

Foundation Layer and Serverless

100 of 104

Thank you.

100

101 of 104

@quarkusio

https://quarkusio.zulipchat.com

https://quarkus.io

101

102 of 104

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

103 of 104

Emmanuel Bernard, Red Hat

Dr. Clement Escoffier, Red Hat

The “Ops” side

103

104 of 104

Emmanuel Bernard, Red Hat

Dr. Clement Escoffier, Red Hat

Conclusion

104