SlideShare a Scribd company logo
Copyright © 2019 Oracle and/or its affiliates.
JVMs in Containers
Best Practices
David Delabassée - @delabassee
DevRel
Java Platform Group - Oracle
November 2019
Copyright © 2019 Oracle and/or its affiliates.
@delabassee
Java Platform Group
Oracle
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
Copyright © 2019 Oracle and/or its affiliates.
Copyright © 2019 Oracle and/or its affiliates.
Containers
• Package Software into Standardized Units
- Development
- Shipment
- Deployment
• Runtimes
- Docker, CRI-O, Podman, LXC, rkt, runC, systemd-nspawn, OpenVZ, etc.
Copyright © 2019 Oracle and/or its affiliates.
Container
Copyright © 2019 Oracle and/or its affiliates.
Container vs. VM
Infrastructure
Infrastructure
Host OS
Host OS
Hypervisor
Container Daemon
Guest OS A
Bin/libs
App #1
Bin/libs
App #1
Bin/libs
App #2
Guest OS B
Bin/libs
App #2
Java
Copyright © 2019 Oracle and/or its affiliates.
Tools
docker-maven-plugin
Jib + jib-maven-plugin
Testcontainers
…
Copyright © 2019 Oracle and/or its affiliates.
JVM Container Tooling
FaaS
Fn Project
OpenFaaS
OpenWhisk
…
Frameworks
Helidon
Quarkus
Micronaut
…
• JVM should behave as a good (Container) citizen
• “Improved latency”
Copyright © 2019 Oracle and/or its affiliates.
JVM in Containers
Hello Container
Demo
Copyright © 2019 Oracle and/or its affiliates.
Latency
Copyright © 2019 Oracle and/or its affiliates.
Copyright © 2019 Oracle and/or its affiliates.
Latency
Container Start-Up
• 3 “core” layers
- Java application and its dependencies
- Java Runtime
- Operating System
• ⇨ Reduce layers size
Copyright © 2019 Oracle and/or its affiliates.
Stack of Layers
• Dependencies
• Leverage Container cache layer mechanism
• Anything that is (relatively) static in its own layer
• Fat JAR
• CDS Shared Archive
Copyright © 2019 Oracle and/or its affiliates.
Stack of Layers
Copyright © 2019 Oracle and/or its affiliates.
Java Runtime Image
Modules jlink flags MB
JDK Whole JDK! 316 100%
Runtime image All (explicit) --add-modules $(java --list-modules) 178 56% 100%
Custom runtime image Required modules only --add-modules $(jdeps --print-module-deps …) 50 16% 28%
… --no-header-files --no-man-pages
--strip-java-debug-attributes 44 14% 25%
… --compress=1 37 12% 21%
… --compress=2 34 11% 19%
316 MB 178 MB 50 MB 34 MB
Serverless Java function (Fn) - openjdk:13
• musl
Lightweight, fast, simple, free, C standard library implementation
https://www.musl-libc.org
• Alpine
Security-oriented, lightweight Linux distro with 4MB base image
https://www.alpinelinux.org
• Project Portola
Run the JVM on musl
https://openjdk.java.net/projects/portola/
Copyright © 2019 Oracle and/or its affiliates.
Operating System
Copyright © 2019 Oracle and/or its affiliates.
Copyright © 2019 Oracle and/or its affiliates.
Java Runtime Image
Minecraft server
java.base, java.compiler, java.desktop, java.management, java.naming,
java.rmi, java.scripting, java.sql, jdk.sctp, jdk.unsupported, jdk.zipfs
openjdk:13 - 12 modules 88 MB
--strip-debug --strip-java-debug-attributes -14 MB
--compress=1 -18 MB
--compress=2 -31 MB
--no-header-file --no-man-pages 0 MB (*)
openjdk-11-jdk (debian:buster) - all modules 554 MB (!!)
12 modules 469 MB
--strip-native-debug-symbols (new)
Copyright © 2019 Oracle and/or its affiliates.
Latency
Application Start-Up
0
10
20
30
40
50
60
70
80
90
8 9 10 11 12 13
time(ms)
Hello World
Copyright © 2019 Oracle and/or its affiliates.
Startup Time
• Bootstrap regressions in JDK 9 fixed! Keep on fixing!
• +120 startup-related enhancements in JDK 10 through JDK 13!
• Reduce memory footprint between multiple JVMs by sharing
common class metadata
• Improve startup time
• How?
- Loads classes from JAR file into a private internal representation
- Dumps it to a shared archive
- When JVMs (re)starts, the archive is memory-mapped to allow sharing of
R/O JVM metadata for these classes among multiple JVMs
Copyright © 2019 Oracle and/or its affiliates.
Class Data Sharing
CDS
Demo
Copyright © 2019 Oracle and/or its affiliates.
Copyright © 2019 Oracle and/or its affiliates.
Application CDS
Copyright © 2019 Oracle and/or its affiliates.
Application CDS
jdk-08-u202-b08-hotspot
jruby -e 1
real 0m1.601s
user 0m4.434s
sys 0m0.234s
jruby --dev -e 1
real 0m1.216s
user 0m1.646s
sys 0m0.162s
jruby --disable-gems --dev -e 1
real 0m0.853s
user 0m1.030s
sys 0m0.113s
jdk-13.jdk
… -J-XX:SharedArchiveFile=jruby.jsa
real 0m1.491s
user 0m3.378s
sys 0m0.220s
… -J-XX:SharedArchiveFile=jruby.jsa
real 0m1.089s
user 0m1.644s
sys 0m0.133s
… -J-XX:SharedArchiveFile=jruby.jsa
real 0m0.717s
user 0m0.944s
sys 0m0.110s
• Java 5 - Limited to system classes and serial GC
• Java 9 - Application CDS and other GCs (commercial feature + JEP 250)
• Java 10 - Application CDS (JEP 310)
• Java 12 - Default CDS Archives (JEP 341)
• Java 13 - Dynamic CDS Archives (JEP 350)
- Dynamic archiving of classes at the end of application execution
-XX:ArchiveClassesAtExit=my-app-cds.jsa
Copyright © 2019 Oracle and/or its affiliates.
Class Data Sharing
• High Performance Universal Virtual Machine
• Polyglot
• …
• Native Image
- Reduced startup time
- Improved foot-print
- Reduced image size
Copyright © 2019 Oracle and/or its affiliates.
GraalVM
https://www.graalvm.org
• Java 8 & 11
• Not supported
- InvokeDynamic and Method Handles, Dynamic Class Un/Loading, Finalizers, Security
Manager
- JVMTI, JMX, other native VM interfaces
• Mostly supported, or supported via configuration
- Reflections, Dynamic Proxy, JNI, Unsafe Memory Access, Static Initializers, References
Copyright © 2019 Oracle and/or its affiliates.
GraalVM limitations
https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md
Copyright © 2019 Oracle and/or its affiliates.
Container
JVM should behave as a good citizen
JDK-8179498 attach should be relative to /proc/pid/root and namespace
aware as jcmd, jstack, ... fail to attach (10)
JDK-8146115 Improve Docker container detection & resource config usage (10)
JDK-8193710 jcmd –l & jps do not list Java processes running in containers (11)
JDK-8203357 Container Metrics (11)
JDK-8186248 More flexibility in selecting Heap % of available RAM (8u144)
JDK-8203359 JFR jdk.CPUInformation event reports incorrect information when
running in Docker container (open)
JDK-8228428 OperatingSystemMXBean should be made container aware (open 14)
…
Copyright © 2019 Oracle and/or its affiliates.
Container Awareness
• The JVM tunes itself based on the system it runs on
• Behavior-Based Tuning dynamically optimizes the sizes of the heap
to meet an expected behavior
- Maximum Pause-time (-XX:MaxGCPauseMillis)
- Or Application Throughput (-XX:GCTimeRatio)
• Sets defaults for the GC, heap size, and runtime compiler
Copyright © 2019 Oracle and/or its affiliates.
Ergonomics
https://docs.oracle.com/en/java/javase/13/gctuning/ergonomics.html
Ergonomics
Demo
Copyright © 2019 Oracle and/or its affiliates.
Copyright © 2019 Oracle and/or its affiliates.
Wrap-Up
• Reduced “latency”
- Container Startup
- Application Startup
• JVM behaves as a good (Container) citizen
Copyright © 2019 Oracle and/or its affiliates.
JVMs in Containers
• Use the latest Java version and never java:latest !!!
• Only rely on actively-supported versions!
• Use a JRE Java runtime image instead of a JDK
• Move startup costs to the build phase
• It’s “containers as usual”
- Docker-bench-security, Snyk, Clair, Anchore, etc.
- Small(er) is better
- Reduce the potential attack surface
- Multistage build, etc.
Copyright © 2019 Oracle and/or its affiliates.
JVMs in Containers
Copyright © 2019 Oracle and/or its affiliates.
Choose your base image wisely
Copyright © 2019 Oracle and/or its affiliates.
Choose your base image wisely
and secure it!
ありがとうございます
Copyright © 2019 Oracle and/or its affiliates.
DevRel
Java Platform Group - Oracle
October 2019
David Delabassée - @delabassee

