2016-05-29 99 views
0

我正在使用永遠JS來連續運行我的節點JS服務器,但偶爾服務器崩潰並且網站停機一段時間。節點JS進程內存不足

我看着永遠的記錄,在這裏它顯示:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory 

<--- Last few GCs ---> 

35251732 ms: Mark-sweep 687.6 (219898.0) -> 687.6 (527360.0) MB, 13522.0/0 ms [allocation failure] [scavenge might not succeed]. 
35267178 ms: Mark-sweep 687.6 (527360.0) -> 687.6 (940128.0) MB, 15445.8/0 ms [allocation failure] [scavenge might not succeed]. 
35282842 ms: Mark-sweep 687.6 (940128.0) -> 687.6 (1352896.0) MB, 15664.3/0 ms [last resort gc]. 
35298326 ms: Mark-sweep 687.6 (1352896.0) -> 687.6 (1765664.0) MB, 15483.8/0 ms [last resort gc]. 


<--- JS stacktrace ---> 

==== JS stack trace ========================================= 

Security context: 0x82f80fa5a91 <JS Object> 
    2: decode(aka utf8decode) [/home/ubuntu/chat2/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/utf8/utf8.js:~200] [pc=0x19db242bd813] (this=0x1ea709fcc4c9 <an Object with map 0xedc29877b11>,byteString=0x1bd8952f0461 <Very long string[8570662]>) 
    3: decodePacket [/home/ubuntu/chat2/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-... 

error: Forever detected script was killed by signal: SIGABRT 
error: Script restart attempt #9 
Server running at http://localhost:1337/ 

這裏有一些錯誤,我在我的console.log文件中找到導致節點崩潰:

error: Forever detected script was killed by signal: SIGKILL 
error: Script restart attempt #11 


Error: read ECONNRESET 
    at exports._errnoException (util.js:870:11) 
    at TCP.onread (net.js:544:26) 

RangeNotSatisfiableError: Range Not Satisfiable 
    at SendStream.error (/home/ubuntu/chat2/node_modules/express/node_modules/connect/node_modules/serve-static/node_modules/send/index.js:245:31) 
    at SendStream.send (/home/ubuntu/chat2/node_modules/express/node_modules/connect/node_modules/serve-static/node_modules/send/index.js:564:19) 
    at onstat (/home/ubuntu/chat2/node_modules/express/node_modules/connect/node_modules/serve-static/node_modules/send/index.js:624:10) 
    at FSReqWrap.oncomplete (fs.js:82:15) 

任何想法關於如何解決這個問題?我似乎無法找到錯誤?

+0

我想,你應該尋找內存泄漏 –

+0

@AlexeyTen我已經調查了內存泄漏,你能指導我如何解決內存泄漏問題?我在問題中添加了更多錯誤日誌,您可能會看到。 – Faizan

+0

這個鏈接應該很好啓動https://www.google.com/search?q=nodejs+debug+memory+leak –

回答

2

你可以嘗試增加節點JS使用該內存限制,

節點--max_old_space_size = 8192 --optimize_for_size --max_executable_size = 4096 --stack_size = 4096

您可以使用它像這樣:

節點--max_old_space_size = 8192 --optimize_for_size --max_executable_size = 4096 --stack_size = 4096 yourfile.js

+0

我們在這裏談論哪些內存?應用程序運行期間由Node JS使用的服務器內存?它會對我的託管賬單產生不利影響嗎?我的應用程序位於AWS EC2上。 你能告訴我我必須在終端上運行這個命令嗎?因爲我現在正在永遠使用我的節點應用程序。有沒有辦法permanaentyl增加默認的內存? – Faizan

+0

你可以像這樣使用它永久啓動-c「--max_old_space_size = 8192 --optimize_for_size --max_executable_size = 4096 --stack_size = 4096」yourfile.js –

+0

我試過了和你說的完全一樣的命令永遠啓動-c「 - -max_old_space_size = 8192 --optimize_for_size --max_executable_size = 4096 --stack_size = 4096「index.js 它給消息永久進程運行,但我的網站仍然關閉。但是,當我用永遠啓動index.js的時候它就可以工作。 是什麼導致它不能使用命令參數? plz幫助 – Faizan