Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Java automatic heap increase "transparent" or it have a cost?

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)?

like image 364
BlacK Avatar asked Nov 01 '22 09:11

BlacK


1 Answers

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.

like image 96
Stephen C Avatar answered Nov 15 '22 03:11

Stephen C