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

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

Cad9d9d8998f49269ce4f28a018ba53e?s=47 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.

Cad9d9d8998f49269ce4f28a018ba53e?s=128

Elder Moraes

December 16, 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 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
  5. @elderjava 5 Common Issues when combining Java & containers •

    Long build time • Huge image size • Hard maintainability • Resources allocation
  6. @elderjava 6 https://github.com/eldermoraes/java_and_containers

  7. @elderjava 7 Long build time How to avoid

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

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

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

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

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

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

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

  15. @elderjava 15 Use optimized tools/frameworks

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

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

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

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

  20. @elderjava 20 Resources allocation How to manage

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

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

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