More Related Content

PDF
Monitoring of Web Applications and GlassFish for Performance and Availability...
PPTX
GlassFish in Production Environments
PDF
Serverless Java Challenges & Triumphs
PDF
Java EE 7 for WebLogic 12c Developers
PPTX
Ausoug glassfish perth
PDF
Serverless Java: JJUG CCC 2019
PDF
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
PDF
Get Rid Of OutOfMemoryError messages
Monitoring of Web Applications and GlassFish for Performance and Availability...
GlassFish in Production Environments
Serverless Java Challenges & Triumphs
Java EE 7 for WebLogic 12c Developers
Ausoug glassfish perth
Serverless Java: JJUG CCC 2019
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Get Rid Of OutOfMemoryError messages

What's hot (20)

PDF
MySQL User Camp: GTIDs
PPTX
Java modules using project jigsaw@jdk 9
PDF
Running your Java EE 6 applications in the Cloud
PDF
20191119 Cloud Native Java : GraalVM
PDF
Cloud Consolidation with Oracle (RAC) - How much is too much?
PDF
The Kubernetes WebLogic revival (part 1)
PDF
The Oracle RAC Family of Solutions - Presentation
PDF
Troubleshooting Tools In JDK
PDF
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
PDF
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
PDF
Java Summit Chennai: JAX-RS 2.0
PDF
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
PDF
Oracle RAC Internals - The Cache Fusion Edition
PDF
How to Become a Winner in the JVM Performance-Tuning Battle
PDF
Oracle RAC BP for Upgrade & More by Anil Nair and Markus Michalewicz
PDF
Running your Java EE 6 applications in the Cloud @ Silicon Valley Code Camp 2010
DOCX
Aneez Hasan_Resume
PDF
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
PDF
Oracle RAC 12c Best Practices with Appendices DOAG2013
PDF
JDK 9 Java Platform Module System
MySQL User Camp: GTIDs
Java modules using project jigsaw@jdk 9
Running your Java EE 6 applications in the Cloud
20191119 Cloud Native Java : GraalVM
Cloud Consolidation with Oracle (RAC) - How much is too much?
The Kubernetes WebLogic revival (part 1)
The Oracle RAC Family of Solutions - Presentation
Troubleshooting Tools In JDK
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Java Summit Chennai: JAX-RS 2.0
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
Oracle RAC Internals - The Cache Fusion Edition
How to Become a Winner in the JVM Performance-Tuning Battle
Oracle RAC BP for Upgrade & More by Anil Nair and Markus Michalewicz
Running your Java EE 6 applications in the Cloud @ Silicon Valley Code Camp 2010
Aneez Hasan_Resume
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle RAC 12c Best Practices with Appendices DOAG2013
JDK 9 Java Platform Module System
Ad

