Remix.run Logo
▲ brunoborges 3 hours ago

Lots of details that teams miss when tuning the JVM on Kubernetes:

1. Default heap size varies: it can be 50% of the available memory for any amount of available memory up to 256mb; ~128mb for anywhere between 256 and 512; and then 25% for anything above 512mb;

2. The JVM will still do parallel threads even when CPU limit is 1,000 or below , which triggers CPU throttling much faster. Threads such as GC (even when it is SerialGC), ForkJoin pools, Database connection pools, HTTP server, and so on.

3. The JVM behaves MUCH better with 2,000 or more milicores, and a well sized heap. Having very small containers and dozens of replicas is worse than having slightly bigger containers (cpu/memory limits) and fewer replicas, even with a different ratio (e.g. 6 replicas will perform worse than 3 replicas, even when aggregated CPU and memory limits are the same).

I've been advocating on this for years [1].

[1] https://www.youtube.com/watch?v=wApqCjHWF8Q

▲joosd 4 minutes ago | parent | next [-]

Hey man just wanted to let you know years ago our team used your Devoxx talk as a starting point for tuning our Java apps that are running on K8s and it has been of tremendous help. I still refer back to it every now and then!

▲gavinray an hour ago | parent | prev [-]

Modern JVM's (JDK +10) have runtime detection for whether they're operating in a container environment, and apply sensible defaults based dynamically on resources if so.

Google term: "-XX:+UseContainerSupport"

▲hibikir an hour ago | parent | next [-]

While you are replying to someone that definitely knows this, you'd be surprised by the number of production containers out there, in big companies, that haven't turned on container support, or hand tuned their memory well, and thus end up throwing away large parts of the memory they are allocated.

Having used Java since the days where you needed to do very heavy tuning to get it to run properly, it all seems alien, as understanding the old garbage collectors was basically mandatory 20 year ago. But even if you reply to someone that does understand the new features, you might be helping a bunch of people that don't. In my unit of about 100 programmers I am the only one that even bothered looking, given how every single pod we deployed was either completely unconfigured, or so badly misconfigured, using settings that haven't been ideal since Java 6.

In one of the pods, running a batch job that was using way too much memory, about a third of the memory in the old generation were millions of copies of the very same string. Interning of strings loaded like that has been a JVM option since 2014.

▲gavinray an hour ago | parent | prev [-]

I just realized the username of the comment I replied to.

The OP undoubtedly knows this, whoops.

▲froh an hour ago | parent [-]

I (and presumably some others) didn't. TIL and thx for sharing.

and I also read it not as contradiction but simply as useful additional information.