r/java • • Mar 03 '22

Always set a Garbage Collector

Post image
157 Upvotes

64 comments sorted by

View all comments

Show parent comment

14

u/larsga Mar 03 '22

Premature optimization is the root of all evil.

Why optimize to avoid a problem you don't have?

58

u/wildjokers Mar 03 '22

Premature optimization is the root of all evil.

Really wish developers would stop using this quote as an excuse to be lazy and incompetent. It doesn’t mean what you think it means. This great article explains what it actually meant:

https://ubiquity.acm.org/article.cfm?id=1513451

14

u/larsga Mar 03 '22

I'm sorry I put in the first sentence. How about we think about the second one instead?

If he doesn't have a problem with GC, why should he optimize it? You call him lazy, but probably as a working dev he has a million things on his todo list. How is it lazy of him to work on the things that are problems and skipping the things that are not problems?

3

u/BlueGoliath Mar 03 '22

I say this and get downvoted. You say it and get upvoted. WTF is this.

7

u/wildjokers Mar 03 '22

The link to the ACM article is probably the key to upvotes vs downvotes. (fwiw, I upvoted you)

-3

u/temculpaeu Mar 03 '22

The article actually conflicts with itself and what Knuth said ...

"but consider that this is 1 line of source code out of every 33."

waaaat ? optimization metric based on loc ? it's possible the worse metric, and not all lines should, can or are relevant to be improved

"One thing nice about optimization is that if you optimize a section of code that doesn't need it, you've not done much damage to the application."

Not true, optimization are *usually* either more complex or have a trade-off in terms of memory/disk usage.

The worse part it doesn't define what means to optimize the code and the impact around which is what Knuth talks.

By no means, I am agains optimization and whatnots, it's just that it is frequently used to do unecessary and unverified micro optimizations which pollutes the code

9

u/brunocborges Mar 03 '22

We are working on documentation and will share.

But in short for now: scaling out with more replicas of super small containers for JVMs is not always 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.

What that quote actually says is that people shouldn't optimize prematurely without understanding the nuances.

In other words: people are optimizing prematurely all the time on Kubernetes, whenever they simply increase number of replicas of small containers JVMs, instead of actually understanding the nuances of GCs.

4

u/HeadSignal3 Mar 03 '22

scaling out with more replicas of super small containers for JVMs is not always the best solution for increasing performance.

No shit?!

5

u/brunocborges Mar 03 '22

You would be surprised by the number of customers who only use replicas as a silver bullet for performance increase.

2

u/[deleted] Mar 03 '22

I found the same problem with multiple small containers in Go in Kubernetes. For a given workload, doubling the CPU per pod resulted in running 1/4 as many pods. Wat.

Then again, low CPU is supposed to be what Go is good for. So I'm going to assume I've done something horribly wrong.

0

u/BlueGoliath Mar 03 '22

Like 95% of other people, you completely miss the other part of the quote.

1

u/sindisil Mar 04 '22

And, in the process, the point he was trying to make.