【问题标题】:Node JS Process out of memory [closed]Node JS进程内存不足[关闭]
【发布时间】:2016-09-27 14:46:38
【问题描述】:

我一直在使用forever JS来连续运行我的node 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)

关于如何解决这个问题的任何想法?我似乎找不到错误?

【问题讨论】:

  • 我猜,你应该寻找内存泄漏
  • @AlexeyTen 我已经调查过内存泄漏,您能指导我如何解决内存泄漏问题吗?我在我的问题中添加了更多错误日志,您可能会看到。
  • 这个链接应该是好的开始google.com/search?q=nodejs+debug+memory+leak
  • 有时 nodejs 被意外安装为 32 位版本。我认为网站上曾经有一个错误,它总是选择 32 位版本。至少我曾经遇到过这个问题......

标签: javascript node.js process garbage-collection forever


【解决方案1】:

你可以尝试使用这个来增加node 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

【讨论】:

  • 我们在这里讨论的是哪个内存?应用程序运行期间 Node JS 使用的服务器是否在内存中?它会对我的托管费用产生任何不利影响吗?我的应用程序在 AWS EC2 上。你能告诉我我必须在终端上运行这个命令吗?因为我现在正在使用永远运行我的节点应用程序。有什么办法可以永久增加默认内存?
  • 你可以永远这样使用它 start -c "--max_old_space_size=8192 --optimize_for_size --max_executable_size=4096 --stack_size=4096 " yourfile.js
  • 我尝试了和你说的完全相同的命令 forever start -c "--max_old_space_size=8192 --optimize_for_size --max_executable_size=4096 --stack_size=4096 " index.js 它给出消息永远进程运行但我的网站仍然关闭。但是,当我使用 forever start index.js 进行操作时,它可以工作。是什么导致它不能使用命令参数?请帮助
  • --optimize_for_size --max_executable_size=4096 --stack_size=4096 不适用于node.js v14.1.0
猜你喜欢
  • 1970-01-01
  • 2013-08-18
  • 1970-01-01
  • 1970-01-01
  • 2021-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多