CPU 100% 问题排查流程
- 排查CPU占用率高的进程,使用
top
命令查看
[a@b bin]$ top
top - 11:39:57 up 382 days, 10:08, 2 users, load average: 6.05, 6.08, 6.08
Tasks: 240 total, 1 running, 239 sleeping, 0 stopped, 0 zombie
Cpu(s): 76.6%us, 0.4%sy, 0.0%ni, 22.9%id, 0.0%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 16333660k total, 16140076k used, 193584k free, 42456k buffers
Swap: 8388604k total, 660720k used, 7727884k free, 4612148k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3195 a 20 0 6230m 543m 7848 S 600.4 3.4 56111:03 java
5993 a 20 0 6319m 1.0g 7812 S 3.7 6.4 450:23.24 java
- 查看所有java进程
jps
工具jps -l
[a@abin]$ ./jps -l
3195 test.jar
20423 sun.tools.jps.Jps
可直接grep出来
- 查询当前进程下线程CPU占用
top -H -p pid
[a@a bin]$ top -H -p 3195
top - 11:46:21 up 382 days, 10:15, 2 users, load average: 6.15, 6.10, 6.09
Tasks: 107 total, 6 running, 101 sleeping, 0 stopped, 0 zombie
Cpu(s): 76.7%us, 0.8%sy, 0.0%ni, 22.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 16333660k total, 16125280k used, 208380k free, 42376k buffers
Swap: 8388604k total, 662352k used, 7726252k free, 4600612k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27347 a 20 0 6230m 543m 7860 R 100.0 3.4 9347:13 java
27152 a 20 0 6230m 543m 7860 R 100.0 3.4 9333:35 java
拿到 CPU占用异常的线程id
- 转16进制查看
printf "%x\n" 27347
得6ad3 - 通过
jstack
定位线程信息jstack pid|grep tid
[mplat@mplatformprd23 bin]$ ./jstack 3195|grep 6ad3 -C 10 --color
"pool-6-thread-10" #103 prio=5 os_prio=0 tid=0x00007ffc0c00f800 nid=0x6ad3 runnable [0x00007ffcfc490000]
java.lang.Thread.State: RUNNABLE
at java.io.DataInputStream.read(DataInputStream.java:149)
at com.xxx.SocketHandle.readByLength(SocketHandle.java:236)
at com.xxx.SocketHandle.run(SocketHandle.java:105)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)