Friday, March 3, 2017

Heap Memory Usage details for a Java Process

          Heap Memory Usage details for a Java Process
                
Heap dump is a snapshot of the memory of a Java process. The snapshot contains information about the Java objects and classes in the heap at the moment the snapshot is triggered. Some time there are times we need to figure out what is using all of heap of a Java process, this is when heap dump comes handy .

METHOD I :

1) First lets check the PID of all the jvm's running on the node and for purpose of this blog I am taking heap dump of CLDB pid.

[mapr@node9 root]$ jps -v
11956 CLDB -Xms571m -Xmx953m -XX:ErrorFile=/opt/cores/hs_err_pid%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/cores -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:CMSInitiatingOccupancyFraction=60 -XX:+UseCMSInitiatingOccupancyOnly -XX:ThreadStackSize=256 -Dlog4j.configuration=file:/opt/mapr/conf/log4j.cldb.properties -Dlog.file=/opt/mapr/logs/cldb.log -Dcldb.conf.file=/opt/mapr/conf/cldb.conf -Dcldb.audit.file=/opt/mapr/logs/cldbaudit.log.json -Dcldb.role.balancer.log.file=/opt/mapr/logs/cldbrolebalancer.log -Dcldb.disk.balancer.log.file=/opt/mapr/logs/cldbdiskbalancer.log -Dcldb.time.skew.log.file=/opt/mapr/logs/timeskew.log -Dcldb.fs.summary.log.file=/opt/mapr/logs/cldbfssummary.log -Dhadoop.login=maprsasl -Dhttps.protocols=TLSv1.2 -Djava.security.auth.login.config=/opt/mapr/conf/mapr.login.conf -Dzookeeper.sasl.clientconfig=Client_simple -Dzookeeper.saslprovider=com.mapr.security.simplesasl.SimpleSaslProvider -Djava.library.path=/opt/mapr/lib -Drpc.drop=false -Dhs.rpcon=true -Dmapr.library.flatclass -Dc

10856 WardenMain -XX:ErrorFile=/opt/cores/hs_err_pid%p.log -XX:-HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/cores -XX:+UseConcMarkSweepGC -Dlog.file=/opt/mapr/logs/warden.log -Djava.library.path=/opt/mapr/lib -Dhadoop.login=maprsasl -Dhttps.protocols=TLSv1.2 -Djava.security.auth.login.config=/opt/mapr/conf/mapr.login.conf -Dzookeeper.sasl.clientconfig=Client_simple -Dzookeeper.saslprovider=com.mapr.security.simplesasl.SimpleSaslProvider -Dmapr.library.flatclass -Dcom.sun.management.jmxremote -Dmapr.usemaprserverticket=true -Dpid=9696 -Dpname=warden -Dmapr.home.dir=/opt/mapr

419 Jps -Dapplication.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64 -Xms8m

2) Now using jmap command i will dump heap dump of CLDB process.

[mapr@node9 tmp]$ jmap -dump:file=CLDB.heapdump.hprof,format=b 11956
Dumping heap to /tmp/CLDB.heapdump.hprof ...
Heap dump file created

[mapr@node9 tmp]$ du -sh /tmp/CLDB.heapdump.hprof
313M /tmp/CLDB.heapdump.hprof

3) Now using Visual VM we can view all Java objects and classes in the heap when heap dump was taken.



METHOD I I :

Alternatively we can run below steps to get similar details.

i) Find CLDB pid .

