2014-11-17 5 views
5

내 nodejs 앱이 갑자기 100 % cpu를 사용하는 이유를 추적하려고합니다. 응용 프로그램은 약 50 개의 동시 연결을 가지고 있으며 ec2 마이크로 인스턴스에서 실행 중입니다.NodeJS 100 % cpu 사용법 - epoll_wait

는 아래의 출력 : 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 
에게 있습니다

답변

2

노드 JS와 비슷합니다 v0.10.25 이벤트 루프 버그, here보세요.

참고 this GitHub의 풀 요청에서 : 바와 같이

동일한 파일 설명 (파일 디스크립터를 닫는 에서 epoll 파일 인스턴스를 등록 해제하기에 충분하지 않다이어서, 두 개의 다른 공정에서 열려 있다면 epoll (7)에서), 결과적으로 이벤트 루프가 반복적으로 회전하도록하는 가짜 이벤트가 발생합니다. 따라서 항상 은 명시 적으로 등록을 취소합니다.

솔루션으로 OS 업데이트 또는 노드 JS 업데이트를 시도 할 수 있습니다.

+0

나는 내 서버를 업데이트했으며 그 날짜 동안 사용해 보았습니다. 나중에 알게되면 여기에 상태를 게시 할 것입니다. – Alosyius

+0

감사합니다,이 버그, 정말 재미 있고 이상한 것 – Maksym

+0

인스턴스 중 하나가 다시 미쳐 가서 100 cpu를 누르기 시작했습니다. 다른 'strace -c node server.js'를 다시 시작했는데 다시 100에 도달하면 바로 결과가 표시됩니다. – Alosyius