Successfully reported this slideshow.
Your SlideShare is downloading. ×

jLove 2020 - Micronaut and graalvm: The power of AoT

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Enterprise(d) Tomcat & httpd
Enterprise(d) Tomcat & httpd
Loading in …3
×

Check these out next

1 of 34 Ad

jLove 2020 - Micronaut and graalvm: The power of AoT

Download to read offline

Micronaut is a reflection-free app-development framework that uses ahead-of-time (AoT) compilation to precompute everything in the application, paving the way for lightning-fast startup times and significantly reduced memory consumption. What if I told you that you can reduce the startup time by orders of magnitude? And what if you could reduce memory consumption even more?

GraalVM is a new universal virtual machine from Oracle that supports a polyglot runtime environment. GraalVM has the ability to compile Java applications down to native machine code, making it an ideal partner for Micronaut.

In this talk you will learn how you can take advantage of GraalVM's powerful capabilities to convert your Micronaut applications to run as binary native images.

Micronaut is a reflection-free app-development framework that uses ahead-of-time (AoT) compilation to precompute everything in the application, paving the way for lightning-fast startup times and significantly reduced memory consumption. What if I told you that you can reduce the startup time by orders of magnitude? And what if you could reduce memory consumption even more?

GraalVM is a new universal virtual machine from Oracle that supports a polyglot runtime environment. GraalVM has the ability to compile Java applications down to native machine code, making it an ideal partner for Micronaut.

In this talk you will learn how you can take advantage of GraalVM's powerful capabilities to convert your Micronaut applications to run as binary native images.

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to jLove 2020 - Micronaut and graalvm: The power of AoT (20)

Advertisement

More from Iván López Martín (20)

Recently uploaded (20)

Advertisement

jLove 2020 - Micronaut and graalvm: The power of AoT

  1. 1. Micronaut and GraalVM: The power of AoT Iván López (@ilopmar)
  2. 2. Iván López @ilopmar Iván López (@ilopmar)
  3. 3. Iván López @ilopmar GraalVM - Substrate VM: compile Java applications to native binaries - https://www.graalvm.org
  4. 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. 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. 6. Iván López @ilopmar $ mn create-app basic-app --features=graalvm Create an application with GraalVM support
  7. 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. 8. Iván López @ilopmar $ ./gradlew nativeImage $ ./mvnw package -Dpackaging=native-image Create native-image $ ./gradlew dockerBuildNative $ ./mvnw package -Dpackaging=docker-native
  9. 9. Iván López @ilopmar - Composable native-image.properties How does it work?
  10. 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. 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. 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. 13. Iván López @ilopmar Micronaut includes everything (IV)
  14. 14. Iván López @ilopmar Micronaut includes everything (V)
  15. 15. Iván López @ilopmar - @Introspected - @TypeHint - @ReflectiveAccess - GraalTypeElementVisitor -reflect-config.json -resource-config.json (* Micronaut 2.0) Support in Micronaut
  16. 16. DEMO
  17. 17. Iván López @ilopmar Demo
  18. 18. Iván López @ilopmar 14 vs 140 MB What about memory?
  19. 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. 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. 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. 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. 23. Iván López @ilopmar Gitlab CI
  24. 24. Iván López @ilopmar Gitlab CI
  25. 25. Iván López @ilopmar Gitlab CI 2 years ago
  26. 26. Iván López @ilopmar x8 - JDK 8 & 11 - 2.3.x & 2.2.x - GraalVM dev/stable Gitlab CI today
  27. 27. Iván López @ilopmar Gitlab CI
  28. 28. Iván López @ilopmar Use cases
  29. 29. Iván López @ilopmar - https://launch.micronaut.io (Google Cloud) - Micronaut CLI: Linux, MacOS, Windows - AWS Lambda + Custom runtime Use cases
  30. 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. 31. Thank you! @ilopmar lopez.ivan@gmail.com https://github.com/ilopmar Iván López https://bit.ly/jlove-micronaut Questions?

×