5

Is it preferable set with -Xms<> parameter to JVM the expected memory or is it better to leave it in automatic? I mean, if I know that my application will use at least 500MB of RAM and maximum 1 GB (used random numbers), would setting the parameters to the JVM be better? I know that if you have a bigger heap the consequence is that you have longer wait time but if the heap is almost finished, should the JVM relocate the occupied memory (losing precious time)?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
BlacK
  • 241
  • 7
  • 16
  • 1
    http://stackoverflow.com/questions/15338261/optimizing-java-application-using-xms-and-xmx – assylias Dec 14 '13 at 16:36
  • How much time are you loosing exactly? – Ingo Dec 14 '13 at 16:42
  • Since benchmarking the JVM is not so easy (warm-up) I don't know if the result are good or not. It depends on the algorithm obviously but at the state of art I cannot reply you with correct data – BlacK Dec 14 '13 at 16:48
  • Adjusting the heap size is done primarily to adjust the frequency of GC. (It also helps the JVM avoid using more system resource than it needs.) Starting with a large heap means GC is rare, but, especially with "stop-the-world" collectors, there will be a significant pause in execution when GC actually occurs. Using a smaller heap makes the pause smaller. – Hot Licks Dec 15 '13 at 02:16
  • (And there is no noticeable "cost" for the act of actually increasing heap size -- it's just a matter of adjusting numbers.) – Hot Licks Dec 15 '13 at 02:18

1 Answers1

2

The process of heap expansion does affect performance. However, the effects depends on what kind of performance you are talking about.

One performance criterion is the percentage of processor time that is spent "doing garbage collection"; i.e. "throughput". The GCs that optimize for throughput tend to work best with a large heap. So in this case, a simple analysis say that you will do better preallocating the heap to the size that you expect to be required ... instead of starting small and relying on the GC to expand the heap.

Another performance criterion is pause time. However, the behaviour of "low pause" collectors is too complicated for the simplistic style of analysis above. (And I don't how it typically works out in practice ...)


There is one aspect that applies across the board. Assuming that the application's heap usage reaches a (roughly) steady state, and assuming that it reaches that state early on in the life-time of the JVM, the various performance overheads involved in reaching that steady state (i.e. the application's "warmup" overheads) will tend towards being insignificant.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216