Java Heap settings best practice


  • Best Practice For Java Heap settings




A. According to Oracle JVM ergonomic page, the maximum heap size should be 1/4 of the physical memory. This threshold is also extended when Jenkins is running inside a VM and/or Docker Container (maximum heap size limits are aggregated when there are more than one Java application running on the same host).

B. Set your minimum heap size (-Xms) to the same value as maximum size (-Xmx). As a JVM Administrator, you should know the needs of the application based on current usage if you are following Best Practices and collecting Garbage Collection logs. If you need assistance with analyzing your GC logs, please submit a support ticket.

C. Jenkins should not be started with less than -Xmx2g. However, no more than -Xmx16g should be allocated to heap per our Best Practices and horizontal scaling should be employed.


If your instance is not able to support its current workload (due to number of jobs and dynamic configurations) you should consider scaling horizontally your infrastructure by adding more masters to divide the workload more efficiently.


D. The Jenkins Monitoring Plugin can be installed to monitor the performance of your instance, the right heap value should be a value between 80-90% of total heap consumption when the instance is at the maximum workload. Increased heap memory will produce long Garbage Collection pauses, which can be observed via slowness in the UI and sometimes even side effects like agent disconnections.

Have more questions?


  • 0
    Kostiantyn Gorbunov

    According to Oracle JVM ergonomic page, the maximum heap size NEVER should be 1/4 of the physical memory IN GENERAL CASE. If you read actual source it is just DEFAULT value 1/4 or mem and < 1 GB. This example never ever ever should appear on that kind of reference material.

  • 0
    Carlos Rodriguez Lopez

    @Kostiantyn Gorbunov Thanks for pointing this out

Please sign in to leave a comment.