How to decrease your application footprint Java Module System · Docker awareness JDK-8146115...
Transcript of How to decrease your application footprint Java Module System · Docker awareness JDK-8146115...
![Page 1: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/1.jpg)
Java Module SystemHow to decrease your application footprint
Leonardo Zanivan - CrossoverRodrigo Cândido da Silva - Integritas
![Page 2: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/2.jpg)
![Page 3: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/3.jpg)
Java
9 M
odul
es S
yste
m
![Page 4: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/4.jpg)
![Page 5: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/5.jpg)
Previous Module System Classpath
![Page 6: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/6.jpg)
After Module System ClasspathJD
K 9
+
![Page 7: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/7.jpg)
![Page 8: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/8.jpg)
![Page 9: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/9.jpg)
Sprin
g Mo
du
les
![Page 10: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/10.jpg)
![Page 11: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/11.jpg)
jlink
exec
![Page 12: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/12.jpg)
● 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
![Page 13: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/13.jpg)
● 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
![Page 14: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/14.jpg)
● 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
![Page 15: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/15.jpg)
JDK 10 Highlights
Docker awareness
JDK-8146115 enhancement JDK-8186309 enhancementJDK-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
![Page 16: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/16.jpg)
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)
![Page 17: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/17.jpg)
● 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
![Page 18: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/18.jpg)
Eclipse OpenJ9
● TL;DR; 2x smaller memory
footprint and starts 2x faster
than HotSpot.
● Experimental; AdoptOpenJDK
builds are available.
https://adoptopenjdk.net
![Page 20: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/20.jpg)
Note: JDK 10 Alpine was built from source: https://hub.docker.com/r/panga/openjdk10/
JDK 10 Minimal JRE + Module Application < 100mb
![Page 21: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/21.jpg)
Note: Best case scenario during my tests.Limit: 2 cpus, 1g memory, JVM_OPTS= Xmx512m
JDK 10 Modules starts 2x faster on Docker
![Page 22: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/22.jpg)
Note: Best case scenario during my tests.JMeter test plan was used to load application.
JDK 10 Modules has 2x lower footprint on Startup!
![Page 23: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/23.jpg)
JDK 10 Modules has 2x lower footprint after Load!
Note: Best case scenario during my tests.JMeter test plan was used to load application.
![Page 24: How to decrease your application footprint Java Module System · Docker awareness JDK-8146115 enhancement JDK-8186309 enhancement JDK-8179498 enhancement Can extract container-specific](https://reader035.fdocuments.in/reader035/viewer/2022071021/5fd52ceb57f25422fd486b04/html5/thumbnails/24.jpg)
github.com/panga/spring-petclinic-java9modules