[mapr@node107rhel72 root]$ jps -v | grep cldb
5080 CLDB -Xms2400m -Xmx4000m -XX:ErrorFile=/opt/cores/hs_err_pid%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/cores -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:CMSInitiatingOccupancyFraction=60 -XX:+UseCMSInitiatingOccupancyOnly -XX:ThreadStackSize=256 -Dlog4j.configuration=file:/opt/mapr/conf/log4j.cldb.properties -Dlog.file=/opt/mapr/logs/cldb.log -Dcldb.conf.file=/opt/mapr/conf/cldb.conf -Dcldb.audit.file=/opt/mapr/logs/cldbaudit.log.json -Dcldb.role.balancer.log.file=/opt/mapr/logs/cldbrolebalancer.log -Dcldb.disk.balancer.log.file=/opt/mapr/logs/cldbdiskbalancer.log -Dcldb.time.skew.log.file=/opt/mapr/logs/timeskew.log -Dcldb.fs.summary.log.file=/opt/mapr/logs/cldbfssummary.log -Dhadoop.login=maprsasl -Dhttps.protocols=TLSv1.2 -Djava.security.auth.login.config=/opt/mapr/conf/mapr.login.conf -Dzookeeper.sasl.clientconfig=Client_simple -Dzookeeper.saslprovider=com.mapr.security.simplesasl.SimpleSaslProvider -Djava.library.path=/opt/mapr/lib -Drpc.drop=false -Dhs.rpcon=true -Dmapr.library.flatclass -


ii) Running below command against CLDB PID will print a histogram of the heap for CLDB JVM. For each Java class, the number of objects/instance, memory size in bytes, and the fully qualified class names are printed as seen below .

[mapr@node107rhel72 root]$ jmap -histo:live 5080 >> /tmp/abi
[mapr@node107rhel72 root]$ less /tmp/abi 


 num     #instances         #bytes  class name
----------------------------------------------
   1:         23347        1722240  [C
   2:         22704         544896  java.lang.String
   3:          4417         508024  java.lang.Class
   4:          1239         507928  [B
   5:          3095         217376  [Ljava.lang.Object;
   6:          5806         185792  java.util.concurrent.ConcurrentHashMap$Node
   7:          4443         142176  java.util.HashMap$Node
   8:          3207         102624  java.util.Hashtable$Entry
   9:          2192          97256  [I
  10:          4837          77392  java.lang.Object
  11:           594          75744  [Ljava.util.HashMap$Node;
  12:          1137          45480  java.util.LinkedHashMap$Entry
  13:            75          44776  [Ljava.util.concurrent.ConcurrentHashMap$Node;
  14:           497          43736  java.lang.reflect.Method

  15:          1129          41576  [Ljava.lang.String;
  16:           720          34560  java.util.HashMap
  17:           100          29704  [Ljava.util.Hashtable$Entry;
  18:           673          26920  java.lang.ref.SoftReference
  19:            60          22560  java.lang.Thread
  20:           280          17920  java.net.URL
  21:           480          15360  java.lang.ref.WeakReference
  22:           161          13584  [Ljava.util.WeakHashMap$Entry;
  23:           305          12200  java.lang.ref.Finalizer
  24:           304          12160  com.google.common.collect.MapMakerInternalMap$WeakEntry
  25:           499          11768  [Ljava.lang.Class;
  26:           482          11568  java.util.ArrayList
  27:           205          11480  java.lang.invoke.MemberName
  28:           196          10976  java.security.Provider$Service
  29:           341          10912  sun.misc.FDBigInteger
  30:           134          10720  java.lang.reflect.Constructor
  31:           107          10272  java.util.jar.JarFile$JarFileEntry
  32:           410           9840  java.security.Provider$ServiceKey
  33:           305           9760  com.sun.org.apache.xerces.internal.xni.QName
  34:           398           9552  java.util.LinkedList$Node
  35:           145           9280  org.mortbay.io.BufferCache$CachedBuffer
  36:           562           8992  java.lang.Integer
---- 
----
1955:             1             16  sun.text.normalizer.NormalizerBase$NFKDMode
1956:             1             16  sun.util.calendar.Gregorian
1957:             1             16  sun.util.locale.provider.AuxLocaleProviderAdapter$NullProvider
1958:             1             16  sun.util.locale.provider.CalendarDataUtility$CalendarWeekParameterGetter
1959:             1             16  sun.util.locale.provider.SPILocaleProviderAdapter
1960:             1             16  sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter
1961:             1             16  sun.util.resources.LocaleData
1962:             1             16  sun.util.resources.LocaleData$LocaleDataResourceBundleControl
Total        102688        5308368

No comments:

Post a Comment