IBM Support

Methods for Extracting Java Heap Values and Monitoring Java Heap Usage in WebSphere

Technical Blog Post


Abstract

Methods for Extracting Java Heap Values and Monitoring Java Heap Usage in WebSphere

Body

     

There are a few methods or ways to verify Configured Heap Values and monitor Current Heap Usage in WebSphere Application Server as well as a few different dump and file types useful for this task.

 

Useful Dumps and Files containing information about your Java Heap.

 

Javacores txt files are useful to determine Initial, Maximum and Current Heap values along with Threading and Locking information and even include a Native Memory usage section.  They are generally used to track Abends, Hangs, Out of Memory, GPF Crash, and Trace Assert type conditions.
Heapdumps (Portable Heap Dump) files are useful to determine Heap Occupancy and help identify Primary Leak Suspects and Classes or Types of objects responsible for the highest consumption of heap.  They are generally used to investigate Java OutofMemory conditions and unexpected Java Memory growth.
VerboseGC nativestderr.log output is useful to determine Mean or Average Heap usage, verify Garbage Collection Pause Times, track Large Object Allocation Requests and confirm if Excessive GC may be occurring, as well as help identify any noteworthy GC patterns or anomalies and spikes in activity.
Snap.Java Traces trc files are essentially in-flight recorders for Event sequences and also contain GC Allocation information, so a good substitute if you do not have VerboseGC currently enabled.
System Coredumps dmp files contain both Java and Native Memory references and Heapdumps can also be extracted from them.  They can be used to help track Abends, Hangs, Java + Native OutofMemory, GPF Crash, Trace Asserts conditions.  They are very large dumps and generally not our first recommendation to monitor heap usage, also needing to be Jextracted to include Local Native libraries for our Tooling to format their binary contents.

 

Useful Methods to generate the above referenced Dumps and Files for Monitoring the Java Heap.

 

1.) Generate a Javacore manually from the Command line or a DOS box.

 

a. Execute a kill -3 or kill -quit command on Unix generates Javacore or Threaddump, which contains the following Java Heap information including Initial Heap, Maximum Heap, Total Heap, Heap in use, and Heap Free:

 

-Xms

-Xmx

Total memory:

Total memory in use:

Total memory free:

 

***

You can also use our Dump Agent as a Generic JVM Arg to specify which dumps to generate on the kill -3 command:

e. g.'s

-Xdump:java:events=user (javacore only)

or

-Xdump:heap+java:events=user (heapdump and javacore)

-->> system+snap parameters can also be used if needed to specify additional System Coredump an Java Snap Traces, system dumps are generally speaking very large requiring proper ulimit setup (ulimit -c -f unlimited for hard and soft values) on Unix or enough file system space on windows and also need to be Jextracted to include required local libraries necessary for out Tooling to process these binary files.

***

 

b.  CTRL+BREAK can be used on Windows to generate Javacore dumps, but the user needs to create a special startup script first for the JVM.

1. Open the command prompt.
2. Navigate to "bin" subdirectory under the server's profile root (<WAS_HOME>\profiles\<PROFILE_NAME>\bin)
3. From the "bin" subdirectory, execute the one of the following commands. Choose the command from the list below based on the type of server that the javacore will be generated from.

Application Servers
startServer.bat SERVER_NAME -script

Nodeagents
startNode.bat -script

Deployment Managers (DMGR)
startManager.bat -script

This will generate a script named start_<SERVER_NAME>.bat in the current directory that can be used to start the JVM activating the CTRL+BREAK key combination to generate Javacores.

 

c. Invoke WSAdmin user interface from a Command prompt or DOS box against the SOAP port for AppServer or DMgr to generate a Javacore or Threaddump.

 

<WAS_HOME>\profiles\<PROFILE_NAME>\bin\wsadmin.bat/sh>

 

JACL



set jvm [$AdminControl completeObjectName type=JVM,process=SERVER_NAME,*]
$AdminControl invoke $jvm dumpThreads



JYTHON



jvm = AdminControl.completeObjectName('type=JVM,process=SERVER_NAME,*')
AdminControl.invoke(jvm, 'dumpThreads')

___________________________________________________________________________________________________________________________________________________________________________________________________________________

 

2.) Generate Javacore and Heapdump manually from WebSphere Administrative or Integrated Solutions Console in Full Profile or using javadump command in Liberty Profile.

 

a. Example in Full Profile using GUI or WUI Console:

 

  • Within the Administrative Console, expand the Troubleshooting section and click Java dumps and cores.
  • Find the list of available JVM processes and select the JVM(s) of interest.
  • Once selected you can then click the button corresponding to the 'File Type' you would like to generate: Heap dump, Java core, or System dump.

 

b. Example in Liberty Profile using javadump command:

Assume <server_name> = server1

  • To get just a javacore/thread memory dump:
  • Server javadump server1
  • To get a javacore/thread dump and a heapdump:
  • server javadump server1 --include=heap
  • To get a javacore/thread dump and a system core dump:
  • server javadump server1 --include=system

 

*** Analyzing Viewing resulting Javacore or Heapdump output ***

Javacores are Plain Text or Ascii files so can be read with any Editor of your choice and do not require additional tooling or formatting.  You can also use Thread and Monitor Dump Analyzer if you prefer a GUI front end and this does have the advantage of processing multiple Javacores at one time, performing Threads and Monitor Locks comparisons and so forth, so it can be a very practical and useful tool.

