Chapter 4. JVM Tuning
Configuring optimal JVM options for your applications and JBoss EAP environment is one of the most fundamental ways to tune performance. This chapter covers configuring some general JVM options.
Many of the JVM options listed in this chapter can be easily generated using the JVM Options Configuration Tool on the Red Hat Customer Portal.
4.1. Setting a Fixed Heap Size
You must set an appropriate heap size to prevent out of memory errors.
-Xms option sets the initial heap size, and
-Xmx sets the maximum heap size. It is recommended for production environments that you set the initial and maximum heap size options to the same size, so that the heap size is fixed and pre-allocated.
For example, the following options set a 2048 MB heap size:
It is recommended that you test your applications under load in a development environment to determine the maximum memory usage. Your production heap size should be at least 25% higher than the tested maximum to allow room for overhead.
4.2. Configuring the Garbage Collector
Although the parallel garbage collector, also known as the throughput garbage collector, is the default garbage collector in Java 8 for server-class machines, Red Hat recommends using the G1 garbage collector, which is expected to be the default from Java 9 onward. The G1 garbage collector generally performs better than the CMS and parallel garbage collectors in most scenarios.
To enable the G1 collector, use the following JVM option:
Garbage Collection Logging Options
Garbage collection logging is enabled by default for standalone JBoss EAP servers. To enable garbage collection logging for a JBoss EAP managed domain, see Section 3.1, “Enabling Garbage Collection Logging”.
4.3. Enabling Large Pages
Enabling large pages for JBoss EAP JVMs results in pages that are locked in memory and cannot be swapped to disk like regular memory.
Especially for memory-intensive applications, the advantage of using large pages is that the heap cannot be paged or swapped to disk, and is thus always readily available.
One disadvantage of using large pages is that other processes running on the system might not have quick access to memory, which might result in excessive paging for these processes.
As with any other performance configuration change, it is recommended that you test the impact of the change in a testing environment.
You must ensure that your operating system configuration allows for processes to use large pages.
For Red Hat Enterprise Linux systems, you must explicitly configure
HugeTLBpages to guarantee that JBoss EAP processes will have access to large pages.
For information on configuring Red Hat Enterprise Linux memory options, see the Memory chapter in the Red Hat Enterprise Linux Performance Tuning Guide.
For Windows Server systems, the user that is running JBoss EAP must have the large pages privilege assigned:
- Select Control Panel → Administrative Tools → Local Security Policy.
- Select Local Policies → User Rights Assignment.
- Double-click Lock pages in memory.
- Add the Windows Server users and user groups that you want to use large pages.
- Restart the machine.
Enable or disable large page support:
To explicitly enable large page support for JBoss EAP JVMs, use the following JVM option:
To explicitly disable large page support for JBoss EAP JVMs, use the following JVM option:
When starting JBoss EAP, ensure that there are no warnings related to reserving memory.
On Red Hat Enterprise Linux, an error might look like:
OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory. (error = 1)
On Windows Server, an error might look like:
Java HotSpot(TM) 64-Bit Server VM warning: JVM cannot use large page memory because it does not have enough privilege to lock pages in memory.
If you do see warnings, verify that your operating system configuration and JVM options are configured correctly.
For more information, see the Oracle documentation on Java support for large pages.
4.4. Enabling Aggressive Optimizations
Using the aggressive optimizations (AggressiveOpts) JVM option can provide performance improvements for your environment. This option enables Java performance optimization features that are expected to become default in future Java releases.
To enable AggressiveOpts, use the following JVM option:
4.5. Setting ulimits
For Red Hat Enterprise Linux and Solaris platforms, you must configure appropriate
ulimit values for JBoss EAP JVM processes. The "soft"
ulimit can be temporarily exceeded, while the "hard"
ulimit is the strict ceiling for the usage of a resource. Appropriate
ulimit values vary depending on your environment and applications.
If you are using IBM JDK, it is important to note that IBM JDK uses the soft limit for the maximum number of open files used by a JVM process. On Red Hat Enterprise Linux, the default soft limit (
1024) is considered too low for JBoss EAP processes using IBM JDK.
If the limits applied to JBoss EAP processes are too low, you will see a warning like the following when starting JBoss EAP:
WARN [org.jboss.as.warn.fd-limit] (main) WFLYSRV0071: The operating system has limited the number of open files to 1024 for this process; a value of at least 4096 is recommended.
To see your current
ulimit values, use the following commands:
To set the
ulimit for the maximum number of open files, use the following commands with the number you want to apply:
To set the soft
ulimitfor the maximum number of open files:
ulimit -Sn 4096
To set the hard
ulimitfor the maximum number of open files:
ulimit -Hn 4096
To guarantee that a
ulimit setting is effective, it is recommended on production systems to set the soft and hard limits to the same value.
For more information on setting
ulimit values using a configuration file, see How to set ulimit values on the Customer Portal.
4.6. Host Controller and Process Controller JVM Tuning
JBoss EAP managed domain hosts have separate JVMs for the host controller and process controller. See the JBoss EAP Configuration Guide for more information on the roles of host controllers and process controllers.
You can tune the host controller and process controller JVM settings, but even for large managed domain environments, the default JVM configuration for the host controller and process controller should suffice.
The default configurations for host controller and process controller JVMs have been tested with a managed domain size of up to 20 JBoss EAP hosts each running 10 JBoss EAP servers, for a total domain size of 200 JBoss EAP servers.
If you experience issues with larger managed domains, you might need to monitor the host controller or process controller JVMs in your environment to determine appropriate values for JVM options such as heap size.