Java Heap settings best practice

Issue

  • Best Practice For Java Heap settings

Environment

Resolution

To set the heap size, you can update -Xms and -Xmx parameters in the command-line argument of the JVM.

Limits

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

B. Set your minimum heap size ( -Xms) to at least 1/2 of your maximum size ( -Xmx).

C. For 64 bit JVM, set -Xmx less than 32G to benefit from -XX:+UseCompressedOops (which comes activated by default in recent JVM).

D. Jenkins should not be started with less than -Xmx2g. However, for production environment with a considerable job workload, Jenkins should run with -Xmx16g or so. In the case your instance demands more than -Xmx16g any of the following points could be happening.

  • Other factors, apart from the Heap Size, are not taking into consideration for improving your performance. please review: CJP Performance Best Practices for Linux.
  • Your instance is not able to support its current workload (number of jobs and configuration) so you should consider about scaling horizontally your infra (more masters) to divide this workload more efficiently.

Estimation

F. The Jenkins Monitoring Plugin can be installed temporally (It’s not recommendable for Production Environments) to monitor the performance of your instance, the right heap value which should be a value between 80-90% of total heap consumption when the instance is at the maximum workload. Big heap memory values might produce big GC pauses which means slowness and sometimes even side effects like agent disconnections.

E. Running Jenkins inside a Docker Container: The following points talks about how to calculate the max heap size for a Java application running in a Docker Container.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.