I have always wondered, why does Java require you set the heap size manually? I was under the impression that programs written in other languages would just allocate as much memory as needed as the program run until the OS could allocate no more.
In the Java world we need to set the heap, stack, and permgen size. While this is simple enough forgetting to increase these to "large enough" numbers is the #1 reason I have seen servers go down.
Why is it not possible to tell Java to grow the heap/stack/permgen as much as it needs over time?
Heap space is used for the dynamic memory allocation of Java objects and classes at runtime. New objects are always created in the heap space, and references to these objects are stored in the stack memory.
A larger heap size also means that a larger amount of time is needed to find and process objects that need to be collected. When you plan for system memory consumption, include additional processor memory for the JVM to use outside of the heap size and random access memory (RAM) for the operating system.
A too small heap size may affect performance if your system also does not have enough cores, so that the garbage collectors do compete over the CPU with the business threads. At some point, the CPU spends a significant time on garbage collection.
Initial heap size is 1/64th of the computer's physical memory or reasonable minimum based on platform (whichever is larger) by default. The initial heap size can be overridden using -Xms. Maximum heap size is 1/4th of the computer's physical memory or 1 GB (whichever is smaller) by default.
Three reasons:
My interpretation is that Sun is a company focused on selling Big Boxes and they like that the sysadmins can do things on these boxes. Running a system to fill all the memory is a good way to run it into the ground and be unable to efficiently take action to restore operation because you cannot allocate memory to create a login shell for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With