Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Java & containers: what I wish I knew before I have used it

Elder Moraes
December 16, 2020

Java & containers: what I wish I knew before I have used it

They told you that using Java with containers were great, but they never mentioned that wouldn't be that easy, right?
You really got all advantages of containers like isolation, scalability, ease of deployment, and version management, but what about the pitfalls when using it with Java? Memory management, image size, initialization time… sometimes they can be tricky!
But there's a way out! Luckily there are have some best practices that will rescue your application from failing. From the Dockerfile to the Java updates (from 9 to 14 and beyond), you can have the best of both worlds right on your hands.
Join this practical session and transform the way you deal with Java and containers. Today.

Elder Moraes

December 16, 2020
Tweet

More Decks by Elder Moraes

Other Decks in Technology

Transcript

  1. Java & containers: what I wish I knew before I

    used it Elder Moraes Developer Advocate @elderjava
  2. @elderjava 4 eldermoraes.com/join Java Champion Developer Advocate at Red Hat

    Board member at SouJava Author of Jakarta EE Cookbook Helps Java developers to build and deliver awesome application so they can work on great projects
  3. @elderjava 5 Common Issues when combining Java & containers •

    Long build time • Huge image size • Hard maintainability • Resources allocation
  4. @elderjava 22 For Java 8u121 and before "Control groups (cgroups)

    is a kernel feature that limits, accounts for and isolates the CPU, memory, disk I/O and network's usage of one or more processes." Source: https://www.linuxjournal.com/content/everything-you-need-know-about-linux-containers-part-i-linux-control-groups-and-process
  5. @elderjava 24 For Java 8u131 and Java 9 • ParallelGCThreads:

    helps to limit the cpu usage of a container • UseCGroupMemoryLimitForHeap: JVM uses the cgroups limits to calculate memory defaults • MaxRAMFraction: percentage of available RAM that can be used
  6. @elderjava 25 For Java 8u191 and Java 10 • InitialRAMPercentage:

    initial percentage of heap allocation • MaxRAMPercentage: maximum percentage of heap allocation • MinRAMPercentage: minimum percentage of heap allocation • # of CPUs is calculated from container allocation by default (JDK-8196595)
  7. @elderjava 26 For Java 11 • -XshowSettings (Container Metrics): display

    the system or container configuration • JDK-8197867: improve CPU calculations for both containers and JVM hotspot (see PreferContainerQuotaForCPUCount)
  8. @elderjava 27 For Java 12 and 13 • jhsdb now

    can be attached to Java processes running in containers (JDK-8205992) • Container support improved for Java Flight Recorder (JDK-8203359) • Improve systemd slice memory limit support (JDK-8217338)
  9. @elderjava 28 For Java 14 • JFR Event Streaming: expose

    JDK Flight Recorder data for continuous monitoring (easier for observability in clusters) • Packaging Tool: tool for packaging self-contained Java applications (incubator)
  10. @elderjava 29 Conclusions • Yes, Java and containers can get

    along! • Be intentional when building your Dockerfiles • Better start with Java 11+ • If you *really* need 8 (why?), be extra cautious