Tune the Java Virtual Machine settings of a standalone server as well as a managed domain.
| Resources | |
|---|---|
| Directories: |
|
| Application URL: | NA |
| Resources | NA |
Outcomes
You should be able to configure the Java Virtual Machine (JVM) options for the Red Hat JBoss Enterprise Application Platform (JBoss EAP) server in standalone and managed domain modes.
Before beginning the guided exercise, run the following command to prepare the environment:
[student@workstation ~]$ lab start jvm-domain
Instructions
Configure JVM options for a standalone server by using the JBOSS_HOME/bin/standalone.conf file.
Edit the file /opt/jboss-eap-7.4/bin/standalone.conf by using a text editor of your choice.
Note that you have to edit this file as the jboss user:
[student@workstation ~]$ sudo -u jboss vi /opt/jboss-eap-7.4/bin/standalone.confObserve the JVM options in the $JAVA_OPTS variable.
The -Xms JVM minimum heap size and the -Xmx maximum heap size have the 1303m value by default.
...output omitted...
#
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms1303m -Xmx1303m \
-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m \
-Djava.net.preferIPv4Stack=true"
JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
else
echo "JAVA_OPTS already set in environment; overriding default options with values: $JAVA_OPTS"
fi
...output omitted...These default values might not be enough for larger applications and might cause out of memory (OOM) errors in the JVM due to excessive memory consumption by the application.
It is recommended to set the minimum and maximum heap sizes based on the object allocation characteristics of the application. You should also tune the garbage collection (GC) settings after profiling the application under production work loads.
Set the minimum and maximum JVM heap size to 1500m (1.5 GB) .
JAVA_OPTS="-Xms1500m -Xmx1500m\
-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m\
-Djava.net.preferIPv4Stack=true"Start the standalone JBoss EAP server.
Run the following command to start a JBoss EAP instance by using the /home/student/AD248/labs/jvm-domain/standalone directory as the server base directory:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./standalone.sh \-Djboss.server.base.dir=/home/student/AD248/labs/jvm-domain/standalone/
Observe the console window where JBoss EAP is starting, and verify that the new JVM options are in use:
JBoss Bootstrap Environment
JBOSS_HOME: /opt/jboss-eap-7.4
JAVA: java
JAVA_OPTS: -server -Xlog:gc*:file="/home/student/AD248/labs/jvm-domain/standalone/log/gc.log":time,uptimemillis:filecount=5,filesize=3M -Xms1500m -Xmx1500m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
...output omitted...You can also verify that the new options are in effect by running the following command to view the full arguments to the java process representing the JBoss EAP Standalone server:
[student@workstation bin]$ps -aef | grep javastudent 5785 5669 5 06:32 pts/0 00:00:11 java -D[Standalone] -server -Xlog:gc*:file=/home/student/AD248/labs/jvm-domain/standalone/log/gc.log:time,uptimemillis:filecount=5,filesize=3M-Xms1500m -Xmx1500m-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED --add-exports=java.desktop/sun.awt=ALL-UNNAMED ...output omitted...
Stop the JBoss EAP instance by pressing Ctrl+C in the terminal.
Configure the JVM options for a managed domain.
Start the domain controller in machine1.
[student@workstation bin]$./domain.sh \-Djboss.domain.base.dir=/home/student/AD248/labs/jvm-domain/machine1/ \--host-config=host-master.xml
Start the host controller on machine2.
In a new terminal window on your workstation run the following commands:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./domain.sh \-Djboss.domain.base.dir=/home/student/AD248/labs/jvm-domain/machine2/ \--host-config=host-slave.xml \-Djboss.domain.master.address=172.25.250.9
Start the host controller on machine3.
In a new terminal window on your workstation run the following commands:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./domain.sh \-Djboss.domain.base.dir=/home/student/AD248/labs/jvm-domain/machine3/ \--host-config=host-slave.xml \-Djboss.domain.master.address=172.25.250.9
Verify that all four servers in the managed domain start with a minimum and maximum heap size of 1000 MB.
[student@workstation bin]$ps -aef | grep server-onestudent 13893 13793 27 07:26 pts/2 00:00:13 /usr/lib/jvm/java-11-openjdk-11.0.14.1.1-6.el9.x86_64/bin/java -D[Server:server-one] -D[pcid:1181613295]-Xms1000m -Xmx1000m-server -XX:MetaspaceSize=96m -XX:MaxMetaspaceSize=256m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Djboss.domain.base.dir=/home/student/AD248/labs/jvm-domain/machine2/ -Djboss.domain.master.address=172.25.250.9 -Djboss.home.dir=/opt/jboss-eap-7.4 -Djboss.modules.system.pkgs=org.jboss.byteman --add-exports=java.base/sun.nio.ch=ALL-UNNAMED ...output omitted...
Override the JVM options for the server group Group1 and set the minimum and maximum JVM heap size value to 500m (500 MB).
Navigate to the management console at http://172.25.250.9:9990/.
Log in with admin as the username and redhat123 as the password.
Navigate to → → in the management console.
Click the arrow icon near to the button, and select the option to stop all servers in Group1.
Click in the confirmation window.
When all the servers in Group1 have stopped, click the button next to Group1 to view the Group1 configuration page.
Click the tab, and then click .
Use the dev-group-jvm name to create the JVM, and click .
In the list of JVMs select . Click , configure the following JVM options and click :
| Field | Value |
|---|---|
Heap Size
|
500m
|
Max Heap Size
|
500m
|
In the list of JVMs select , and click .
Click in the confirmation window.
Open the /home/student/AD248/labs/jvm-domain/machine1/configuration/domain.xml domain configuration file with an editor of your choice, and verify that the Group1 server group now references the dev-group-jvm JVM.
...output omitted... <server-group name="Group1" profile="default"> <jvm name="dev-group-jvm"> <heap size="500m" max-size="500m"/> </jvm> <socket-binding-group ref="standard-sockets"/> </server-group> ...output omitted...
Start the servers in Group1 by using the management console, and verify that the JVM changes take effect.
Navigate to → → in the management console.
Click the arrow icon near to , and select the option to start Group1 servers.
Observe that the server-one and server-three servers in Group1 have started with 500 MB as the minimum and the maximum heap size.
[student@workstation bin]$ps -aef | grep server-onestudent 15079 13793 32 07:50 pts/2 00:00:13 /usr/lib/jvm/java-11-openjdk-11.0.14.1.1-6.el9.x86_64/bin/java -D[Server:server-one] -D[pcid:233340618]-Xms500m -Xmx500m-Djava.awt.headless=true ...output omitted...
The server-two and server-four servers in Group2 are still running with the default JVM options because you did not override the settings for Group2.
Override the JVM options inherited from the host level or the server group level by configuring the JVM options at the individual server level.
Set the minimum and maximum JVM heap size of the server-three server to 1200m (1.2 GB).
Also, set the AggresiveOpts JVM option to perform runtime code optimization.
Use the management CLI to modify those values at the server level.
Launch the management CLI in a new terminal window:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./jboss-cli.sh --connect --controller=172.25.250.9:9990
Change the server-three JVM options by using the CLI command:
[domain@172.25.250.9:9990 /]/host=host2/server-config=server-three\/jvm=server-three-jvm:add\(heap-size=1200m,max-heap-size=1200m,jvm-options=["-XX:+AggressiveOpts"]){ "outcome" => "success", ... "response-headers" => { "operation-requires-restart" => true, "process-state" => "restart-required" } }
Restart server-three to apply the changes:
[domain@172.25.250.9:9990 /]/host=host2\/server=server-three:restart(blocking=true){ "outcome" => "success", "result" => "STARTED" }
Open the host configuration file for host2 at /home/student/AD248/labs/jvm-domain/machine2/configuration/host-slave.xml with an editor of your choice, and verify that the server-three server defines a <jvm> section called server-three-jvm:
...output omitted... <jvm name="server-three-jvm"><heap size="1200m" max-size="1200m"/><jvm-options><option value="-XX:+AggressiveOpts"/></jvm-options> </jvm> ...output omitted...
Observe that only server-three has started with the new JVM options.
Also, verify that server-one still runs with the JVM options inherited from the server group level option for Group1:
[student@workstation bin]$ps -aef | grep server-threejava -D[Server:server-three]-Xms1200m -Xmx1200m -XX:+AggressiveOpts-Djava.awt.headless=true ...output omitted... [student@workstation bin]$ps -aef | grep server-onejava -D[Server:server-one]-Xms500m -Xmx500m -server-Djava.awt.headless=true ...output omitted...
Clean Up
Exit the management CLI, and stop the managed domain by pressing Ctrl+C in all the three terminal windows where you started JBoss EAP.