SlideShare una empresa de Scribd logo
1 de 47
Descargar para leer sin conexión
Micronaut y GraalVM:
¡Compañeros perfectos!
Iván Lopez - @ilopmar
Iván López @ilopmar
Iván López (@ilopmar)
- Desarrollador Java/Groovy
- Grails & Micronaut en OCI
- Coordinador de @MadridGUG
- Speaker: Devoxx, GeeCon, Commit, ConFoo,
Voxxed Days, RigaDev Days, Spring One 2GX,...
Iván López @ilopmar
GraalVM
- Universal Polyglot VM de Oracle
- Lenguajes de la JVM + Ruby, Python, JS, R
- Graal Compiler / JVMCI
- Truffle
- Substrate VM
Iván López @ilopmar
GraalVM
Iván López @ilopmar
Limitaciones
- Dynamic class loading (con configuración)
- Reflection (con configuración)
- Dynamic proxy (con configuración)
- Unsafe Memory Access (parcialmente)
- Class initializers (soportado)
- InvokeDynamic bytecode y method handlers (parcialmente)
- Lambda (soportado)
- Finalizers (no soportado)
- Threads (parcialmente)
Iván López @ilopmar
¿GraalVM en producción?
Iván López @ilopmar
Micronaut
- Framework para microservicios en la JVM
- Ultra-ligero & reactive (basado en Netty)
- Java, Groovy & Kotlin
- Ahead of Time compilation (AoT)
- Sin reflection ni runtime proxies
- Arranque muy rápido
- Consumo de memoria bajo
- Natively Cloud Native
- Micronaut Data
- Soporte para GraalVM (mejorado en Micronaut 2.0)
Iván López @ilopmar
Crear aplicación con soporte para GraalVM
$ mn create-app basic-app
--features=graalvm
Iván López @ilopmar
Soporte en Micronaut para GraalVM
- Dependencias
- Dockerfile
compileOnly "org.graalvm.nativeimage:svm"
annotationProcessor "io.micronaut:micronaut-graal"
FROM oracle/graalvm-ce:20.1.0-java8 as graalvm
RUN gu install native-image
COPY . /home/app/basic-app
WORKDIR /home/app/basic-app
RUN native-image --no-server -cp build/libs/basic-app-*-all.jar
FROM frolvlad/alpine-glibc
RUN apk update && apk add libstdc++
EXPOSE 8080
COPY --from=graalvm /home/app/basic-app/basic-app /app/basic-app
ENTRYPOINT ["/app/basic-app"]
Iván López @ilopmar
Soporte en Micronaut para GraalVM (II)
- native-image.properties
Args = -H:Name=basic-app 
-H:Class=example.micronaut.Application
Iván López @ilopmar
Native image
native-image 
--no-server 
--class-path build/libs/basic-app-*-all.jar
Iván López @ilopmar
¿Cómo funciona?
- Composable native-image.properties
Iván López @ilopmar
Micronaut incluye todo lo necesario (I)
# inject/native-image.properties
Args = --allow-incomplete-classpath 
-H:EnableURLProtocols=http,https
# http/native-image.properties
Args = -H:IncludeResources=META-INF/http/mime.types
# http-netty/native-image.properties
Args = --initialize-at-run-time=
com.sun.jndi.dns.DnsClient,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.Je
ttyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.JdkNpn
ApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.net
ty.handler.ssl.ReferenceCountedOpenSslClientContext,io.netty.handler.ssl.util.BouncyCastleSelf
SignedCertGenerator,io.netty.handler.ssl.ReferenceCountedOpenSslContext,io.micronaut.buffer.ne
tty.NettyByteBufferFactory,io.netty.handler.ssl.JettyAlpnSslEngine$ClientEngine,io.netty.handl
er.ssl.JettyAlpnSslEngine$ServerEngine,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.ha
ndler.codec.http2.CleartextHttp2ServerUpgradeHandler,io.netty.handler.codec.http2.Http2ServerU
pgradeCodec,io.micronaut.http.netty.channel.converters.EpollChannelOptionFactory,io.micronaut.
http.netty.channel.converters.KQueueChannelOptionFactory,io.micronaut.http.bind.binders.Contin
uationArgumentBinder$Companion,io.micronaut.http.bind.binders.ContinuationArgumentBinder
Iván López @ilopmar
Micronaut incluye todo lo necesario (II)
@AutomaticFeature
final class HibernateFeature implements Feature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
// other drivers...
registerIfPresent(access, "oracle.jdbc.OracleDriver",
Oracle8iDialect.class,
Oracle9iDialect.class,
Oracle10gDialect.class,
Oracle12cDialect.class);
}
}
Iván López @ilopmar
Micronaut incluye todo lo necesario (III)
private void handleOracle(BeforeAnalysisAccess access) {
Class<?> oracleDriver = access.findClassByName(ORACLE_DRIVER);
if (oracleDriver != null) {
registerAllIfPresent(access, "oracle.jdbc.driver.T4CDriverExtension");
registerAllIfPresent(access, "oracle.jdbc.driver.T2CDriverExtension");
registerAllIfPresent(access, "oracle.net.ano.Ano");
registerAllIfPresent(access, "oracle.net.ano.AuthenticationService");
registerAllIfPresent(access, "oracle.net.ano.DataIntegrityService");
registerAllIfPresent(access, "oracle.net.ano.EncryptionService");
registerAllIfPresent(access, "oracle.net.ano.SupervisorService");
ResourcesRegistry resourcesRegistry = getResourceRegistry();
if (resourcesRegistry != null) {
resourcesRegistry.addResources("META-INF/services/java.sql.Driver");
resourcesRegistry.addResources("oracle/sql/converter_xcharset/lx20002.glb");
resourcesRegistry.addResources("oracle/sql/converter_xcharset/lx2001f.glb");
resourcesRegistry.addResources("oracle/sql/converter_xcharset/lx200b2.glb");
resourcesRegistry.addResourceBundles("oracle.net.jdbc.nl.mesg.NLSR");
resourcesRegistry.addResourceBundles("oracle.net.mesg.Message");
}
initializeAtBuildTime(access,
"oracle.net.jdbc.nl.mesg.NLSR_en",
"oracle.jdbc.driver.DynamicByteArray",
"oracle.sql.ConverterArchive",
"oracle.sql.converter.CharacterConverterJDBC",
"oracle.sql.converter.CharacterConverter1Byte"
);
initializeAtRuntime(access, "java.sql.DriverManager");
}
}
Iván López @ilopmar
Micronaut incluye todo lo necesario (IV)
Iván López @ilopmar
Micronaut incluye todo lo necesario (V)
Iván López @ilopmar
Soporte en Micronaut
- @Introspected
- @TypeHint
- @ReflectiveAccess
- GraalTypeElementVisitor
-reflection-config.json
-resource-config.json (* Micronaut 2.0)
Iván López @ilopmar
Depurar errores
[basic-app:15340] classlist: 14,103.05 ms
[basic-app:15340] (cap): 3,947.49 ms
[basic-app:15340] setup: 6,654.60 ms
[basic-app:15340] analysis: 68,716.43 ms
Error: No instances of io.netty.buffer.PooledByteBufAllocator are allowed in the image heap as this
class should be initialized at image runtime. Object has been initialized by the
io.micronaut.buffer.netty.NettyByteBufferFactory class initializer with a trace:
at io.netty.buffer.PooledByteBufAllocator.<init>(PooledByteBufAllocator.java:187)
at io.netty.buffer.PooledByteBufAllocator.<clinit>(PooledByteBufAllocator.java:168)
at io.netty.buffer.ByteBufUtil.<clinit>(ByteBufUtil.java:84)
at io.netty.buffer.ByteBufAllocator.<clinit>(ByteBufAllocator.java:24)
at io.micronaut.buffer.netty.NettyByteBufferFactory.<init>(NettyByteBufferFactory.java:62)
at io.micronaut.buffer.netty.NettyByteBufferFactory.<clinit>(NettyByteBufferFactory.java:44)
. To fix the issue mark io.netty.buffer.PooledByteBufAllocator for build-time initialization with
--initialize-at-build-time=io.netty.buffer.PooledByteBufAllocator or use the the information from
the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation.
. To fix the issue mark io.netty.buffer.PooledByteBufAllocator for build-time initialization with
--initialize-at-build-time=io.netty.buffer.PooledByteBufAllocator or use the the information from
the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation.
Iván López @ilopmar
Depurar errores
Detailed message:
Trace: object io.micronaut.buffer.netty.NettyByteBufferFactory
object io.micronaut.buffer.netty.NettyByteBufferFactory$$Lambda$95116b6497efb4cbd0dc7c4dc91186562d629e7b
object io.micronaut.core.convert.TypeConverter$$Lambda$802fd3b66b18a7bf114f797df2507ad969fcb1c0
object java.util.concurrent.ConcurrentHashMap$Node
object java.util.concurrent.ConcurrentHashMap$Node[]
object java.util.concurrent.ConcurrentHashMap
object io.micronaut.core.convert.DefaultConversionService
method io.micronaut.http.server.netty.NettyHttpResponseFactory.status(HttpStatus, String)
Call path from entry point to io.micronaut.http.server.netty.NettyHttpResponseFactory.status(HttpStatus, String):
at io.micronaut.http.server.netty.NettyHttpResponseFactory.status(NettyHttpResponseFactory.java:61)
at io.micronaut.http.HttpResponseFactory.status(HttpResponseFactory.java:74)
at io.micronaut.http.HttpResponse.serverError(HttpResponse.java:189)
at
io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$exceptionCaughtInternal$3(RoutingInBoundHandler.java:403)
at io.micronaut.http.server.netty.RoutingInBoundHandler$$Lambda$1102/974221323.call(Unknown Source)
at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:140)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
DEMO
Iván López @ilopmar
Demo
Iván López @ilopmar
Demo
Iván López @ilopmar
¿Y la memoria?
11 vs 134 MB
Iván López @ilopmar
Y esto… ¿cómo se testea?
- Crear una imagen nativa tarda mucho
- Y necesita mucha RAM
- GraalVM cambia muy rápido (y a veces rompen cosas)...
- ...y nosotros también ;-)
- Usabamos Travis para Micronaut (ahora Github Actions), pero...
- ...Travis tiene límite para la RAM
- Necesitábamos otra opción.
Iván López @ilopmar
Tests usando Gitlab CI
- Jobs periódicos cada hora (master / 1.3.x)
- Sólo si nuevos commit en Micronaut o GraalVM
- Compila GraalVM desde el código fuente (JDK8 & JDK 11)
- Crea imágenes nativas de aplicaciones de prueba de Micronaut
- Ejecuta tests funcionales
- https://github.com/micronaut-graal-tests
- https://gitlab.com/micronaut-projects/micronaut-graal-tests
Iván López @ilopmar
Aplicaciones de prueba Micronaut-GraalVM
- Basic application: DI, serialización de POJO, tipos reactivos, HTTP Client
- Cache
- Micronaut function
- Service discovery: Consul & Eureka
- Static resources & views: Handlebars, Thymeleaf, Freemarker y Velocity
- Endpoints de Management & Metrics
- Distributed tracing: Zipkin
- RabbitMQ: Fire-and-forget & RPC
Iván López @ilopmar
Aplicaciones de prueba Micronaut-GraalVM
- Security: JWT, Basic Auth, Cookie, Session
- Scheduled jobs
- Micronaut Data JDBC: H2, Postgresql, Oracle, MariaDB, MS SQL Server
- Micronaut Data JPA-Hibernate: H2, Postgresql, MariaDB
- Bean Introspection
- Servlet: Tomcat & Jetty
- Flyway
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI
Iván López @ilopmar
Gitlab CI Pipeline hace 16 meses
Iván López @ilopmar
x2 (master & 1.3.x)
Iván López @ilopmar
Runners propios en AWS
Iván López @ilopmar
Casos de uso
Iván López @ilopmar
Casos de uso
- https://launch.micronaut.io (Google Cloud Functions)
- Micronaut CLI: Linux, MacOS, Windows
- AWS Lambda + Custom runtime
- Azure Functions
Iván López @ilopmar
Resumen
GraalVM es una tecnología
nueva e interesante
Cuidado con las
limitaciones y casos de uso
Soporte out-of-the-box
en Micronaut
Mejoras en cada release Arranque más rápido &
menos consumo de
memoria
Desarrolladores
contentos y productivos
SLIDE TITLE 27 PT ALL CAPS
¡Gracias!
@ilopmar
lopez.ivan@gmail.com
https://github.com/ilopmar
Iván López
https://bit.ly/bcn-jug-micronaut
¿Preguntas?

