今天发现我的服务器cpu负载太高,服务器只是运行一个Java应用。
下面是我的操作步骤。
我使用
top
命令来查找应用程序的 pid。PID 为 25713。我使用
top -H -p 25713
命令找到了一些使用最多 cpu 的 pid。比如25719 tomcat 20 0 10.6g 1.5g 13m R 97.8 4.7 314:35.22 java
。我使用
jstack -F 25713
命令打印转储信息。例如"Gang worker#4 (Parallel GC Threads)" os_prio=0 tid=0x00007f5f10021800 nid=0x6477 runnable
我从转储文件中搜索了 pid。然后我发现使用cpu最多的pids都像
"Gang worker#4 (Parallel GC Threads)" os_prio=0 tid=0x00007f5f10021800 nid=0x6477 runnable
我使用
jstack
命令后,cpu就正常了!
以下是我的问题:
- 为什么
GC Threads
cpu负载太高。 - 为什么我使用
jstack
命令后cpu变得正常。
不止这一次,每一次。
这是一些正常的日志。2015-10-10T10:17:52.019+0800: 71128.973: [GC (Allocation Failure) 2015-10-10T10:17:52.019+0800: 71128.973: [ParNew: 309991K->206K(348416K), 0.0051145 secs] 616178K->306393K(1009920K), 0.0052406 secs] [Times: user=0.09 sys=0.00, real=0.01 secs]
当 CPU 过高时,GC 日志停留在 中[GC (Allocation Failure) 2015-10-10T10:18:10.564+0800: 71147.518: [ParNew:
,没有其他日志。
当我执行jstack
命令时,打印日志
2015-10-10T10:17:50.757+0800: 53501.137: [GC (Allocation Failure) 2015-10-10T10:17:50.757+0800: 53501.137: [ParNew: 210022K->245K(235968K), 369.6907808 secs] 400188K->1
90410K(1022400K), 369.6909604 secs] [Times: user=3475.15 sys=11.69, real=369.63 secs]