Bookmark this page

Guided Exercise: Configuring Java Virtual Machines

Tune the Java Virtual Machine settings of a standalone server as well as a managed domain.

Resources
Directories:

/home/student/AD248/labs/jvm-domain/standalone

/home/student/AD248/labs/jvm-domain/machine1/

/home/student/AD248/labs/jvm-domain/machine2/

/home/student/AD248/labs/jvm-domain/machine3/

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

  1. Configure JVM options for a standalone server by using the JBOSS_HOME/bin/standalone.conf file.

    1. 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.conf
    2. Observe 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.

    3. 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"
    4. 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/
    5. 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...
    6. 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 java
        student     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...
    7. Stop the JBoss EAP instance by pressing Ctrl+C in the terminal.

  2. Configure the JVM options for a managed domain.

    1. 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
    2. 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
    3. 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
    4. 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-one
      student    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...
    5. 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.

    6. Navigate to RuntimeServer GroupsGroup1 in the management console.

      Click the arrow icon near to the View button, and select the Stop option to stop all servers in Group1. Click Yes in the confirmation window.

    7. When all the servers in Group1 have stopped, click the View button next to Group1 to view the Group1 configuration page.

      Click the JVMs tab, and then click Add. Use the dev-group-jvm name to create the JVM, and click Add.

      In the list of JVMs select dev-group-jvm. Click Edit, configure the following JVM options and click Save:

      FieldValue
      Heap Size 500m
      Max Heap Size 500m
    8. In the list of JVMs select default, and click Remove.

      Click Yes in the confirmation window.

    9. 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...
    10. Start the servers in Group1 by using the management console, and verify that the JVM changes take effect.

      Navigate to RuntimeServer GroupsGroup1 in the management console. Click the arrow icon near to View, and select the Start option to start Group1 servers.

    11. 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-one
      student    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.

    12. 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"
      }
    13. 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...
    14. 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-three
      java -D[Server:server-three] -Xms1200m -Xmx1200m -XX:+AggressiveOpts -Djava.awt.headless=true
      ...output omitted...
      [student@workstation bin]$ ps -aef | grep server-one
      java -D[Server:server-one] -Xms500m -Xmx500m -server -Djava.awt.headless=true
      ...output omitted...
  3. Clean Up

    1. Exit the management CLI, and stop the managed domain by pressing Ctrl+C in all the three terminal windows where you started JBoss EAP.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish jvm-domain

Revision: ad248-7.4-18a9db2