Java performance testing tool - a record high troubleshoot Linux server CPU utilization practices by jstack
https://www.jianshu.com/p/d4e31301ba2e
I. Description of the problem
Configuring a Linux server is 4-core 16G, the war package is deployed to tomcat, start tomcat, found that memory usage is not high, but the CPU has been up to 100%; browser, enter the relevant url can not access the project, and the tomcat process has been there is, what configuration program no problem ah, confused ...... view the performance status of the server by top command is as follows:
[root@aws-java-MAM ec2-user]# top
top - 18:49:21 up 45 min, 2 users, load average: 0.97, 0.50, 0.19 Tasks: 129 total, 1 running, 128 sleeping, 0 stopped, 0 zombie Cpu0 : 95.1%us, 0.0%sy, 0.0%ni, 4.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu1 : 5.9%us, 0.0%sy, 0.0%ni, 94.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu2 : 1.6%us, 0.5%sy, 0.0%ni, 97.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu3 : 1.1%us, 0.0%sy, 0.0%ni, 98.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 16330912k total, 2374776k used, 13956136k free, 20172k buffers Swap: 0k total, 0k used, 0k free, 370244k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2141 root 20 0 7684m 1.7g 22m S 103.0 11.0 3:35.95 java 1423 root 20 0 449m 23m 2884 S 0.0 0.1 0:01.05 salt-minion 1959 root 20 0 98280 3860 2920 S 0.0 0.0 0:00.00 sshd 2278 root 20 0 98280 3836 2900 S 0.0 0.0 0:00.00 sshd 1387 postfix 20 0 81536 3436 2544 S 0.0 0.0 0:00.00 qmgr 1379 root 20 0 81284 3424 2520 S 0.0 0.0 0:00.01 master 1386 postfix 20 0 81364 3380 2508 S 0.0 0.0 0:00.00 pickup 1303 ntp 20 0 30720 2124 1508 S 0.0 0.0 0:00.00 ntpd 1986 root 20 0 105m 2000 1544 S 0.0 0.0 0:00.03 bash 1413 zabbix 20 0 42448 1972 1300 S 0.0 0.0 0:00.13 zabbix_agentd
PID can be seen as a java process 2141 11% of the cost of memory, is not high, but the CPU reaches 103%, where there should be an infinite loop or thread is blocked to live, resulting in high CPU utilization (in various configurations personally feel should be is no problem), how to locate specific thread or program position it? Thought jstack tool.
Two, jstack Profile
jstack is java virtual machine comes with a stack trace tool. Java stack information for printing a given java process ID or core file or remote debugging services, use the command tool can be jstack thread stack information, according to the thread stack information, we can go to check for problems arise Java programs, such as detection deadlocks, and troubleshooting information output deadlock.
Third, the way the investigation
1, the first list of threads displayed by the following command
ps -mp pid -o THREAD,tid,time
[root@aws-java-MAM ec2-user]# ps -mp 2141 -o THREAD,tid,time |sort -rn USER %CPU PRI SCNT WCHAN USER SYSTEM TID TIME root 94.3 - - - - - - 00:04:04 root 85.9 19 - - - - 2185 00:03:21 root 3.7 19 - futex_ - - 2153 00:00:09 root 3.6 19 - futex_ - - 2152 00:00:09 root 2.8 19 - futex_ - - 2162 00:00:07 root 1.3 19 - futex_ - - 2154 00:00:03 root 0.9 19 - futex_ - - 2176 00:00:02 root 0.7 19 - futex_ - - 2147 00:00:02 root 0.7 19 - futex_ - - 2146 00:00:02 root 0.7 19 - futex_ - - 2145 00:00:02 root 0.7 19 - futex_ - - 2144 00:00:02 root 0.2 19 - futex_ - - 2148 00:00:00 root 0.2 19 - futex_ - - 2143 00:00:00 root 0.1 19 - inet_s - - 2209 00:00:00 root 0.0 19 - poll_s - - 2181 00:00:00 root 0.0 19 - poll_s - - 2179 00:00:00 root 0.0 19 - futex_ - - 2188 00:00:00 root 0.0 19 - futex_ - - 2183 00:00:00 root 0.0 19 - futex_ - - 2182 00:00:00 root 0.0 19 - futex_ - - 2180 00:00:00 root 0.0 19