Más contenido relacionado

Más de Iván López Martín

Más de Iván López Martín (20)

jLove 2020 - Micronaut and graalvm: The power of AoT
jLove 2020 - Micronaut and graalvm: The power of AoTjLove 2020 - Micronaut and graalvm: The power of AoT
jLove 2020 - Micronaut and graalvm: The power of AoT
 
Codemotion Madrid 2020 - Serverless con Micronaut
Codemotion Madrid 2020 - Serverless con MicronautCodemotion Madrid 2020 - Serverless con Micronaut
Codemotion Madrid 2020 - Serverless con Micronaut
 
JConf Perú 2020 - ¡Micronaut en acción!
JConf Perú 2020 - ¡Micronaut en acción!JConf Perú 2020 - ¡Micronaut en acción!
JConf Perú 2020 - ¡Micronaut en acción!
 
JConf Perú 2020 - Micronaut + GraalVM = <3
JConf Perú 2020 - Micronaut + GraalVM = <3JConf Perú 2020 - Micronaut + GraalVM = <3
JConf Perú 2020 - Micronaut + GraalVM = <3
 
JConf México 2020 - Micronaut + GraalVM = <3
JConf México 2020 - Micronaut + GraalVM = <3JConf México 2020 - Micronaut + GraalVM = <3
JConf México 2020 - Micronaut + GraalVM = <3
 
