Java Module System
How to decrease your application footprint
Leonardo Zanivan - Crossover
Rodrigo Cândido da Silva - Integritas
Java9ModulesSystem
Previous Module System Classpath
After Module System Classpath
JDK9+
SpringModules
jlinkexec
● Spring Boot 2 sample application with REST MVC & JPA
1. Create module-info.java with all the required imports
2. Update third party libs with JDK 9/10 fixes
3. Add new Maven plugin to copy dependencies
4. No Java code change was required
Migrating Spring PetClinic to Java 9 Modules
● Application can still run with explicit classpath after migration
● Use --upgrade-module-path to override problematic modules
● You will find that third party libs are not ready to use modules
Lessons Learned
● Automatic modules can cause issues (naming conflicts, JLink)
○ e.g: JLink was used to create a minimal JRE manually
● Third party libs may require you to open some packages
○ e.g: Hibernate JPA, Spring
● Hello World always work!
Lessons Learned
JDK 10 Highlights
Docker
awareness
JDK-8146115 enhancement
JDK-8186309 enhancement
JDK-8179498 enhancement
Can extract
container-specific
information about number
of CPUs (automatically)
Can extract
container-specific
information about
allocated memory
(automatically)
Attaching to namespace
issue(s) have been resolved!
host PID ⇒ container PID
New JVM flags for Docker support:
-XX:UseContainerSupport (default)
-XX:ActiveProcessorCount
-XX:InitialRAMPercentage
-XX:MaxRAMPercentage
-XX:MinRAMPercentage
Support for Linux only
JDK 10 Highlights
Reduce resource
footprint when
multiple JVMs were
running on the same
physical machine
JEP 310:
Application
Class-Data
Sharing
Pre-Java 10, use of CDS had
been restricted to the
bootstrap class loader only
Improve
startup time
of application Processes/applications can sharing
common class metadata
(class-data), from a shared archive
(CDS archive)
● java.xml.ws (JAX-WS)
● java.xml.bind (JAXB)
● java.activation (JAF)
● java.xml.ws.annotation (JSR 250)
● java.corba (CORBA)
● java.transaction (JTA)
● java.se.ee (Aggregator module)
● jdk.xml.ws (Tools for JAX-WS)
● jdk.xml.bind (Tools for JAXB)
JDK 11 Changes
JEP 320:
Remove Java EE
and CORBA
Modules
Eclipse OpenJ9
● TL;DR; 2x smaller memory
footprint and starts 2x faster
than HotSpot.
● Experimental; AdoptOpenJDK
builds are available.
https://adoptopenjdk.net
github.com/panga/qcon2018-java9modules
Note: JDK 10 Alpine was built from source: https://hub.docker.com/r/panga/openjdk10/
JDK 10 Minimal JRE + Module Application < 100mb
Note: Best case scenario during my tests.
Limit: 2 cpus, 1g memory, JVM_OPTS= Xmx512m
JDK 10 Modules starts 2x faster on Docker
Note: Best case scenario during my tests.
JMeter test plan was used to load application.
JDK 10 Modules has 2x lower footprint on Startup!
JDK 10 Modules has 2x lower footprint after Load!
Note: Best case scenario during my tests.
JMeter test plan was used to load application.
github.com/panga/spring-petclinic-java9modules
@leonardopanga
@rcandidosilva
http://jav.mn/java10

QConSP 2018 - Java Module System

  • 1.
    Java Module System Howto decrease your application footprint Leonardo Zanivan - Crossover Rodrigo Cândido da Silva - Integritas
  • 3.
  • 5.
  • 6.
    After Module SystemClasspath JDK9+
  • 9.
  • 11.
  • 12.
    ● Spring Boot2 sample application with REST MVC & JPA 1. Create module-info.java with all the required imports 2. Update third party libs with JDK 9/10 fixes 3. Add new Maven plugin to copy dependencies 4. No Java code change was required Migrating Spring PetClinic to Java 9 Modules
  • 13.
    ● Application canstill run with explicit classpath after migration ● Use --upgrade-module-path to override problematic modules ● You will find that third party libs are not ready to use modules Lessons Learned
  • 14.
    ● Automatic modulescan cause issues (naming conflicts, JLink) ○ e.g: JLink was used to create a minimal JRE manually ● Third party libs may require you to open some packages ○ e.g: Hibernate JPA, Spring ● Hello World always work! Lessons Learned
  • 15.
    JDK 10 Highlights Docker awareness JDK-8146115enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific information about number of CPUs (automatically) Can extract container-specific information about allocated memory (automatically) Attaching to namespace issue(s) have been resolved! host PID ⇒ container PID New JVM flags for Docker support: -XX:UseContainerSupport (default) -XX:ActiveProcessorCount -XX:InitialRAMPercentage -XX:MaxRAMPercentage -XX:MinRAMPercentage Support for Linux only
  • 16.
    JDK 10 Highlights Reduceresource footprint when multiple JVMs were running on the same physical machine JEP 310: Application Class-Data Sharing Pre-Java 10, use of CDS had been restricted to the bootstrap class loader only Improve startup time of application Processes/applications can sharing common class metadata (class-data), from a shared archive (CDS archive)
  • 17.
    ● java.xml.ws (JAX-WS) ●java.xml.bind (JAXB) ● java.activation (JAF) ● java.xml.ws.annotation (JSR 250) ● java.corba (CORBA) ● java.transaction (JTA) ● java.se.ee (Aggregator module) ● jdk.xml.ws (Tools for JAX-WS) ● jdk.xml.bind (Tools for JAXB) JDK 11 Changes JEP 320: Remove Java EE and CORBA Modules
  • 18.
    Eclipse OpenJ9 ● TL;DR;2x smaller memory footprint and starts 2x faster than HotSpot. ● Experimental; AdoptOpenJDK builds are available. https://adoptopenjdk.net
  • 19.
  • 20.
    Note: JDK 10Alpine was built from source: https://hub.docker.com/r/panga/openjdk10/ JDK 10 Minimal JRE + Module Application < 100mb
  • 21.
    Note: Best casescenario during my tests. Limit: 2 cpus, 1g memory, JVM_OPTS= Xmx512m JDK 10 Modules starts 2x faster on Docker
  • 22.
    Note: Best casescenario during my tests. JMeter test plan was used to load application. JDK 10 Modules has 2x lower footprint on Startup!
  • 23.
    JDK 10 Moduleshas 2x lower footprint after Load! Note: Best case scenario during my tests. JMeter test plan was used to load application.
  • 24.
  • 25.