【问题标题】:NodeJS 100% cpu usage - epoll_waitNodeJS 100% cpu 使用率 - epoll_wait
【发布时间】:2014-11-17 14:07:12
【问题描述】:

我试图找出为什么我的 nodejs 应用程序突然使用 100% cpu。该应用有大约 50 个并发连接,并在 ec2 微型实例上运行。

下面是strace -c node server.js的输出

^C% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 87.32    0.924373           8    111657           epoll_wait
  6.85    0.072558           3     22762           pread
  2.55    0.026965           0    146179           write
  0.92    0.009733           0    108434         1 futex
  0.44    0.004661           0     82010         7 read
  0.44    0.004608           0    223317           clock_gettime
  0.31    0.003244           0    172467           gettimeofday
  0.31    0.003241          35        93           brk
  0.20    0.002075           0     75233         3 epoll_ctl
  0.19    0.002052           0     23850     11925 accept4
  0.19    0.001997           0     12302           close
  0.19    0.001973           7       295           mmap
  0.06    0.000617           4       143           munmap

这是node-tick-processor的输出

 [Top down (heavy) profile]:
  Note: callees occupying less than 0.1% are not shown.

  inclusive      self           name
  ticks   total  ticks   total
  669160   97.4%  669160   97.4%  /lib/x86_64-linux-gnu/libc-2.15.so

   4834    0.7%     28    0.0%  LazyCompile: *Readable.push _stream_readable.js:116
   4750    0.7%     10    0.0%    LazyCompile: *emitReadable _stream_readable.js:392
   4737    0.7%     19    0.0%      LazyCompile: *emitReadable_ _stream_readable.js:407
   1751    0.3%      7    0.0%        LazyCompile: ~EventEmitter.emit events.js:53
   1081    0.2%      2    0.0%          LazyCompile: ~<anonymous> _stream_readable.js:741
   1045    0.2%      1    0.0%            LazyCompile: ~EventEmitter.emit events.js:53
    960    0.1%      1    0.0%        LazyCompile: *<anonymous> /home/ubuntu/node/node_modules/redis/index.js:101
    948    0.1%     11    0.0%          LazyCompile: RedisClient.on_data /home/ubuntu/node/node_modules/redis/index.js:541

这是我第一次调试节点应用程序。从上面的调试输出中可以得出任何结论吗?错误可能在哪里?

编辑

我的节点版本:v0.10.25

编辑 2

更新节点后为:v0.10.33

这是输出

^C% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 91.81    1.894522           8    225505        45 epoll_wait
  3.58    0.073830           1     51193           pread
  1.59    0.032874           0    235054         2 write
  0.98    0.020144           0   1101789           clock_gettime
  0.71    0.014658           0    192494         1 futex
  0.57    0.011764           0    166704        21 read

【问题讨论】:

    标签: node.js


    【解决方案1】:

    似乎 Node JS v0.10.25 有事件循环错误,请看here

    注意,来自thisgithub 拉取请求:

    如果相同的文件描述在两个不同的进程中打开,那么 关闭文件描述符不足以从 epoll 实例(如 epoll(7) 中所述),导致虚假 导致事件循环重复旋转的事件。所以总是 明确注销它。

    因此,作为解决方案,您可以尝试更新您的操作系统或更新 Node JS。

    【讨论】:

    • 我已经更新了我的服务器,并将在此期间试一试。当我知道更多时,我会在这里发布状态。
    • 谢谢,这个bug,真的很有趣也很奇怪
    • 其中一个实例再次开始发疯并达到 100 cpu。我已经开始了另一个strace -c node server.js,一旦再次达到 100,我就会返回结果。
    • 我不确定这是否与我使用 mysql 和 redis 有关,连接在所有套接字之间共享。
    • 是的,您的代码似乎有问题,请参阅kennynet.co.uk/2014/07/07/nodejs-and-blocked-io
    猜你喜欢
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多