I really need to determine the minimum java heap size

I am going to deploy the application on a real server, and now I am in the part where I need to set the heap and perm sizes for jvm. I've seen a lot of articles, and they all say "set the minimum heap size to (some number)" and "set the maximum heap size to (some number)", but none of these articles really say why the minimum heap size should be set . I understand the reason for setting the maximum heap size, but not about the minimum. I would be grateful if you shed light on this.

+6
source share
3 answers

A heap in Java is a shared memory allocation area. Suppose we set the minimum heap size to 1000 bytes (this is an absurdly small number). Now let's say that I create an instance of an object in my program that contains text two thousand characters long. I cannot save this object without first expanding the heap size. Now, presumably, my maximum heap parameter is large enough for this to be possible, but this is the reason for setting the maximum heap size.

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

The minimum size does two things for you; Firstly, it quickly allows RAM to provide a quick start. Secondly, it allows you to customize your jvm so that you have some invariants that allow you to make predictions about how many processes you can start. If your minimum heap size is too large, you are probably wasting memory on a process that never needs it, limiting the capacity of your system. If you set it too small, the programs will take a long time to start, which will negatively affect the performance of the process.

+6
source

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

+1
source

Setting the minimum size explicitly (above the default) helps with fragmentation of placement at the OS level and startup speed.

The Java heap is supported by memory allocated by the OS, the larger the initial block, the less redistribution and fragmentation.

Setting the minimum value equal to or almost equal to the maximum will completely eliminate these situations.

+1
source

Source: https://habr.com/ru/post/915819/


All Articles