Do the -Xms and -Xmx flags reserve the machine's resources?

前端 未结 3 686
眼角桃花
眼角桃花 2021-01-01 15:31

I know that the -Xms flag of JVM process is to allow the JVM process to use a specific amount of memory to initialize its process. And in regard to performance

3条回答
  •  既然无缘
    2021-01-01 15:50

    Does JVM process makes a reservation for the specific amount of memory?

    Yes, the JVM reserves the memory specified by Xms at the start and might reserve upto Xmx but the reservation need not be in the physical memory, it can also be in the swap. The JVM pages will be swaped in and out of memory as needed.


    Why is it recommended to have same value for Xms and Xmx?

    Note: Setting Xms and Xmx is generally recommended for production systems where the machines are dedicated for a single application (or there aren't many applications competing for system resources). This does not generalize it is good everywhere.

    Avoids Heap Size:

    The JVM starts with the heap size specified by the Xms value initially. When the heap is exhausted due to allocation of objects by the application. The JVM starts increasing the heap. Each time the JVM increases the heap size it must ask the operating system for additional memory. This is a time consuming operation and results in increased gc pause times and inturn the response times for the requests.

    Applications Behaviour In the Long Run:

    Even though I cannot generalize, many applications over the long run eventually grow to the maximum heap value. This is another reason to start of with maximum memory instead of growing the heap over time and creating unnecessary overhead of heap resize. It is like asking the application to take up the memory at the start itself which it will eventually take.

    Number of GCs::

    Starting off with small heap sizes results in garbage collection more often. Bigger heap sizes reduce the number of gcs that happen because more memory is available to object allocation. However it must be noted that increased heap sizes increases gc pause times. This is an advantage only if your garbage collection has been tuned properly and the pause times don't increase significantly with increase in heap sizes.

    One more reason for doing this is servers generally come with large amounts of memory, So why not use the resources available?

提交回复
热议问题