Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java ergonomics: how are defaults calculated?

I'm following this question and discovering that all of the information is outdated.

The most up-to-date guide seems to be this document regarding GC tuning. In it Oracle defines their silly term ergonomics, which I think just means reasonable ("comfortable") defaults. In that document, this document is referred to, which is cited heavily in the above SO question.

It claims maximum heap size is calculated as follows:

Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

This is clearly false since I have a machine I tested on that has 12 GB of RAM and a 4096 MB, as verified with java -XX:+PrintFlagsFinal -version | grep HeapSize. But the caveat is included:

Note: The boundaries and fractions given for the heap size are correct for J2SE 5.0. They are likely to be different in subsequent releases as computers get more powerful.

Which is great! Except I can't find any up to date documentation on this. I verified that I am running a server-class per this question. Why is this important? Because my 12 GB server class machine is defaulting to 170 MB. Everything breaks on that. Yes, I am aware I can override this. I'd rather not have to duplicate that override across every application I run, and I would rather not hard code it into pom files. More to the point, this number somehow randomly changed on my machine, and I need to understand how it got bumped.

Here's my java version:

$ java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

I'm on Mac OS X 10.9.2.

like image 599
djechlin Avatar asked Nov 10 '22 08:11

djechlin


1 Answers

You're right. The documentation about the Java memory management is outdated nor complete: Xmx is just one example.

I made the same observation and I changed MY behavior: I specify Xmx always.

In my opinion, it is not a problem. The memory required by your Java program should not depend on your hardware. Moreover I think it is a good practice: specify explicitly Xmx (and other tunings) in your scripts/recipes help to have the same behavior in all environments (dev/prod have frequently different hardware configurations)

like image 95
mcoolive Avatar answered Nov 15 '22 06:11

mcoolive