$ top -c
(按shft+p按照cpu占用进行排序,按shift+m按照内存占用进行排序)
此时发现9331的java进程CPU高达253.4%,且一直降不下来,很显然9331这个进程出现了问题。
top - 17:57:20 up 91 days, 20:37, 1 user, load average: 3.34, 3.14, 2.23
Tasks: 180 total, 1 running, 179 sleeping, 0 stopped, 0 zombie
Cpu(s): 46.1%us, 13.4%sy, 0.0%ni, 36.2%id, 0.1%wa, 0.0%hi, 2.5%si, 1.7%st
Mem: 8059860k total, 7888496k used, 171364k free, 22648k buffers
Swap: 10485752k total, 0k used, 10485752k free, 2750132k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7331 kafka 20 0 43.2g 4.3g 16m S 253.4 56.2 3942:19 /home/kafka/software/java/bin/java -Xms4G -Xmx4G -server -XX:+UseG1GC -XX:MaxGCPauseMi
因为java使用的是单进程多线程,所有需要通过进程PID(7331)找到CPU最高的线程
$ top -Hp 7331
很容易发现,多个线程的CPU占用达到了56%多。我们挑选线程号为7573的线程继续分析。
top - 18:01:28 up 91 days, 20:41, 1 user, load average: 1.90, 2.31, 2.08
Tasks: 90 total, 6 running, 84 sleeping, 0 stopped, 0 zombie
Cpu(s): 43.2%us, 14.6%sy, 0.0%ni, 38.4%id, 0.1%wa, 0.0%hi, 3.0%si, 0.8%st
Mem: 8059860k total, 7888236k used, 171624k free, 24888k buffers
Swap: 10485752k total, 0k used, 10485752k free, 2741760k cachedPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7535 kafka 20 0 43.6g 4.3g 11m R 21.0 56.2 318:04.55 java
7481 kafka 20 0 43.6g 4.3g 11m R 20.0 56.2 230:05.61 java
7534 kafka 20 0 43.6g 4.3g 11m S 18.6 56.2 297:30.55 java
7475 kafka 20 0 43.6g 4.3g 11m S 16.3 56.2 229:33.86 java
7477 kafka 20 0 43.6g 4.3g 11m S 15.6 56.2 229:55.57 java
7478 kafka 20 0 43.6g 4.3g 11m S 15.3 56.2 229:38.64 java
7482 kafka 20 0 43.6g 4.3g 11m R 15.0 56.2 230:00.66 java
printf “%x\n” 命令(tid指线程的id号)将以上10进制的线程号转换为16进制:
$ printf %x 7535
1d6f
因为 1d6f 为十六进制,所以加上0x在grep会跟准确,不然可能会被其他信息干扰。
$ jstack 7331 | grep "0x1d6f" -C30 --color
此处不再做介绍,因为没有案例截图,以后再补充。