Record an OOM analysis process

Source: Internet
Author: User

Tools:

    • Jstat
    • Jmap
    • Jhat

1.jstat Viewing GC Status

s0c, s1c, s0u, S1u:survivor 0/1-zone capacity (capacity) and usage (used) EC, Eu:eden area capacity and usage oc, OU: Old generation capacity and Usage pc, PU: Permanent generation capacity and usage ygc, YGT: Young generation GC times and GC time-consuming FGC, fgct:full GC times, and full GC time-consuming GCT:GC total time-consuming

  

The situation is that the oldarea to the specified recovery threshold trigger FGC, but the old area can not be recycled, continuous growth (but has been frequent FGC).

The JVM is configured as follows:

-SERVER-XX:PERMSIZE=64M-XX:MAXPERMSIZE=128M-XMN500M-XMS3000M-XMX3000M-XX:+USECONCMARKSWEEPGC-XX: CMSINITIATINGOCCUPANCYFRACTION=60-XX:+HEAPDUMPONOUTOFMEMORYERROR-XX:HEAPDUMPPATH=/HOME/APPS/OOM/GC.HPROF-XX: Errorfile=/var/log/java_error_%p.log

2. Use Jmap to analyze memory when you find that the old area is not recycled.

Jmap-heap PID

Use the Jmap-heap PID to view the process heap memory usage, including the GC algorithm used, heap configuration parameters, and heap memory usage in each generation.

For example:

Attaching to process ID 10253, please wait ... Debugger attached successfully. Server compiler detected. JVM version is 24.65-b04using parallel threads in the new Generation.using thread-local object allocation. Concurrent mark-sweep gcheap configuration:minheapfreeratio = + Maxheapfreeratio = Maxheapsize = 314572800 0 (3000.0MB) NewSize = 524288000 (500.0MB) maxnewsize = 524288000 (500.0MB) oldsize = 543948 8 (5.1875MB) Newratio = 2 Survivorratio = 8 PermSize = 67108864 (64.0MB) MaxPermSize = 134  217728 (128.0MB) g1heapregionsize = 0 (0.0MB) Heap usage:new Generation (Eden + 1 Survivor Space): capacity = 471859200 (450.0MB) used = 113244456 (107.99832916259766MB) free = 358614744 (342.00167083740234MB) 23.99962870279948 % Usededen space:capacity = 419430400 (400.0MB) used = 66465208 (63.38616180419922MB) free = 352965192 (336 .6138381958008MB) 15.846540451049805% Usedfrom space:capacity = 52428800 (50.0MB) used = 46779248 (44.61216735839844MB) free = 5649552 (5.3878326416015625MB) 89.224 33471679688% usedto space:capacity = 52428800 (50.0MB) used = 0 (0.0MB) free = 52428800 (50.0MB) 0.0% use      Dconcurrent mark-sweep generation:capacity = 2621440000 (2500.0MB) used = 259229192 (247.22022247314453MB) free     = 2362210808 (2252.7797775268555MB) 9.888808898925781% usedperm generation:capacity = 67108864 (64.0MB) used = 37059440 (35.34263610839844MB) free = 30049424 (28.657363891601562MB) 55.22286891937256% used19254 interned S Trings occupying 2351584 bytes.

Jmap-heap can only view detailed usage of each area of the JVM, and what data is in memory (biting the old area) is analyzed with Jmap-histo.

Jmap-histo[:live] PID

For example:

Num #instances #bytes class name----------------------------------------------1:32,727 88492 856 [I 2:369677 62058808 [C 3:145200 54408968 [B 4:545638 17460416 JAV A.util.hashmap$entry 5:451316 14442112 org.wltea.analyzer.dic.DictSegment 6:158,024 100514   [Ljava.lang.Object;          7:59193 8940656 <constMethodKlass> 8:59193 7588736 <methodKlass> 9:  6105 7139824 <constantPoolKlass> 10:39329 6230272 [Ljava.util.hashmap$entry; 11:255466 6131184 java.lang.String 12:182746 5847872 [Lorg.wltea.analyzer.dic.DictSegment  ; 13:6097 4220448 <instanceKlassKlass> 14:5064 3900032 <constantpoolcacheklass > 15:100084 3202688 org.apache.lucene.document.lazydocument$lazyfield 16:78,719 314876 0 Java.util.linkedhashmap$entry 17:11980 3120656 [S 18:122352 2936448 Java.util.ArrayLis        T 19:9747 2740192 [J 20:95649 2295576 Java.util.linkedlist$node 21:53,484 2139360 org.apache.lucene.document.FieldType 22:125687 2010992 java.lang.Character 23:410  1969008 Org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl 24:53,663 1913576 [Lorg.apache.lucene.util.automaton.Transition;

Class name is the object type, as described below:

B  Bytec  chard  doublef  floati  intj  longz  boolean[  array, such as [i = int[][l+ class name other objects

If you need to see more detailed information, use:

Jmap-dump:format=b,file=dumpfilename PID

Dump files can be viewed with tools such as mat, VISUALVM, or Jhat.

Jhat-port 9999 Dumpfilename

If the dump file is too large, you may need to specify XMX (Jhat actually launches a web app).

Jhat-j-xmx1000m-port 9999 Dumpfilename

After successful startup, you can view it through the browser:

Ip:port

For example:

There are some query tools on the last side of the page, for example: OQL (object Query Language)

For example, an int array with a length greater than 256 is queried.

------------------------------------

Enterprise development, there are likely to encounter problems:

    • Oom
    • Memory leaks
    • Thread deadlock
    • Lock contention
    • The Java process consumes too much CPU

Tools:

    • JPS (Java Virtual Machine process Status tool)

The JPS is primarily used to output process state information that runs in the JVM. The syntax format is as follows:

JPS [Options] [HostID]

Q does not output the class name, the jar name, and the parameter of the incoming main method-m output passed the parameter of the main method-L output the full-name-V output of the main class or jar to the parameters of the JVM

    • Jstack

Jstack is primarily used to view thread stack information within a Java process.

Inspection process:

1) Get the corresponding process number (PS-EF |grep * * *)

2) Query the thread information for this process (TOP-HP pid)

The PID here needs to be converted into 16, which needs to be used later.

[[email protected] bin]$ printf "%x\n" 108312a4f

Using Jstack for analysis

[[email protected] bin]$ Jstack 10253 | grep 2a4f "http-bio-2223-exec-172" daemon prio=10 tid=0x00007fb2d400a000 nid=0x2a4f waiting on condition [ 0X00007FB28C5C4000]

You can also dump the information into the file for analysis, which is more convenient.

  

    • Jmap (Memory map)/Jhat (Java Heap Analysis tool)

Jmap is used to view heap memory usage, typically combined with jhat.

Jmap-heap pidjmap-histo[:live] Pidjmap-dump:format=b,file=dumpfilename pid

  

    • Jstat

Heap memory = young generation + old generation + permanent generation young generation = Eden Zone + two survivor zones (from and to)

  

    • Hprof (heap/cpu profiling tool)

Hprof can show CPU usage and count heap memory usage.

Resources:

http://my.oschina.net/feichexia/blog/196575

Record an OOM analysis process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.