Home  >  Q&A  >  body text

javascript - node memory overflow problem

<--- Last few GCs --->

117435494 ms: Mark-sweep 1244.2 (1352.1) -> 1226.4 (1306.1) MB, 2539.5 / 0.0 ms [allocation failure] [GC in old space requested].
117437812 ms: Mark-sweep 1226.4 (1306.1) -> 1225.0 (1288.1) MB, 2318.0 / 0.0 ms [last resort gc].
117440139 ms: Mark-sweep 1225.0 (1288.1) -> 1224.7 (1288.1) MB, 2326.8 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

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

Security context: 0xa0c120cfb39 <JS Object>
    1: set [/home/iclassroom/nodejs/cnwkw/node_modules/express-session/session/memory.js:~131] 
    [pc=0x3cd12a011ce7] (this=0x23d9dec61609 
    <a MemoryStore with map 0x9ff52e70789>,
    sessionId=0x2ae89ca06ba9 <String[32]: tjNgaUldqGDhIny-NrTy-k2Z14N07L1f>,
session=0x2ae89ca06be1 <a Session with map 0x9ff52ed4809>,callback=0x2ae89ca08c79 
    <JS Function onsave (SharedFunctionInfo 0x173be2d1b1)>)
    2: save [...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/root/.nvm/versions/node/v6.10.2/bin/node]
 2: 0x109b7ac [/root/.nvm/versions/node/v6.10.2/bin/node]
我想大声告诉你我想大声告诉你2713 days ago791

reply all(2)I'll reply

  • 阿神

    阿神2017-05-16 13:31:53

    When executing a file, use

    node --inspect --expose-gc XXX.js

    The two flags --inspact tell it to debug through chrome devtool, and --expose-gc mean that you can actively collect memory through the global.gc() method.

    After execution, there will be a chrome://协议的链接,粘贴进chrome,就会出现最常见的chrome dev tool,在profile 里面,点击第二栏 Take Heap Snapshot,然后点击Take Snapshot,记录一次当前heap内存使用情况,此时就会出现当前的内存使用情况的快照,然后等一下,让node程序运行一段时间,再记录一次,然后点击左上角的Summary切换成Comparison mode. By comparing it with the first time, you can find out what has been increased and you can find the specific problem.

    Secondly, leaks can be passed node 全局变量 processmemoryUsage 方法,打印出 heap
    究竟的使用量,通过对比代码前后使用量的差别,判断是否有 heap before and after the suspicious code segment.

    According to the error message of the subject, such as the problem when recording the express session, add more break points where the session is written, and use the process.memoryUsage() method to find out where the problem is. This requires patience and luck.

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:31:53

    express-session directly uses memory itself to have leakage problems. The document has already stated that it can be used with mongo or redis

    reply
    0
  • Cancelreply