Similar to JVMs in Containers - Best Practices (20)

PDF
JVMs in Containers
PDF
Java in a World of Containers - DockerCon 2018
PDF
Java in a world of containers
PDF
Commit to excellence - Java in containers
PDF
Java-light-speed NebraskaCode.pdf
PPTX
Practical Tips for Hardening Java Applications
PDF
Effective Spring on Kubernetes
PDF
Java is Container Ready - Vaibhav - Container Conference 2018
PDF
Serverless Java - Challenges and Triumphs
PDF
Kubernetes Native Java and Eclipse MicroProfile | EclipseCon Europe 2019
PDF
Kubernetes Native Java and Eclipse MicroProfile | EclipseCon Europe 2019
PDF
Java Cloud and Container Ready
PDF
Java 40 versions_sgp
PDF
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
PPTX
CodeOne 2019: "Continuous Delivery with Docker and Java"
PDF
USAA Mono-to-Serverless.pdf
PDF
JDK versions and OpenJDK
PDF
Java and Containers - Make it Awesome !
PDF
javalightspeed-jakartatech-2023.pdf
PDF
Running Java Applications on Cloud Foundry
JVMs in Containers
Java in a World of Containers - DockerCon 2018
Java in a world of containers
Commit to excellence - Java in containers
Java-light-speed NebraskaCode.pdf
Practical Tips for Hardening Java Applications
Effective Spring on Kubernetes
Java is Container Ready - Vaibhav - Container Conference 2018
Serverless Java - Challenges and Triumphs
Kubernetes Native Java and Eclipse MicroProfile | EclipseCon Europe 2019
Kubernetes Native Java and Eclipse MicroProfile | EclipseCon Europe 2019
Java Cloud and Container Ready
Java 40 versions_sgp
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
CodeOne 2019: "Continuous Delivery with Docker and Java"
USAA Mono-to-Serverless.pdf
JDK versions and OpenJDK
Java and Containers - Make it Awesome !
javalightspeed-jakartatech-2023.pdf
Running Java Applications on Cloud Foundry
Ad