Developing Micronaut Applications With IntelliJ IDEA
Developing Micronaut Applications With IntelliJ IDEADeveloping Micronaut Applications With IntelliJ IDEA
Developing Micronaut Applications With IntelliJ IDEA
 
CommitConf 2019 - Micronaut y GraalVm: La combinación perfecta
CommitConf 2019 - Micronaut y GraalVm: La combinación perfectaCommitConf 2019 - Micronaut y GraalVm: La combinación perfecta
CommitConf 2019 - Micronaut y GraalVm: La combinación perfecta
 
Codemotion Madrid 2019 - ¡GraalVM y Micronaut: compañeros perfectos!
Codemotion Madrid 2019 - ¡GraalVM y Micronaut: compañeros perfectos!Codemotion Madrid 2019 - ¡GraalVM y Micronaut: compañeros perfectos!
Codemotion Madrid 2019 - ¡GraalVM y Micronaut: compañeros perfectos!
 
Greach 2019 - Creating Micronaut Configurations
Greach 2019 - Creating Micronaut ConfigurationsGreach 2019 - Creating Micronaut Configurations
Greach 2019 - Creating Micronaut Configurations
 
VoxxedDays Bucharest 2019 - Alexa, nice to meet you
VoxxedDays Bucharest 2019 - Alexa, nice to meet youVoxxedDays Bucharest 2019 - Alexa, nice to meet you
VoxxedDays Bucharest 2019 - Alexa, nice to meet you
 
