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

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.

Cad9d9d8998f49269ce4f28a018ba53e?s=128

Elder Moraes

June 19, 2020
Tweet

Transcript

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

    used it Elder Moraes Developer Advocate @elderjava
  2. @elderjava 2 Photo by Andy Li on Unsplash

  3. @elderjava 3 Source: https://www.bricoleurbanism.org/whimsicality/personal-container-management/

  4. @elderjava 4 bit.ly/elderyt 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
  5. @elderjava 5 Common Issues • Long build time • Huge

    image size • Hard maintainability • Memory allocation
  6. @elderjava 6 Long build time How to avoid

  7. @elderjava 7 Mind order for caching Do this Avoid this

  8. @elderjava 8 Be specific for caching Do this Avoid this

  9. @elderjava 9 Group units for caching Do this Avoid this

  10. @elderjava 10 Huge image size How to get rid of

  11. @elderjava 11 Mind unnecessary dependencies Do this Avoid this

  12. @elderjava 12 Eliminate package manager cache Do this Avoid this

  13. @elderjava 13 Hard maintainability How to stay away from

  14. @elderjava 14 Use official images Do this Avoid this

  15. @elderjava 15 Be specific with tags Do this Avoid this

  16. @elderjava 16 Choose minimal size images SIZE REPOSITORY TAG

  17. @elderjava 17 Reference https://www.docker.com/blog/intro-guide-to- dockerfile-best-practices/

  18. @elderjava 18 Memory allocation How to manage

  19. @elderjava 19 For Java 8u121 and before Container? cgroups?

  20. @elderjava 20 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
  21. @elderjava 21 For Java 8u121 and before https://github.com/fabric8io-images/run-java-sh

  22. @elderjava 22 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
  23. @elderjava 23 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)
  24. @elderjava 24 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)
  25. @elderjava 25 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)
  26. @elderjava 26 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)
  27. @elderjava 27 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
  28. @elderjava 28 developer.redhat.com