3

Suppose I am running tomcat with -Xms256m -Xmx1024m, but would like to increase my heap usage.

What is the largest safe heap size I can allocate?

For the purpose of this question, please assume, the system has 5GB RAM and is a z/Linux system. However, if possible I would like a broader rule of thumb answer.

Also, if this is a duplicate, sorry. I was surprised I did not find more information on this kind of thing.

Not duplicate of: I looked at here, however, his answer seems to just be a guess, with no backup. The other answers in that question are not very clear and/or specific to my problem. 1) I am not on a window 32 bit system, 2) I was not asking about PermGen, though it may be mentioned in a good answer, 3) The third answer did say "Finally, you also have to take into account the other things that are running on the server and that need RAM too" but this is not a precise answer. I am just worried about the OS usage of memory for now.

Edit: This is dedicated system, so I am mostly worried about the OS memory usage. I am not worried about other programs.

GC

GC_
  • 211
  • 2
  • 6
  • 1
    possible duplicate of [java max heap size, how much is too much](http://serverfault.com/questions/120787/java-max-heap-size-how-much-is-too-much) – JamesRyan May 22 '15 at 16:42
  • Even though other applications may not be running, the memory footprint of your specific system is not equal to other systems. You have different drivers, configurations, services, and other things that will run in the background that you must account for in your specific setup. The only way to do that is to look at your performance logs. If you're trying to optimize for performance, there is no way to do it without looking at performance logs. – IceMage May 22 '15 at 17:36
  • I made that edit before I was your answer. I just what you mean. I am surprise that OS itself does not have guidance. Also, like I side, this is a dedicated machine. – GC_ May 22 '15 at 17:56
  • 1
    There is no solid answer. Nobody is going to tell you "Put your heap size as X megabytes and profit," because you should be able to determine how much memory your java app can use based on the available resources of your system, which vary greatly depending on the hardware you have. Calculate the amount of resources you have, allocate a percentage of that, and tweak from there. – IceMage May 22 '15 at 19:01
  • Still think it useful to have a basic idea of how much ram an OS needs to run correctly. I think a clear how-to for looking at the logs, to figure this out would be helpful. – GC_ Jan 14 '16 at 21:34
  • Still think this is a valid question. I don't know where these trolls come from. Every serious java administrator has to ask themselves this every time they setup a server. – GC_ Apr 21 '20 at 23:04

1 Answers1

1

The Maximum heap size you will want to assign will be based on your system's utilization of it's own resources, other services you are running, etc. You want to assign a heap size that leaves enough memory available to the OS to prevent unnecessary memory paging. This is more of a problem in Windows, but the problem is seen in Linux too (I'm more of a Windows expert than Linux, so sorry for that).

First, You want to check your systems' resource utilization: http://www.cyberciti.biz/faq/linux-check-memory-usage/

Next, you want to see how your page file is configured: http://www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/

Then, you're going to have to try different configurations based on the information you gathered before, and watch your page file utilization: http://www.cyberciti.biz/faq/linux-check-swap-usage-command/

If your page file is being utilized a lot, then your Heap size is too big. If it's being utilized very little, or not at all, you can try increasing your heap size to improve performance (Actual performance results will vary among different Java apps, and increasing heap size can make some apps perform worse due to the way in which they are programmed).

You want to make sure that you assign the appropriate amount memory so that your OS will have enough free RAM to easily maintain the page file, and your application has plenty of memory assigned to it. In Windows, I try to maintain at least 25% free RAM under load. I'd try different configurations and watch your system performance.

ONE MORE IMPORTANT NOTE THOUGH: In Java 8, you don't need to define these items at all, Java 8 seems to be better at maintaining these values on its own, rather than having them statically assigned.

IceMage
  • 1,336
  • 7
  • 12