2015-04-23 110 views
5

我使用Ubuntu 14.04服务器(8核,16 GB RAM)来托管PHP网站,MySQL和Redis。 PHP web和MySQL的流量非常低(MySQL:每秒查询平均值:0.825)。 Redis每秒处理8011个命令。Ubuntu 14.04 nc 100%CPU使用率

今天我注意到,NC停留在top顶部:

8348 root  20 0 11224 764 624 R 100.0 0.0 2277:01 nc                                
8319 root  20 0 11224 760 624 R 100.0 0.0 2277:59 nc                               
8324 root  20 0 11224 764 624 R 100.0 0.0 2278:09 nc                               
8344 root  20 0 11224 760 624 R 100.0 0.0 2277:07 nc 

Stracing NC给出:

[email protected]:/home/user# strace -p 8348 
Process 8348 attached 
poll([{fd=3, events=POLLIN}, {fd=-1}], 2, 1000) = 1 ([{fd=3, revents=POLLERR}]) 
poll([{fd=3, events=POLLIN}, {fd=-1}], 2, 1000) = 1 ([{fd=3, revents=POLLERR}]) 
poll([{fd=3, events=POLLIN}, {fd=-1}], 2, 1000) = 1 ([{fd=3, revents=POLLERR}]) 
intentionally cutted N lines from output 

man poll快速查找给我的信息是poll waits for one of a set of file descriptors to become ready to perform I/O.

如何我是否会发现文件描述符发生了什么(是文件描述符问题?)并修复nc占用100%CPU的问题?

回答

6

最近我们有类似的问题。我们有一项cron工作,通过netcat,通过udp向石墨发送一些redis统计信息,上周我们将一个石墨主机放置一段时间后,我们注意到我们的redis机箱的CPU使用量猛增。这似乎是在netcat了一个错误:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=752931

我们运行的命令是这样的:

echo "{redis_metric}" | nc -w 1 -u ${graphite_host} 8125 

使用“退出”选项(-q),而不是在“超时”选项(-w),似乎解决了我们的问题:

echo "{redis_metric}" | nc -q 1 -u ${graphite_host} 8125 

希望帮助!

+0

谢谢我的用例是完全一样的。这完全回答了如何使用100%CPU修复NC。 – Aivaras