TMDA - https://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=2245aa39-fa5c-4475-b891-14c205f7333c

Heapdumps are Binary Files and require one of the following tools to format them for analysis:

Memory Analyzer (MAT) or Heap Analyzer (HA)

MAT - https://www.eclipse.org/mat/

HA - https://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=4544bafe-c7a2-455f-9d43-eb866ea60091

Most of these tools can be downloaded as separate eclipse EXEs or java JARs or can also be used in conjunction with IBM Support Assistant tooling as Plugins, see 5.) below for more information regarding ISA download.

***

 

3.) Enable VerboseGC, which would be very little or no overhead associated, since the calculations were previously performed during the actual GC runtime.

  • a. Select Servers > Application servers > server1 > Java and Process Management > Process Definition > Java Virtual Machine.
  • b. Select Verbose garbage collection.
  • c. Click Apply and click Save at the top of this page.

* You can use GCMV or PMAT standalone or eclipse plugins to analyze view the resulting output.

IBM Monitoring and Diagnostic Tools - Garbage Collection and Memory Visualizer (GCMV

https://marketplace.eclipse.org/content/ibm-monitoring-and-diagnostic-tools-garbage-collection-and-memory-visualizer-gcmv

IBM Pattern Modeling and Analysis Tool for Java Garbage Collector

https://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=22d56091-3a7b-4497-b36e-634b51838e11

 

4.) Setup and use built-in PMI Request Metrics or more specifically Counters for monitoring java heap usage, just need to configure and setup.

 

Java Virtual MachineCounter Definitions:

https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/rprf_datacounter4.html

 

You can use the Java virtual machine (JVM) counters that the Performance Monitoring Infrastructure (PMI) and Tivoli® Performance Viewer (TPV) collect to monitor JVM performance.

The total, used, and free heap size counters are available without any additional configuration settings. The remaining counters are available only when a Java virtual machine profiler is enabled.

Enabling the Java virtual machine profiler data

https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tprf_jvmpidata.html

 

e. g.  Heap and Garbage Collection related counters...

 

FreeMemory

HeapSize

UsedMemory

GCcount

GCIntervalTime

GCTime

 

5.) Download and use IBM Support Assistant or Team Server, and use the Java HealthCenter and appropriate Plugins (Tools):

 

ISA IBM Support Assistant:

https://www-01.ibm.com/software/support/isa/

 

IBM Support - IBM Support Assistant Team Server

https://www-01.ibm.com/support/docview.wss?uid=ibm10718131

 

Problem Determination Tools for IBM Support Assistant Team Server 5

https://www-01.ibm.com/support/docview.wss?uid=swg27036217

 

Tools or Plugins Available for ISA:

Classloader Analyzer

FileNet Optical Storage and Retrieval (OSAR) Cable Tool

Garbage Collection and Memory Visualizer (GCMV)

Java Health Center

Heap Analyzer (HA)

Interactive Diagnostic Data Explorer (IDDE)

Memory Analyzer Tool (MAT)

Pattern Modeling and Analysis Tool for Java Garbage Collector (PMAT)

Portal Log Analyzer

Profile Port Checker

Processor Time Analysis Tool for Linux

Serviceability Tool for Sametime

Thread and Monitor Dump Analyzer for Java (TMDA)

Trace and Request Analyzer for WebSphere Application Server

WAIT Javacore Analyzer

Web Server Plug-in Analyzer for WebSphere Application Server

WebSphere Application Server Configuration Visualizer

WebSphere Cross Component Trace Logviewer

 

6.)  Using WSAdmin Command-Line Interface:

 

a.  Check pre-configured Initial and Maximum Heap size values if explicitly set.

e. g.

wsadmin Script to check the JVM heap size of a WebSphere Server:

# Usage: wsadmin -f getJvmHeap.py server

server = AdminConfig.getid('/Server:'+sys.argv[0]+'/')

jvm = AdminConfig.list('JavaVirtualMachine', server)

 

print 'initialHeapSize: ' + AdminConfig.showAttribute(jvm, 'initialHeapSize')

print 'maximumHeapSize: ' + AdminConfig.showAttribute(jvm, 'maximumHeapSize')

 

b.  Check current runtime Total, Free and Maximum Java Heap Memory values.

e. g.

Get current system data by running wasadmin.sh as follows.


- Declare Object Name
-- JVMName=AdminControl.completeObjectName('type=JVM,process=server1,*')


- Run operation, and confirm total memory size, and available memory size.
-- AdminControl.invoke(JVMName,"getTotalMemory()")
-- AdminControl.invoke(JVMName,"getFreeMemory()")
-- AdminControl.invoke(JVMName,"getMaxMemory()")

Class Runtime

https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#freeMemory()

  • freeMemory

      public long freeMemory()
    Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory.
    Returns:
    an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.
  • totalMemory

      public long totalMemory()
    Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.

    Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

    Returns:
    the total amount of memory currently available for current and future objects, measured in bytes.
  • maxMemory

      public long maxMemory()
    Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned.
    Returns:
    the maximum amount of memory that the virtual machine will attempt to use, measured in bytes
    Since:
    1.4

[{"Business Unit":{"code":"BU004","label":"Hybrid Cloud"},"Product":{"code":"","label":""},"Component":"","Platform":[{"code":"","label":""}],"Version":"","Edition":""}]

UID

ibm11081149