Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I really need to define java minimum heap size

I'm about to deploy an application to a live server and right now I am at the part where I have to set heap and permgen sizes for the jvm. I have seen a lot of articles and all of them say to "set the minimum heap size to (some number)", and to "set the maximum heap size to (some number)", but none of these articles really says why the minimum heap size needs to be set. I understand the reason to set the maximum heap size, but not about the minimum. I would be thankful if you shed some light on this.

like image 469
Martin Asenov Avatar asked May 15 '12 16:05

Martin Asenov


2 Answers

The heap in Java is the general memory allocation area. Let us suppose that we set the minimum heap size to 1000 bytes (this is an absurdly low number). Now lets say that I instantiate an object in my program that contains some text that is two thousand characters long. I cannot save this object without first expanding my heap size. Now, presumably my maximum heap parameter is large enough to allow this - but that is the reason to set the maximum heap size.

However, suppose my server has 4G of ram, and I set the minimum heap size to that. (An absurdly large number.) If no other programs took up any memory, this would work. However, if I started a second process with my java program, it would not be able to allocate sufficient memory and quit.

The minimum size does two things for you; first, it makes memory available quickly to allow rapid startup. Secondly, it lets you tune your jvm so that you have some invariants, allowing you to make predictions about how many processes you can run. If your minimum heap size is too large, you're probably wasting memory on a process that never needs that much, limiting the capacity of your system. If you set it too small, programs will take a long time to start up, adversely affecting the process's performance.

like image 120
Nathaniel Ford Avatar answered Oct 21 '22 01:10

Nathaniel Ford


Setting a minimum heap size allows Java to allocate some memory up front which improves startup time.

like image 39
sproketboy Avatar answered Oct 21 '22 02:10

sproketboy