JavaDay Lviv 2019 - Micronaut in action!
JavaDay Lviv 2019 - Micronaut in action!JavaDay Lviv 2019 - Micronaut in action!
JavaDay Lviv 2019 - Micronaut in action!
 
CrossDvlup Madrid 2019 - Alexa, encantado de conocerte
CrossDvlup Madrid 2019 - Alexa, encantado de conocerteCrossDvlup Madrid 2019 - Alexa, encantado de conocerte
CrossDvlup Madrid 2019 - Alexa, encantado de conocerte
 
Madrid-GUG - ¡Micronaut en acción!
Madrid-GUG - ¡Micronaut en acción!Madrid-GUG - ¡Micronaut en acción!
Madrid-GUG - ¡Micronaut en acción!
 
Codemotion Madrid 2018 - Microservicios Reactivos con Micronaut
Codemotion Madrid 2018 - Microservicios Reactivos con MicronautCodemotion Madrid 2018 - Microservicios Reactivos con Micronaut
Codemotion Madrid 2018 - Microservicios Reactivos con Micronaut
 
Commit Conf 2018 - Alexa, encantado de conocerte
Commit Conf 2018 - Alexa, encantado de conocerteCommit Conf 2018 - Alexa, encantado de conocerte
Commit Conf 2018 - Alexa, encantado de conocerte
 
