Scenario
Users have reported that the new benefits application is running slowly. You investigate
WebLogic Server’s use of the JVM’s memory as well as CPU usage while the new application is being accessed.
Overview
In this practice, you troubleshoot a HotSpot JVM by using Java Visual VM (JVisualVM) and Java Mission Control.
Assumptions
You completed practice “4-1: Configuring and Monitoring Diagnostic Events.” All instances of WebLogic Server are running.
Tasks
1. Run the setup script to deploy the new application.
a. Access host01. Open a Terminal window and run the setup script in the current practice directory.
$> cd /practices/tshoot/practice05-01 $> ./setup.sh
Note:
− The script deploys the new benefits application. This application: − Overuses the CPU
− Hogs memory
− Please ignore any messages about:
− An insecure protocol being used to connect to the admin server. − WLContext.close() being called in a different thread.
2. Find the process ID of server1 by using the JVM Process Status tool.
a. In a Terminal window, navigate to the bin directory of the JVM and run the jps
command with the -v argument.
$> cd /u01/app/jdk/bin $> ./jps -v
Note: The jps (JVM Process Status) command lists running JVMs. The -v option tells the command to output arguments passed to the JVM.
b. Look through the output. The first thing listed in each entry is the process ID. Two of the listings should be WebLogic Servers (after the PID it says: Server). Find the one that is server1 (within the arguments passed to the JVM is an option that gives the server name: -Dweblogic.Name=server1).
c. Make note of the PID of server1.
3. Run the JVisualVM tool to view CPU and memory usage before simulating users accessing the new benefits application.
a. In a Terminal window, navigate to the bin directory of the JVM and run the
jvisualvm command.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Practices for Lesson 5: JVM Troubleshooting
Chapter 5 - Page 4
$> cd /u01/app/jdk/bin $> ./jvisualvm
Note: If an informational window is displayed about calibration, click OK. Then click OK again.
b. When the graphical user interface comes up, under the Applications tab, expand
Local (if it is not already expanded). Find the WebLogic JVM that matches the PID of
server1 which you discovered earlier. Double-click this JVM.
Note: The “pid” values and other processes in the list may not match this screenshot
exactly.
c. On the right side, there is now a WebLogic tab. It starts out displaying the Overview subtab. Click the Monitor subtab.
Oracle University and In Motion Servicios S.A. use only
d. Leave JVisualVM running. You can minimize it, if you want. Also, do not close the Terminal window that started JVisualVM, because this will exit the program. 4. Run a Grinder script to simulate users accessing the new benefits application.
a. In a new Terminal window, from the current practice directory, run the script to call the Grinder.
$> cd /practices/tshoot/practice05-01 $> ./rungrinder.sh
b. Do not close this Terminal window. You can minimize it, if you want.
5. Return to JVisualVM tool. View how the CPU and memory usage are affected by the Grinder script. Use the tool to help figure out what is causing these effects.
a. Return to JVisualVM on the same screen as before: the server1 WebLogic JVM, and the Monitor tab.
Note: Notice the CPU usage spikes and the memory usage goes up dramatically.
b. Use JVisualVM to look into the CPU issue. Click the Sampler tab. Then click the CPU button. Watch for a little while. Are there any methods in the application using a lot of CPU?
Note: The results may not be exactly the same for you as shown, but the service()
method of BenefitsServlet is probably using a large percentage of the CPU. You have not looked at the code of the benefits application, but based on the name of this Servlet, the odds are that it is part of the benefits application.
c. Click the Stop button.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Practices for Lesson 5: JVM Troubleshooting
Chapter 5 - Page 6
d. See if you can determine what is taking so much memory. Click the Memory button under the Sampler tab. Watch for a little while.
Note: There are always many char arrays and String instances around. But it seems in this case a Byte array is taking a large percentage of the memory. e. Click the Stop button again.
f. Close JVisualVM.
Tip: You can exit the tool by using File > Exit in the menu.
6. Stop the Grinder script.
a. In a new Terminal window, navigate to the current practice directory and run a script to kill the Grinder processes.
$> cd /practices/tshoot/practice05-01 $> ./killgrinder.sh
b. Verify it worked by looking at the Terminal window in which you started the Grinder script. There should be a message that things were killed and the prompt should display again.
7. Set some flags so all of Java Mission Control is accessible in the JVM running server1. a. Access the administration console, log in, and lock the configuration.
b. Navigate to server1.
c. Click Configuration > Server Start.
d. In the Arguments text area enter:
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder
Note: This will ensure the flight recorder in Mission Control will work. Be careful to
enter the arguments exactly as shown. There are no spaces in each argument. The “XX” are capital letters.
e. Click Save.
f. Activate the changes.
Oracle University and In Motion Servicios S.A. use only
g. Even though the message says that no restarts are necessary, you do need to restart server1 for these flags to take effect. Use the admin console to force shutdown and then restart server1.
Tip: Environment > Servers > Control. Select the check box in front of server1 and
click Shutdown > Force Shutdown Now. Click Yes. Select the check box again and click Start. Click Yes.
h. Wait for the server to be running before continuing.
8. Investigate the same issues as before by using Java Mission Control.
a. Because you stopped and restarted server1, it will now have a different process ID. Return to host01. In a Terminal window, navigate to the bin directory of the JVM and use the jps command again to find the new process of server1. This time use grep to eliminate output not needed. Make note of server1’s PID.
$> cd /u01/app/jdk/bin $> ./jps –v | grep server1
b. Now run the jmc command.
$> ./jmc
Note: Ignore any messages or warnings in the Terminal window.
c. When the graphical user interface comes up, under the JVM Browser tab, locate the
WebLogic Server entry with the correct PID (the number in parentheses). Expand that
entry and double-click MBean Server. Under the new WebLogic Server tab, ensure that the General icon is selected.
Tip: If you do not see the JVM Browser tab, click Window > Show View > JVM Browser. You can also close the Welcome tab.
d. Leave Java Mission Control (JMC) running. You can minimize it, if you want. Also, do not close the Terminal window that started JMC, because this will exit the program. e. Run the Grinder script again.
Tip: In a different Terminal window, from the current practice directory, run the script
rungrinder.sh again.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Practices for Lesson 5: JVM Troubleshooting
Chapter 5 - Page 8
f. Leave the Grinder script window open and return to JMC. Watch for a while.
Note: Notice the CPU spikes and the memory usage goes up, as before.
9. <OPTIONAL> Create and view a Java Flight Recording.
a. First, set the diagnostic volume of server1 to “High,” so the flight recording has more data. Access the admin console and lock the configuration. Navigate to Environment > Servers > server1 > Configuration > General. Use the drop-down list to set
Diagnostic Volume to High. Save and activate your changes. b. Return to Java Mission Control on host01.
c. Below the MBean Server entry of the server1 WebLogic Server, right-click on Flight Recorder.
d. Select Start Flight Recording.
e. In the window that opens leave all the defaults and click Finish.
f. Click the arrow next to Flight Recorder in the JVM Browser so you can see the new recording, My Recording (the default name).
g. The default recording time is 1 minute. Once it counts down and completes the recording it will open a new tab to display the recording.
Note: It may take a little while to finish recording and appear.
h. Click around on the various icons and tabs to view the flight recording. 10. Exit Java Mission Control.
a. Exit JMC by clicking File > Exit.
b. Close the Terminal window in which you started JMC.
Oracle University and In Motion Servicios S.A. use only
11. Stop the Grinder script again.
a. In a new Terminal window, navigate to the current practice directory and run a script to kill the Grinder processes, killgrinder.sh.
b. Verify the Grinder has been killed. 12. Clean up.
a. Return to the admin console and set the Diagnostic Volume of server1 back to “Low.” Save and activate the change.
b. Return to host01. In a Terminal window in the current practice directory, run the cleanup script.
$> cd /practices/tshoot/practice05-01 $> ./cleanup.sh
Note: This script calls a WLST script to undeploy the benefits application.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Practices for Lesson 5: JVM Troubleshooting
Chapter 5 - Page 10