一些使用100%CPU的进程在select()调用中挂起一段时间

所以我有这种奇怪的情况:有一个服务器这个Apache /乘客/ Rails和其他服务。 例如top命令本身需要100%的CPU时间(也是iostat和ruby,其他进程看起来很正常)。 起初我虽然这是着名的futex bug Linux futex_wait()错误 (因为处理器是至强E5),但这是与3.2.13-grsec-xxxx-grs-ipv6-64内核的Centos 6.5,这似乎并没有受到影响由futex错误。 这里是top命令的输出:

top - 18:14:46 up 60 days, 6:32, 2 users, load average: 2.15, 1.24, 1.04 Tasks: 180 total, 1 running, 179 sleeping, 0 stopped, 0 zombie Cpu(s): 1.6%us, 1.0%sy, 0.0%ni, 95.0%id, 1.7%wa, 0.0%hi, 0.7%si, 0.0%st Mem: 66008460k total, 21226356k used, 44782104k free, 817252k buffers Swap: 61437944k total, 0k used, 61437944k free, 17404540k cached Change delay from 3.0 to: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 18042 root 20 0 15076 1272 904 S 100.0 0.0 5109402h top 18041 root 20 0 105m 1192 1028 S 100.0 0.0 900776:13 sh 18043 root 20 0 98.6m 808 692 S 100.0 0.0 900776:13 iostat 1 root 20 0 19276 1508 1228 S 0.0 0.0 0:02.40 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 5119411h ksoftirqd/0 5 root 20 0 0 0 0 S 0.0 0.0 10218485h kworker/u:0 6 root RT 0 0 0 0 S 0.0 0.0 986912:21 migration/0 7 root RT 0 0 0 0 S 0.0 0.0 906076:59 migration/1 9 root 20 0 0 0 0 S 0.0 0.0 45038,51 ksoftirqd/1 11 root RT 0 0 0 0 S 0.0 0.0 911444:25 migration/2 13 root 20 0 0 0 0 S 0.0 0.0 120103,33 ksoftirqd/2 14 root RT 0 0 0 0 S 0.0 0.0 941393:43 migration/3 

strace显示这些过程挂在select()系统调用上

 # strace -p 1938 Process 1938 attached - interrupt to quit select(12, [0 11], NULL, NULL, NULL^C <unfinished ...> Process 1938 detached 

这可能是什么原因?

我今天也遇到类似的情况。 我的朋友是gdbrb_backtrace()rake debug 。 而就我而言,在极less数情况下,这是一个无限的循环。

只需rb_backtrace()打印回溯。 在我的情况下,它被打印出来的Apache的错误日志( /var/log/apache2/error.log )。

这种回溯与往常相反。 查看最后一行,并查找涉及您的应用程序代码的行。 然后,使用rubydebugging器在该行之前进行debugging。

这篇文章https://robots.thoughtbot.com/using-gdb-to-inspect-a-running-ruby-process很有帮助&#x3002;