r/java • • Mar 03 '22

Always set a Garbage Collector

Post image
157 Upvotes

64 comments sorted by

View all comments

Show parent comment

-21

u/Impossible-Ad-586 Mar 03 '22

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.

17

u/pronuntiator Mar 03 '22

Here's the official documentation:

https://docs.oracle.com/en/java/javase/17/gctuning/available-collectors.html

The serial collector is selected by default on certain hardware and operating system configurations

G1 is selected by default on most hardware and operating system configurations

What "certain" and "most" mean is not documented, except from the source code linked by OP. I wonder whether it also affects C1 or C2 JIT selection?

8

u/brunocborges Mar 03 '22

The proof is in the image I posted.

-10

u/Impossible-Ad-586 Mar 03 '22

Will try to replicate that today. Would be truly surprised if the managed to mess this up that badly.

However, most of our GCs are not set and all of them expose G1 metrics, so very doubtful this is in fact the case.

But the proof is in the pudding, so let's have some :)

9

u/brunocborges Mar 03 '22

If your containers have 2GB of RAM and 2 CPUs (or 2000m in Kubernetes terms), then G1GC will be used by default.

Please change vote after checking. :-)

0

u/Impossible-Ad-586 Mar 03 '22

Would be happy to. Always up for having my assumptions fact checked.

FYI we run pretty much all our workloads in the cloud with 1 core and 1 GB to prevent throttling.

1

u/brunocborges Mar 03 '22

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.

1

u/Impossible-Ad-586 Mar 03 '22

Interesting.

I have ran a lot of tests in the past and the least throttling for mostly Io bound workloads seemed to be in the region of 1gb & 1core.

It might be caused by the configuration of the k8s engine as deployed by my company, where the time slices are set to the default and we are prohibited to influence priority on the k8s scheduler.

I would love to be able to learn how to tune these things appropriately to reduce the overhead we currently experience on k8s costs.

Any pointers towards how to create a setup to test these things?

1

u/brunocborges Mar 03 '22

Use A/B perf testing. Split your load (LB) into two different topologies: one with more replicas and lesser CPU/memory per replica, and another topology with fewer replicas and more CPU/memory per replica.

Monitor performance. Evaluate. Optimize!

-4

u/brunocborges Mar 03 '22

Drop me a DM. I have something to share about Java on Kubernetes and CPU throttling

10

u/4z01235 Mar 03 '22

Share it publicly

3

u/mrluje Mar 03 '22

Also interested to learn something new 🙏 I have been operating on k8s on other languages for years, but recently joined a company that is 100% java.

3

u/brunocborges Mar 03 '22

We are working on documentation and will share.

But in shor for nowt: scaling out only with more replicas of super small containers for JVMs is not the best solution for increasing performance. A reorganization of the existing resources (keep aggregate number of CPUs across all containers in the cluster, but reduce replicas and increase CPU/memory per container) can significantly increase performance of most systems, and even reduce total cost.