Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java & Containers: What I Wish I Knew Before I Used It: Elder Moraes Developer Advocate @elderjava

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Java & containers:

what I wish I knew before I used it

Elder Moraes
Developer Advocate
@elderjava
Photo by Andy Li on Unsplash
2 @elderjava
Source: https://www.bricoleurbanism.org/whimsicality/personal-container-management/
3 @elderjava
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

@elderjava
Common Issues when combining
Java & containers
• Long build time

• Huge image size

• Hard maintainability

• Resources allocation

5 @elderjava
https://github.com/eldermoraes/java_and_containers

6 @elderjava
How to avoid

Long build time

7 @elderjava
Mind order for caching

Do this Avoid this

8 @elderjava
Be specific for caching

Do this Avoid this

9 @elderjava
Group units for caching

Do this Avoid this

10 @elderjava
How to get rid of

Huge image size

11 @elderjava
Mind unnecessary dependencies

Do this Avoid this

12 @elderjava
Eliminate package manager cache

Do this Avoid this

13 @elderjava
Choose minimal size images

SIZE REPOSITORY TAG

14 @elderjava
Use optimized tools/frameworks

15 @elderjava
How to stay away from

Hard maintainability

16 @elderjava
Use official images

Do this Avoid this

17 @elderjava
Be specific with tags

Do this Avoid this

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

19 @elderjava
How to manage

Resources allocation

20 @elderjava
For Java 8u121 and before

Container?
cgroups?

21 @elderjava
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

22 @elderjava
For Java 8u121 and before
https://github.com/fabric8io-images/run-java-sh

23 @elderjava
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

24 @elderjava
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)

25 @elderjava
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)

26 @elderjava
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)

27 @elderjava
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)

28 @elderjava
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

29 @elderjava
developer.redhat.com

30 @elderjava

You might also like