More from David Delabassee (20)

PDF
Randstad Docker meetup - Serverless
PDF
Java Serverless in Action - Voxxed Banff
PPTX
Serverless Kotlin
PDF
REST in an Async World
PDF
JAX-RS 2.1 Reloaded
PDF
Java EE 8 - February 2017 update
PDF
Java EE Next
PDF
Java EE Next - BeJUG JavaOne Afterglow 2016
PDF
HTTP/2 comes to Java
PDF
Java EE 8 - Work in progress
PDF
HTTP/2 comes to Java (Dec. 2015 version)
PDF
EJB and CDI - Alignment and Strategy
PDF
HTTP/2 Comes to Java
PDF
Java EE 8 - What’s new on the Web front
PDF
HTTP/2 Comes to Java
PDF
What's coming in Java EE 8
PDF
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0
PDF
MVC 1.0 / JSR 371
PDF
Java EE 8 - An instant snapshot
PDF
Avatar 2.0
Randstad Docker meetup - Serverless
Java Serverless in Action - Voxxed Banff
Serverless Kotlin
REST in an Async World
JAX-RS 2.1 Reloaded
Java EE 8 - February 2017 update
Java EE Next
Java EE Next - BeJUG JavaOne Afterglow 2016
HTTP/2 comes to Java
Java EE 8 - Work in progress
HTTP/2 comes to Java (Dec. 2015 version)
EJB and CDI - Alignment and Strategy
HTTP/2 Comes to Java
Java EE 8 - What’s new on the Web front
HTTP/2 Comes to Java
What's coming in Java EE 8
Java EE 8 Adopt a JSR : JSON-P 1.1 & MVC 1.0
MVC 1.0 / JSR 371
Java EE 8 - An instant snapshot
Avatar 2.0

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PPT
Introduction Database Management System for Course Database
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Nekopoi APK 2025 free lastest update
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
AI in Product Development-omnex systems
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Introduction to Artificial Intelligence
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
Introduction Database Management System for Course Database
2025 Textile ERP Trends: SAP, Odoo & Oracle
Nekopoi APK 2025 free lastest update
ISO 45001 Occupational Health and Safety Management System
AI in Product Development-omnex systems
Wondershare Filmora 15 Crack With Activation Key [2025
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Odoo POS Development Services by CandidRoot Solutions
CHAPTER 2 - PM Management and IT Context
Introduction to Artificial Intelligence
Odoo Companies in India – Driving Business Transformation.pdf
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

JVMs in Containers - Best Practices

  • 1. Copyright © 2019 Oracle and/or its affiliates. JVMs in Containers Best Practices David Delabassée - @delabassee DevRel Java Platform Group - Oracle November 2019
  • 2. Copyright © 2019 Oracle and/or its affiliates. @delabassee Java Platform Group Oracle
  • 3. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Safe Harbor Copyright © 2019 Oracle and/or its affiliates.
  • 4. Copyright © 2019 Oracle and/or its affiliates. Containers
  • 5. • Package Software into Standardized Units - Development - Shipment - Deployment • Runtimes - Docker, CRI-O, Podman, LXC, rkt, runC, systemd-nspawn, OpenVZ, etc. Copyright © 2019 Oracle and/or its affiliates. Container
  • 6. Copyright © 2019 Oracle and/or its affiliates. Container vs. VM Infrastructure Infrastructure Host OS Host OS Hypervisor Container Daemon Guest OS A Bin/libs App #1 Bin/libs App #1 Bin/libs App #2 Guest OS B Bin/libs App #2
  • 7. Java Copyright © 2019 Oracle and/or its affiliates.
  • 8. Tools docker-maven-plugin Jib + jib-maven-plugin Testcontainers … Copyright © 2019 Oracle and/or its affiliates. JVM Container Tooling FaaS Fn Project OpenFaaS OpenWhisk … Frameworks Helidon Quarkus Micronaut …
  • 9. • JVM should behave as a good (Container) citizen • “Improved latency” Copyright © 2019 Oracle and/or its affiliates. JVM in Containers
  • 10. Hello Container Demo Copyright © 2019 Oracle and/or its affiliates.
  • 11. Latency Copyright © 2019 Oracle and/or its affiliates.
  • 12. Copyright © 2019 Oracle and/or its affiliates. Latency Container Start-Up
  • 13. • 3 “core” layers - Java application and its dependencies - Java Runtime - Operating System • ⇨ Reduce layers size Copyright © 2019 Oracle and/or its affiliates. Stack of Layers
  • 14. • Dependencies • Leverage Container cache layer mechanism • Anything that is (relatively) static in its own layer • Fat JAR • CDS Shared Archive Copyright © 2019 Oracle and/or its affiliates. Stack of Layers
  • 15. Copyright © 2019 Oracle and/or its affiliates. Java Runtime Image Modules jlink flags MB JDK Whole JDK! 316 100% Runtime image All (explicit) --add-modules $(java --list-modules) 178 56% 100% Custom runtime image Required modules only --add-modules $(jdeps --print-module-deps …) 50 16% 28% … --no-header-files --no-man-pages --strip-java-debug-attributes 44 14% 25% … --compress=1 37 12% 21% … --compress=2 34 11% 19% 316 MB 178 MB 50 MB 34 MB Serverless Java function (Fn) - openjdk:13
  • 16. • musl Lightweight, fast, simple, free, C standard library implementation https://www.musl-libc.org • Alpine Security-oriented, lightweight Linux distro with 4MB base image https://www.alpinelinux.org • Project Portola Run the JVM on musl https://openjdk.java.net/projects/portola/ Copyright © 2019 Oracle and/or its affiliates. Operating System
  • 17. Copyright © 2019 Oracle and/or its affiliates.
  • 18. Copyright © 2019 Oracle and/or its affiliates. Java Runtime Image Minecraft server java.base, java.compiler, java.desktop, java.management, java.naming, java.rmi, java.scripting, java.sql, jdk.sctp, jdk.unsupported, jdk.zipfs openjdk:13 - 12 modules 88 MB --strip-debug --strip-java-debug-attributes -14 MB --compress=1 -18 MB --compress=2 -31 MB --no-header-file --no-man-pages 0 MB (*) openjdk-11-jdk (debian:buster) - all modules 554 MB (!!) 12 modules 469 MB --strip-native-debug-symbols (new)
  • 19. Copyright © 2019 Oracle and/or its affiliates. Latency Application Start-Up
  • 20. 0 10 20 30 40 50 60 70 80 90 8 9 10 11 12 13 time(ms) Hello World Copyright © 2019 Oracle and/or its affiliates. Startup Time • Bootstrap regressions in JDK 9 fixed! Keep on fixing! • +120 startup-related enhancements in JDK 10 through JDK 13!
  • 21. • Reduce memory footprint between multiple JVMs by sharing common class metadata • Improve startup time • How? - Loads classes from JAR file into a private internal representation - Dumps it to a shared archive - When JVMs (re)starts, the archive is memory-mapped to allow sharing of R/O JVM metadata for these classes among multiple JVMs Copyright © 2019 Oracle and/or its affiliates. Class Data Sharing
  • 22. CDS Demo Copyright © 2019 Oracle and/or its affiliates.
  • 23. Copyright © 2019 Oracle and/or its affiliates. Application CDS
  • 24. Copyright © 2019 Oracle and/or its affiliates. Application CDS jdk-08-u202-b08-hotspot jruby -e 1 real 0m1.601s user 0m4.434s sys 0m0.234s jruby --dev -e 1 real 0m1.216s user 0m1.646s sys 0m0.162s jruby --disable-gems --dev -e 1 real 0m0.853s user 0m1.030s sys 0m0.113s jdk-13.jdk … -J-XX:SharedArchiveFile=jruby.jsa real 0m1.491s user 0m3.378s sys 0m0.220s … -J-XX:SharedArchiveFile=jruby.jsa real 0m1.089s user 0m1.644s sys 0m0.133s … -J-XX:SharedArchiveFile=jruby.jsa real 0m0.717s user 0m0.944s sys 0m0.110s
  • 25. • Java 5 - Limited to system classes and serial GC • Java 9 - Application CDS and other GCs (commercial feature + JEP 250) • Java 10 - Application CDS (JEP 310) • Java 12 - Default CDS Archives (JEP 341) • Java 13 - Dynamic CDS Archives (JEP 350) - Dynamic archiving of classes at the end of application execution -XX:ArchiveClassesAtExit=my-app-cds.jsa Copyright © 2019 Oracle and/or its affiliates. Class Data Sharing
  • 26. • High Performance Universal Virtual Machine • Polyglot • … • Native Image - Reduced startup time - Improved foot-print - Reduced image size Copyright © 2019 Oracle and/or its affiliates. GraalVM https://www.graalvm.org
  • 27. • Java 8 & 11 • Not supported - InvokeDynamic and Method Handles, Dynamic Class Un/Loading, Finalizers, Security Manager - JVMTI, JMX, other native VM interfaces • Mostly supported, or supported via configuration - Reflections, Dynamic Proxy, JNI, Unsafe Memory Access, Static Initializers, References Copyright © 2019 Oracle and/or its affiliates. GraalVM limitations https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md
  • 28. Copyright © 2019 Oracle and/or its affiliates. Container JVM should behave as a good citizen
  • 29. JDK-8179498 attach should be relative to /proc/pid/root and namespace aware as jcmd, jstack, ... fail to attach (10) JDK-8146115 Improve Docker container detection & resource config usage (10) JDK-8193710 jcmd –l & jps do not list Java processes running in containers (11) JDK-8203357 Container Metrics (11) JDK-8186248 More flexibility in selecting Heap % of available RAM (8u144) JDK-8203359 JFR jdk.CPUInformation event reports incorrect information when running in Docker container (open) JDK-8228428 OperatingSystemMXBean should be made container aware (open 14) … Copyright © 2019 Oracle and/or its affiliates. Container Awareness
  • 30. • The JVM tunes itself based on the system it runs on • Behavior-Based Tuning dynamically optimizes the sizes of the heap to meet an expected behavior - Maximum Pause-time (-XX:MaxGCPauseMillis) - Or Application Throughput (-XX:GCTimeRatio) • Sets defaults for the GC, heap size, and runtime compiler Copyright © 2019 Oracle and/or its affiliates. Ergonomics https://docs.oracle.com/en/java/javase/13/gctuning/ergonomics.html
  • 31. Ergonomics Demo Copyright © 2019 Oracle and/or its affiliates.
  • 32. Copyright © 2019 Oracle and/or its affiliates. Wrap-Up
  • 33. • Reduced “latency” - Container Startup - Application Startup • JVM behaves as a good (Container) citizen Copyright © 2019 Oracle and/or its affiliates. JVMs in Containers
  • 34. • Use the latest Java version and never java:latest !!! • Only rely on actively-supported versions! • Use a JRE Java runtime image instead of a JDK • Move startup costs to the build phase • It’s “containers as usual” - Docker-bench-security, Snyk, Clair, Anchore, etc. - Small(er) is better - Reduce the potential attack surface - Multistage build, etc. Copyright © 2019 Oracle and/or its affiliates. JVMs in Containers
  • 35. Copyright © 2019 Oracle and/or its affiliates. Choose your base image wisely
  • 36. Copyright © 2019 Oracle and/or its affiliates. Choose your base image wisely and secure it!
  • 37. ありがとうございます Copyright © 2019 Oracle and/or its affiliates. DevRel Java Platform Group - Oracle October 2019 David Delabassée - @delabassee