• Post Reply Bookmark Topic Watch Topic
  • New Topic

large difference between -Xms and -Xmx values in jvm

 
Mike Ottinger
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

Could somebody please tell me the reason why it's not a good idea to have a much larger -Xmx value than an -Xms? The settings on my prod JRun4 box are set at -Xmx 256m and -Xms32m. I've read in places that these 2 values should be equal to each other.

- M.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-Xmx is the maximum Java heap size, and -Xms is the initial Java heap size. If they're different, then the JVM process size starts small, and grows as needed. If they're the same, then the JVM starts out using as much memory as it will ever use.

It's useful to make them different if you want to be conservative about requesting memory from the OS. It's useful to make them the same if your process will run for only a short time, but will be performance-critical during that time. I don't think it's possible to make a single, general statement about one arrangement being better than the other.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that there are sometimes good reasons to have widely-different values for -Xmx and -Xms, and sometimes good reasons to use the same value for both.

Widely-different values would be a good idea if you have a program that might need a small or a large amount of memory, depending on information only available at run-time (e.g. user input). If you were to use the same value for both -Xmx and -Xms in this situation, then you would have to make it a very large value and that would waste the resources of the computer for runs when the requirement was actually small.

On the other hand, using the same value for both can boost overall performance, as no time is lost resizing the heap, or thrashing the GC, trying to work within a small heap. Another time when it is useful (one I have experience of) is when there is another application that grabs a large proportion of available memory. The Java application needs to claim enough memory straight away, otherwise this other application will claim it, and prevent the Java application from getting more later.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!