Troubleshooting system operation and maintenance problems-Java memory high analysis

1. Check memory usage

Use top to view the memory usage of the process, shift+m ​​to sort the memory usage in descending order, and shift+p to sort the CPU usage in descending order.
Insert image description here

2. Check the thread status of a process

ps p $pid -L -o pcpu,pmem,pid,tid,time,tname,cmd

3. Execute the jmap $pid command to observe memory usage.

Insert image description here

4. Execute the jstat -gcutil $pid 5s command to check the memory usage.

Insert image description here

The meaning of the result columns:
  S0 — Survivor space on Heap 0 Percentage of area used space
  S1 — Survivor space 1 on Heap Percentage of area used space
  E — Eden space on Heap Percentage of area used space
  O — Heap Old space Percentage of used space
  P — Perm space Percentage of used space
  YGC — Number of times Young GC occurs from application startup to sampling
  YGCT – Time spent by Young GC from application startup to sampling (unit seconds)
  FGC — The number of Full GC occurrences from application startup to sampling time
  FGCT — The time spent in Full GC from application startup to sampling time (in seconds)
  GCT — The total time spent on garbage collection (in seconds) from application startup to sampling time seconds)
  GCT is the time sum of YGCT and FGCT.

5. Execute the jmap –heap $pid command to view the settings of each memory area.

6. Execute the jmap -histo:live $pid command to view the number of instances of each class, memory usage and full class name. Executed once every minute, 5 times continuously

Insert image description here

7. Get the dump file

jmap -dump:live format=b,file=./dump.bin $pid

8. View process stack information

jstack -l $pid> /usr/local/temp/jstack.log

Insert image description here

JSTACK command print parsing
 Log format
 "Keep-Alive-Timer" represents the name of the thread. In actual development, it is necessary to choose a name that is related to the business and is familiar to the user to facilitate troubleshooting.
 "prio=8" indicates the priority of the thread.
 "os_prio=0" indicates operating system level priority.
 "tid=0x000055868e1e9000" represents the thread id.
 "nid=0x394f" indicates the thread id mapped by the operating system.
 "0x00007fabd4f44000" represents the starting address of the thread stack.
Detailed analysis

Waiting to lock <0x00000000d6349040>, that is, trying to obtain a lock on the object at address 0x00000000d6349040; but the object is locked by the thread (locked <0x00000000d6349040>).

waiting on condition [0x00007fabd5b4e000]: Indicates that it is waiting for a certain condition to trigger.
waiting for monitor entry [0x000000001bbcf000]: indicates that the thread is waiting to acquire the lock.

Among them: java.lang.Thread.State: WAITING (parking): Waiting for the condition to occur;
java.lang.Thread.State: TIMED_WAITING (parking or sleeping): Timing, if the condition does not come, it will wake itself up regularly.
MEM.

Note: jmap and jstack need to be executed using the same user as the process.

Guess you like

Origin blog.csdn.net/weixin_40012925/article/details/132164430