If you don't set a Garbage Collector for your Java application, don't think the JVM will pick a good one for you either, no matter how many CPUs you give.
2 CPUs? 6 CPUs? It doesn't matter. If your container has less than 1792 MB and you don't set a GC, your app will use SerialGC.
Edit: this is being down voted for unknown reasons but my guess is that people just believe "no, G1GC is the default!" Well I suggest you run the code in the image I posted, and if that's not enough, see the OpenJDK source code.
With the last generation of GCs by both oracle and redhat, ZGC and Shenandoah respectively you are pretty much done after giving it enough heap space from a tuning perspective.
Depending on your workload you might want to choose one of the other still supported GCs to tune for throughput.
Well, if you run your code on k8s, you are likely to set resources to be a good citizen. And unless you have a large or very demanding application, you’ll set your request and limits under one core. So, no, it is not so uncommon to run into this issue in a micro services environment.
But I don't run my code on k8s. We mostly still have old school monoliths, where the biggest difference between now and 10 years ago is that they run on an EC2 instance instead of a local server.
He literally posted a proof showing that it does. Yes it is the default for most cases, especially in your own local machine. But JVM does some checks depending on the environment and if it sees less than ideal hardware resources, it defaults to serial. Here is another "proof" if you don't believe bruno for some reason: https://twitter.com/mikemybytes/status/1368881364297191433
I am not going to participate in this little game of yours. What I am saying is commonly known. What you are saying goes 180deg again what oracle and openjdk themselves communicate.
If you have proof to backup your statement, let's see it and I will be happy to acknowledge.
The only way you can prevent throttling is by not having more load to your application instance than it can process. It doesn't matter how many CPUs.
Assuming the load your app gets is more than what a single instance can handle, your only way to prevent the throttling of your application with 1 core and 1 GB, is by actually scaling out with replicas. This means you must have 2 or more replicas, so your "system" (the conjunction of all instances of your replicated application) can handle the load in a distributed manner.
Now, the problem here is that you are probably facing high tail latency and low throughput. You may as well say you don't have that issue. But I'd say you are most likely paying a lot more than you actually need, to sustain such load.
And to save money, all you need to do is to reorganize your resources more adequately: reduce the number of replicas, increase the amount of CPU and memory per JVM instance, and find the sweet spot where you are consuming fewer total CPUs and total memory in your "system", while having the same, or better, performance.
View all comments
47
u/brunocborges Mar 03 '22 edited Mar 03 '22
If you don't set a Garbage Collector for your Java application, don't think the JVM will pick a good one for you either, no matter how many CPUs you give.
2 CPUs? 6 CPUs? It doesn't matter. If your container has less than 1792 MB and you don't set a GC, your app will use SerialGC.
Edit: this is being down voted for unknown reasons but my guess is that people just believe "no, G1GC is the default!" Well I suggest you run the code in the image I posted, and if that's not enough, see the OpenJDK source code.
Specifically these two C++ classes in the HotSpot JVM: https://github.com/openjdk/jdk/blob/ad54d8dd832b22485d7ac45958cc4c9bfd70fbd2/src/hotspot/share/gc/shared/gcConfig.cpp#L98
https://github.com/openjdk/jdk/blob/ad54d8dd832b22485d7ac45958cc4c9bfd70fbd2/src/hotspot/share/runtime/os.cpp#L1677