Devoxx Belgium 2018 - Micronaut in Action!
Devoxx Belgium 2018 - Micronaut in Action!Devoxx Belgium 2018 - Micronaut in Action!
Devoxx Belgium 2018 - Micronaut in Action!
 
Heisenbug 2018 - Test your Java applications with Spock
Heisenbug 2018 - Test your Java applications with SpockHeisenbug 2018 - Test your Java applications with Spock
Heisenbug 2018 - Test your Java applications with Spock
 
Codemotion Rome 2018 - Functional Java with Vavr
Codemotion Rome 2018 - Functional Java with VavrCodemotion Rome 2018 - Functional Java with Vavr
Codemotion Rome 2018 - Functional Java with Vavr
 
Greach 2018 - I've seen Grails code you wouldn't believe...
Greach 2018 - I've seen Grails code you wouldn't believe...Greach 2018 - I've seen Grails code you wouldn't believe...
Greach 2018 - I've seen Grails code you wouldn't believe...
 
Codemotion 2017 - Sé funcional con Java y Vavr
Codemotion 2017 - Sé funcional con Java y VavrCodemotion 2017 - Sé funcional con Java y Vavr
Codemotion 2017 - Sé funcional con Java y Vavr
 

Último

Proyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptxProyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptx
241521559
 
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
silviayucra2
 
EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial Uninove
FagnerLisboa3
 

Último (10)

International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)
 
Desarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfDesarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdf
 
Proyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptxProyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptx
 
guía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Josephguía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Joseph
 
Trabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíaTrabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnología
 
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
 
EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial Uninove
 
pruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITpruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNIT
 
Presentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxPresentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptx
 
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricGlobal Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
 

