Publicidad

jLove 2020 - Micronaut and graalvm: The power of AoT

Staff Software Engineer en VMware
4 de Dec de 2020
Publicidad

Más contenido relacionado

Publicidad

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

Publicidad

jLove 2020 - Micronaut and graalvm: The power of AoT

  1. Micronaut and GraalVM: The power of AoT Iván López (@ilopmar)
  2. Iván López @ilopmar Iván López (@ilopmar)
  3. Iván López @ilopmar GraalVM - Substrate VM: compile Java applications to native binaries - https://www.graalvm.org
  4. Iván López @ilopmar - Reflection (with config) - Dynamic class loading (with config) - Dynamic proxy (with config) - Unsafe Memory Access (partially) - Class initializers (supported) - InvokeDynamic bytecode and method handlers (partially) - Lambda (supported) - Finalizers (not supported) - Threads (partially) Limitations
  5. Iván López @ilopmar - Framework for microservices in the JVM - Ultra-lightweight & reactive (Netty-based) - Java, Groovy & Kotlin - Ahead of Time compilation (AoT) - No reflection, no runtime proxies - Fast startup - Low memory footprint - Natively Cloud Native - GraalVM support (improved a lot in Micronaut 2.x) Micronaut
  6. Iván López @ilopmar $ mn create-app basic-app --features=graalvm Create an application with GraalVM support
  7. Iván López @ilopmar $ mn create-app basic-app --features=graalvm Create an application with GraalVM support Micronaut 2.2 (Gradle & Maven)
  8. Iván López @ilopmar $ ./gradlew nativeImage $ ./mvnw package -Dpackaging=native-image Create native-image $ ./gradlew dockerBuildNative $ ./mvnw package -Dpackaging=docker-native
  9. Iván López @ilopmar - Composable native-image.properties How does it work?
  10. Iván López @ilopmar # 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 Micronaut includes everything (I)
  11. Iván López @ilopmar @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); } } Micronaut includes everything (II)
  12. Iván López @ilopmar 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"); } } Micronaut includes everything (III)
  13. Iván López @ilopmar Micronaut includes everything (IV)
  14. Iván López @ilopmar Micronaut includes everything (V)
  15. Iván López @ilopmar - @Introspected - @TypeHint - @ReflectiveAccess - GraalTypeElementVisitor -reflect-config.json -resource-config.json (* Micronaut 2.0) Support in Micronaut
  16. DEMO
  17. Iván López @ilopmar Demo
  18. Iván López @ilopmar 14 vs 140 MB What about memory?
  19. Iván López @ilopmar - Create a native image takes a lot of time - And it needs a lot of RAM - GraalVM changes so fast (and they break things)... - ...and so we do ;-) - We used Travis for testing Micronaut (now Github Actions), but... - ...Travis has a limit for RAM - We needed another way... So… how do we test this?
  20. Iván López @ilopmar - Scheduled jobs every hour (2.2.x / 2.3.x) - Only run if new commits in Micronaut or GraalVM - Compile GraalVM from source code (JDK8 & JDK 11) - Also test GraalVM stable - Create native images for test Micronaut applications - Run native images and execute functional tests - https://github.com/micronaut-graal-tests - https://gitlab.com/micronaut-projects/micronaut-graal-tests Tests using Gitlab CI
  21. Iván López @ilopmar - Basic application: DI, POJO serialization, reactive types, HTTP Client - Cache - Micronaut function - Service discovery: Consul & Eureka - Static resources & views: Handlebars, Thymeleaf, Freemarker, Velocity, Pebble - Management & Metrics endpoints - Distributed tracing: Zipkin - RabbitMQ: Fire-and-forget & RPC - MQTT Test applications Micronaut-GraalVM
  22. Iván López @ilopmar - 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 & Liquibase - AWS app & function - gRPC Test applications Micronaut-GraalVM
  23. Iván López @ilopmar Gitlab CI
  24. Iván López @ilopmar Gitlab CI
  25. Iván López @ilopmar Gitlab CI 2 years ago
  26. Iván López @ilopmar x8 - JDK 8 & 11 - 2.3.x & 2.2.x - GraalVM dev/stable Gitlab CI today
  27. Iván López @ilopmar Gitlab CI
  28. Iván López @ilopmar Use cases
  29. Iván López @ilopmar - https://launch.micronaut.io (Google Cloud) - Micronaut CLI: Linux, MacOS, Windows - AWS Lambda + Custom runtime Use cases
  30. Iván López @ilopmar GraalVM is a new and interesting technology Micronaut AoT is the perfect match Out-of-the-box support in Micronaut New improvements in every release Fast startup & low memory footprint Developers happy and productive Summary
  31. Thank you! @ilopmar lopez.ivan@gmail.com https://github.com/ilopmar Iván López https://bit.ly/jlove-micronaut Questions?
Publicidad