Hacker News new | ask | show | jobs
by Sid_Lmao 16 days ago
Easy-to-miss detail: before JDK 27, the JVM only picked G1 with 2+ CPUs and ~1.8 GB of memory; otherwise, it silently used SerialGC. So a lot of 1- CPU Kubernetes pods have been on serial all along. Worth checking with -XX:+PrintCommandLineFlags before upgrading, since GC behaviour will change.
4 comments

Isn't the reason for this that on a single core SerialGC is better (lower CPU overhead at least)?
Lower overhead yes - but G1 should have shorter pauses. And shorter pauses is probably worth it unless you run only background jobs in your jvms.
Lower CPU and Memory overhead.

Serial will be your best choice if your app is constantly using 100% of that core or if you need to minimize the amount of memory overhead.

G1 is a better choice if you can be flexible with your memory and if you have a lot of periods in your app where it's below 100% CPU usage (maybe a lot of IO).

A 1,000 millicore CPU limit on Kubernetes does not mean the JVM can only use a single core. But that is indeed how the JVM interprets the limit: as a single core being available.
I'd imagine so. The kind of bookkeeping they're talking about here would negatively effect performance on a single core.
> So a lot of 1- CPU Kubernetes pods have been on serial all along

I don't think this is true.

Setting your CPU limit to 1 in Kubernetes does not mean the container sees a single logical processor. It only means the kernel allows it to use 1 core worth of CPU _time_.

If your k8s node is an 8 core node, Java will still see 8 logical processors. It just means you can only use 1/8th of each, or all of one, or some combination in-between.

I've never seen a k8s node running on a single core VM, as most of the cloud providers only use these for their free tier or shared core VM's for the lightest of light workloads.

Actually, setting your limit and request to exactly 1 does mean that, in some common kubernetes configs. There will be exactly 1 visible CPU.
Care to name them? I just shelled into a GKE pod with a CPU limit/request set to 1 and I see 8 logical processors from `lscpu` on an 8-vCPU node.
Then your node is probably using the "none" policy rather than the "static" policy.

https://kubernetes.io/docs/tasks/administer-cluster/cpu-mana...

> Setting your CPU limit to 1 in Kubernetes does not mean the container sees a single logical processor

that's incorrect, the jvm has been container aware for nearly a decade (https://bugs.openjdk.org/browse/JDK-8146115)

you are correct about the underlying scheduling. limits don't pin you to a core, you get quotas across all available

Nit: if your requests are equal to limits, and an integer, and the static cpu manager is turned on inside Kubelet, then it will pin to core(s).

https://kubernetes.io/docs/tasks/administer-cluster/cpu-mana...

yeah, fair point. there's all sorts of knobs available to pin to cpus, numa alignment, etc.. my comment only covers vanilla workloads
This is correct. I have been advocating about this for years now [1].

I have also seen customers wasting resources across Kubernetes because their developers would eventually tune JVMs with lowercase `-xmx` flag, which the JVM ignores, and thus by default, the JVM only sets heap size to 25% by default (for => 512mb of available memory).

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

Open JDK, not The JVM.

There are other implementations.

Not really, other than OpenJ9. In my experience, it's way behind OpenJDK in terms of performance and stability.
Then you never embedded development with real time JVMs, for example.
Nope. What kind of collectors do they use to be real time? I've never understood how this is possible.
Even ZGC now offers better predictablity than malloc/free allocators (which are a long way from predictable as far latency goes). But some hard-realtime software uses (or at least used to) RTSJ, a hard-realtime version of Java, that separates the heap to a part that uses a GC and a part that uses nested arenas. It was a big deal twenty years ago, when I worked on such software. I don't know how much it's still used. Probably not much. C is still king in that world, and Ada too, to some extent.

It's important to know that for hard realtime, even C alone isn't enough, though, and you need special kernels. Ordinary OS schedulers aren't predictable enough for hard realtime.

Real time algorithms, plenty of material on the matter.

Here is the book on the first implementation that was on the genesis of Aicas JamaicaVM.

https://www.amazon.com/dp/3831138931/ref=mp_s_a_1_1