Barcelona-JUG - Micronaut y GraalVM: ¡Compañeros perfectos!

  • 1. Micronaut y GraalVM: ¡Compañeros perfectos! Iván Lopez - @ilopmar
  • 2. Iván López @ilopmar Iván López (@ilopmar) - Desarrollador Java/Groovy - Grails & Micronaut en OCI - Coordinador de @MadridGUG - Speaker: Devoxx, GeeCon, Commit, ConFoo, Voxxed Days, RigaDev Days, Spring One 2GX,...
  • 3.
  • 4. Iván López @ilopmar GraalVM - Universal Polyglot VM de Oracle - Lenguajes de la JVM + Ruby, Python, JS, R - Graal Compiler / JVMCI - Truffle - Substrate VM
  • 6. Iván López @ilopmar Limitaciones - Dynamic class loading (con configuración) - Reflection (con configuración) - Dynamic proxy (con configuración) - Unsafe Memory Access (parcialmente) - Class initializers (soportado) - InvokeDynamic bytecode y method handlers (parcialmente) - Lambda (soportado) - Finalizers (no soportado) - Threads (parcialmente)
  • 8.
  • 9. Iván López @ilopmar Micronaut - Framework para microservicios en la JVM - Ultra-ligero & reactive (basado en Netty) - Java, Groovy & Kotlin - Ahead of Time compilation (AoT) - Sin reflection ni runtime proxies - Arranque muy rápido - Consumo de memoria bajo - Natively Cloud Native - Micronaut Data - Soporte para GraalVM (mejorado en Micronaut 2.0)
  • 10. Iván López @ilopmar Crear aplicación con soporte para GraalVM $ mn create-app basic-app --features=graalvm
  • 11. Iván López @ilopmar Soporte en Micronaut para GraalVM - Dependencias - Dockerfile compileOnly "org.graalvm.nativeimage:svm" annotationProcessor "io.micronaut:micronaut-graal" FROM oracle/graalvm-ce:20.1.0-java8 as graalvm RUN gu install native-image COPY . /home/app/basic-app WORKDIR /home/app/basic-app RUN native-image --no-server -cp build/libs/basic-app-*-all.jar FROM frolvlad/alpine-glibc RUN apk update && apk add libstdc++ EXPOSE 8080 COPY --from=graalvm /home/app/basic-app/basic-app /app/basic-app ENTRYPOINT ["/app/basic-app"]
  • 12. Iván López @ilopmar Soporte en Micronaut para GraalVM (II) - native-image.properties Args = -H:Name=basic-app -H:Class=example.micronaut.Application
  • 13. Iván López @ilopmar Native image native-image --no-server --class-path build/libs/basic-app-*-all.jar
  • 14. Iván López @ilopmar ¿Cómo funciona? - Composable native-image.properties
  • 15. Iván López @ilopmar Micronaut incluye todo lo necesario (I) # inject/native-image.properties Args = --allow-incomplete-classpath -H:EnableURLProtocols=http,https # http/native-image.properties Args = -H:IncludeResources=META-INF/http/mime.types # http-netty/native-image.properties Args = --initialize-at-run-time= com.sun.jndi.dns.DnsClient,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.Je ttyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.JdkNpn ApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.net ty.handler.ssl.ReferenceCountedOpenSslClientContext,io.netty.handler.ssl.util.BouncyCastleSelf SignedCertGenerator,io.netty.handler.ssl.ReferenceCountedOpenSslContext,io.micronaut.buffer.ne tty.NettyByteBufferFactory,io.netty.handler.ssl.JettyAlpnSslEngine$ClientEngine,io.netty.handl er.ssl.JettyAlpnSslEngine$ServerEngine,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.ha ndler.codec.http2.CleartextHttp2ServerUpgradeHandler,io.netty.handler.codec.http2.Http2ServerU pgradeCodec,io.micronaut.http.netty.channel.converters.EpollChannelOptionFactory,io.micronaut. http.netty.channel.converters.KQueueChannelOptionFactory,io.micronaut.http.bind.binders.Contin uationArgumentBinder$Companion,io.micronaut.http.bind.binders.ContinuationArgumentBinder
  • 16. Iván López @ilopmar Micronaut incluye todo lo necesario (II) @AutomaticFeature final class HibernateFeature implements Feature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { // other drivers... registerIfPresent(access, "oracle.jdbc.OracleDriver", Oracle8iDialect.class, Oracle9iDialect.class, Oracle10gDialect.class, Oracle12cDialect.class); } }
  • 17. Iván López @ilopmar Micronaut incluye todo lo necesario (III) private void handleOracle(BeforeAnalysisAccess access) { Class<?> oracleDriver = access.findClassByName(ORACLE_DRIVER); if (oracleDriver != null) { registerAllIfPresent(access, "oracle.jdbc.driver.T4CDriverExtension"); registerAllIfPresent(access, "oracle.jdbc.driver.T2CDriverExtension"); registerAllIfPresent(access, "oracle.net.ano.Ano"); registerAllIfPresent(access, "oracle.net.ano.AuthenticationService"); registerAllIfPresent(access, "oracle.net.ano.DataIntegrityService"); registerAllIfPresent(access, "oracle.net.ano.EncryptionService"); registerAllIfPresent(access, "oracle.net.ano.SupervisorService"); ResourcesRegistry resourcesRegistry = getResourceRegistry(); if (resourcesRegistry != null) { resourcesRegistry.addResources("META-INF/services/java.sql.Driver"); resourcesRegistry.addResources("oracle/sql/converter_xcharset/lx20002.glb"); resourcesRegistry.addResources("oracle/sql/converter_xcharset/lx2001f.glb"); resourcesRegistry.addResources("oracle/sql/converter_xcharset/lx200b2.glb"); resourcesRegistry.addResourceBundles("oracle.net.jdbc.nl.mesg.NLSR"); resourcesRegistry.addResourceBundles("oracle.net.mesg.Message"); } initializeAtBuildTime(access, "oracle.net.jdbc.nl.mesg.NLSR_en", "oracle.jdbc.driver.DynamicByteArray", "oracle.sql.ConverterArchive", "oracle.sql.converter.CharacterConverterJDBC", "oracle.sql.converter.CharacterConverter1Byte" ); initializeAtRuntime(access, "java.sql.DriverManager"); } }
  • 18. Iván López @ilopmar Micronaut incluye todo lo necesario (IV)
  • 19. Iván López @ilopmar Micronaut incluye todo lo necesario (V)
  • 20. Iván López @ilopmar Soporte en Micronaut - @Introspected - @TypeHint - @ReflectiveAccess - GraalTypeElementVisitor -reflection-config.json -resource-config.json (* Micronaut 2.0)
  • 21. Iván López @ilopmar Depurar errores [basic-app:15340] classlist: 14,103.05 ms [basic-app:15340] (cap): 3,947.49 ms [basic-app:15340] setup: 6,654.60 ms [basic-app:15340] analysis: 68,716.43 ms Error: No instances of io.netty.buffer.PooledByteBufAllocator are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized by the io.micronaut.buffer.netty.NettyByteBufferFactory class initializer with a trace: at io.netty.buffer.PooledByteBufAllocator.<init>(PooledByteBufAllocator.java:187) at io.netty.buffer.PooledByteBufAllocator.<clinit>(PooledByteBufAllocator.java:168) at io.netty.buffer.ByteBufUtil.<clinit>(ByteBufUtil.java:84) at io.netty.buffer.ByteBufAllocator.<clinit>(ByteBufAllocator.java:24) at io.micronaut.buffer.netty.NettyByteBufferFactory.<init>(NettyByteBufferFactory.java:62) at io.micronaut.buffer.netty.NettyByteBufferFactory.<clinit>(NettyByteBufferFactory.java:44) . To fix the issue mark io.netty.buffer.PooledByteBufAllocator for build-time initialization with --initialize-at-build-time=io.netty.buffer.PooledByteBufAllocator or use the the information from the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation. . To fix the issue mark io.netty.buffer.PooledByteBufAllocator for build-time initialization with --initialize-at-build-time=io.netty.buffer.PooledByteBufAllocator or use the the information from the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation.
  • 22. Iván López @ilopmar Depurar errores Detailed message: Trace: object io.micronaut.buffer.netty.NettyByteBufferFactory object io.micronaut.buffer.netty.NettyByteBufferFactory$$Lambda$95116b6497efb4cbd0dc7c4dc91186562d629e7b object io.micronaut.core.convert.TypeConverter$$Lambda$802fd3b66b18a7bf114f797df2507ad969fcb1c0 object java.util.concurrent.ConcurrentHashMap$Node object java.util.concurrent.ConcurrentHashMap$Node[] object java.util.concurrent.ConcurrentHashMap object io.micronaut.core.convert.DefaultConversionService method io.micronaut.http.server.netty.NettyHttpResponseFactory.status(HttpStatus, String) Call path from entry point to io.micronaut.http.server.netty.NettyHttpResponseFactory.status(HttpStatus, String): at io.micronaut.http.server.netty.NettyHttpResponseFactory.status(NettyHttpResponseFactory.java:61) at io.micronaut.http.HttpResponseFactory.status(HttpResponseFactory.java:74) at io.micronaut.http.HttpResponse.serverError(HttpResponse.java:189) at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$exceptionCaughtInternal$3(RoutingInBoundHandler.java:403) at io.micronaut.http.server.netty.RoutingInBoundHandler$$Lambda$1102/974221323.call(Unknown Source) at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:140) at java.lang.Thread.run(Thread.java:748) at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460) at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193) at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8 Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception Error: Image build request failed with exit status 1
  • 23. DEMO
  • 26. Iván López @ilopmar ¿Y la memoria? 11 vs 134 MB
  • 27. Iván López @ilopmar Y esto… ¿cómo se testea? - Crear una imagen nativa tarda mucho - Y necesita mucha RAM - GraalVM cambia muy rápido (y a veces rompen cosas)... - ...y nosotros también ;-) - Usabamos Travis para Micronaut (ahora Github Actions), pero... - ...Travis tiene límite para la RAM - Necesitábamos otra opción.
  • 28.
  • 29. Iván López @ilopmar Tests usando Gitlab CI - Jobs periódicos cada hora (master / 1.3.x) - Sólo si nuevos commit en Micronaut o GraalVM - Compila GraalVM desde el código fuente (JDK8 & JDK 11) - Crea imágenes nativas de aplicaciones de prueba de Micronaut - Ejecuta tests funcionales - https://github.com/micronaut-graal-tests - https://gitlab.com/micronaut-projects/micronaut-graal-tests
  • 30. Iván López @ilopmar Aplicaciones de prueba Micronaut-GraalVM - Basic application: DI, serialización de POJO, tipos reactivos, HTTP Client - Cache - Micronaut function - Service discovery: Consul & Eureka - Static resources & views: Handlebars, Thymeleaf, Freemarker y Velocity - Endpoints de Management & Metrics - Distributed tracing: Zipkin - RabbitMQ: Fire-and-forget & RPC
  • 31. Iván López @ilopmar Aplicaciones de prueba Micronaut-GraalVM - Security: JWT, Basic Auth, Cookie, Session - Scheduled jobs - Micronaut Data JDBC: H2, Postgresql, Oracle, MariaDB, MS SQL Server - Micronaut Data JPA-Hibernate: H2, Postgresql, MariaDB - Bean Introspection - Servlet: Tomcat & Jetty - Flyway
  • 41. Iván López @ilopmar Gitlab CI Pipeline hace 16 meses
  • 42. Iván López @ilopmar x2 (master & 1.3.x)
  • 45. Iván López @ilopmar Casos de uso - https://launch.micronaut.io (Google Cloud Functions) - Micronaut CLI: Linux, MacOS, Windows - AWS Lambda + Custom runtime - Azure Functions
  • 46. Iván López @ilopmar Resumen GraalVM es una tecnología nueva e interesante Cuidado con las limitaciones y casos de uso Soporte out-of-the-box en Micronaut Mejoras en cada release Arranque más rápido & menos consumo de memoria Desarrolladores contentos y productivos
  • 47. SLIDE TITLE 27 PT ALL CAPS ¡Gracias! @ilopmar lopez.ivan@gmail.com https://github.com/ilopmar Iván López https://bit.ly/bcn-jug-micronaut ¿Preguntas?