将 v8 的内存管理配置为智能的 node.js 进程 [英] Configuring v8's memory management to be smart for a node.js process

查看:20
本文介绍了将 v8 的内存管理配置为智能的 node.js 进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 node.js 上运行一个 XMPP 服务器,在一台大约 3.8 GB RAM 的机器上.以下是我们在调用 node 时传递的命令行参数:/opt/node/bin/node --max-old-space-size=3000 --trace-gc --trace-gc-verbose main.js

但是,我们经常需要在进程中看到超过 10 秒的 gc 暂停(有时超过 1 分钟的 gc 暂停,此时我们的服务器除了运行 GC 什么都不做).发生这种情况时,我们的进程处于正常的内存消耗状态:大约 1 GB 堆使用量.该进程有大约 2 GB 或可用空间,但该进程只是不使用它,并花一分钟时间尝试释放内存.

查看 --trace-gc-verbose 选项给出的 gc 跟踪,看起来大约 2 GB 的可用空间被标记为大对象空间",并且没有被使用,因为没有那么多大对象.尽管该进程迫切需要更多内存用于旧指针"和旧数据空间",但并未使用来自大对象空间"的空闲内存.

这是 gc 在进程中长时间 gc 暂停期间留下的痕迹:

<上一页>91635809 ms: Mark-sweep 968.8 (1039.0) -> 958.5 (1038.0) MB, 1/410 ms (+ 2287 ms,自标记开始后的 79 步,最大步长 140.227051 ms) [idle notification: finalize incremental] [GC in old要求的空间].内存分配器,使用:1088446464,可用:2124390400新空间,已使用:192,可用:8388416旧指针,已使用:633992112,可用:10460240,浪费:0旧数据空间,已使用:315819248,可用:149776,浪费:0代码空间,已用:5867936,可用:1271392,浪费:0地图空间,已使用:10257976,可用:6384072,浪费:0单元空间,已用:175936,可用:954304,浪费:0大对象空间,已使用:51413600,可用:212332518491636499 毫秒:Scavenge 965.5 (1038.0) -> 964.6 (1038.0) MB,17 毫秒(自上次 GC 以来的 10 步中增加了 109 毫秒)[Runtime::PerformGC].内存分配器,使用:1088446464,可用:2124390400新空间,已用:41256,可用:2055896旧指针,已使用:628458688,可用:15993664,浪费:0旧数据空间,已使用:315821792,可用:147232,浪费:0代码空间,已用:5904256,可用:1235072,浪费:0地图空间,已使用:10263072,可用:6378976,浪费:0单元空间,已用:175936,可用:954304,浪费:0大对象空间,已使用:51413600,可用:212332518491637979 毫秒:Scavenge 966.6 (1038.0) -> 964.7 (1038.0) MB,1 毫秒(自上次 GC 以来的 43 步中增加了 1404 毫秒)[Runtime::PerformGC].内存分配器,使用:1088446464,可用:2124390400新空间,已用:76736,可用:2020416旧指针,已使用:628458688,可用:15993664,浪费:0旧数据空间,已使用:315845520,可用:123504,浪费:0代码空间,已用:5980576,可用:1158752,浪费:0地图空间,已使用:10271416,可用:6370632,浪费:0单元空间,已用:175936,可用:954304,浪费:0大对象空间,已使用:51413600,可用:212332518491639088 ms: Mark-sweep 965.2 (1038.0) -> 935.8 (1038.0) MB, 1/369 ms (+ 2235 ms,自标记开始后的 71 个步骤,最大步骤 69.053955 ms) [idle notification: finalize incremental] [GC in old要求的空间].内存分配器,使用:1088446464,可用:2124390400新空间,已用:168,可用:2096984旧指针,已使用:641099768,可用:3352584,浪费:0旧数据空间,已使用:315820152,可用:148872,浪费:0代码空间,已用:5862976,可用:1276352,浪费:0地图空间,已用:10256744,可用:6385304,浪费:0单元空间,已用:175936,可用:954304,浪费:0大对象空间,已使用:51413600,可用:212332518491640987 毫秒:Scavenge 966.4 (1038.0) -> 964.5 (1038.0) MB,1 毫秒(自上次 GC 以来的 36 步中增加了 1275 毫秒)[分配失败].内存分配器,使用:1088446464,可用:2124390400新空间,已用:100944,可用:1996208旧指针,已使用:627957504,可用:16494848,浪费:0旧数据空间,已使用:315830536,可用:138488,浪费:0代码空间,已用:5951200,可用:1188128,浪费:0地图空间,已使用:10266376,可用:6375672,浪费:0单元空间,已用:175936,可用:954304,浪费:0大对象空间,已使用:51413600,可用:212332518491641560 毫秒:Scavenge 966.5 (1038.0) -> 964.8 (1038.0) MB,2 毫秒(自上次 GC 以来的 29 步中增加了 481 毫秒)[Runtime::PerformGC].内存分配器,使用:1088446464,可用:2124390400新空间,已使用:180712,可用:1916440旧指针,已使用:627957504,可用:16494848,浪费:0旧数据空间,已使用:315871432,可用:97592,浪费:0代码空间,已用:6019392,可用:1119936,浪费:0地图空间,已用:10269848,可用:6372200,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:212332518491642589 ms: Mark-sweep 965.9 (1038.0) -> 947.7 (1038.0) MB, 1/371 ms (+ 2369 ms,自标记开始以来的 89 步,最大步长 67.302002 ms) [空闲通知:完成增量] [旧 GC要求的空间].内存分配器,使用:1088446464,可用:2124390400新空间,已用:264,可用:2096888旧指针,已使用:639592840,可用:4859512,浪费:0旧数据空间,已使用:315849408,可用:119616,浪费:0代码空间,已用:5862976,可用:1276352,浪费:0地图空间,已使用:10257136,可用:6384912,浪费:0单元空间,已用:175936,可用:954304,浪费:0大对象空间,已使用:51413600,可用:212332518491643688 毫秒:Scavenge 966.4 (1038.0) -> 964.6 (1038.0) MB,5 毫秒(自上次 GC 以来的 21 个步骤中增加了 356 毫秒)[Runtime::PerformGC].内存分配器,使用:1088446464,可用:2124390400新空间,已用:144088,可用:1953064旧指针,已使用:627748368,可用:16703984,浪费:0旧数据空间,已使用:315864504,可用:104520,浪费:0代码空间,已用:5990240,可用:1149088,浪费:0地图空间,已使用:10264248,可用:6377800,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:212332518491645276 毫秒:Scavenge 966.5 (1038.0) -> 964.8 (1039.0) MB,2 毫秒(自上次 GC 以来的 46 步中增加了 1520 毫秒)[分配失败].内存分配器,使用:1089495040,可用:2123341824新空间,已使用:108192,可用:1988960旧指针,已使用:627748368,可用:16703984,浪费:0旧数据空间,已使用:315978760,可用:1022200,浪费:0代码空间,已用:6039008,可用:1100320,浪费:0地图空间,已使用:10274216,可用:6367832,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:212227660891645577 毫秒:Scavenge 966.6 (1039.0) -> 965.8 (1039.0) MB,3 毫秒(自上次 GC 以来的 23 步中增加了 263 毫秒)[分配失败].内存分配器,使用:1089495040,可用:2123341824新空间,已用:516168,可用:1580984旧指针,已使用:627843088,可用:16609264,浪费:0旧数据空间,已使用:316550680,可用:450280,浪费:0代码空间,已用:6039008,可用:1100320,浪费:0地图空间,已使用:10275280,可用:6366768,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:212227660891645645 毫秒:Scavenge 967.3 (1039.0) -> 966.8 (1039.0) MB,5 毫秒(自上次 GC 以来的 16 步中增加了 8 毫秒)[分配失败].内存分配器,使用:1089495040,可用:2123341824新空间,已用:1012304,可用:3182000旧指针,已使用:627968088,可用:16484264,浪费:0旧数据空间,已使用:316947304,可用:53656,浪费:0代码空间,已用:6039008,可用:1100320,浪费:0地图空间,已使用:10275280,可用:6366768,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:212227660891645948 毫秒:Scavenge 969.8 (1039.0) -> 968.6 (1041.0) MB,9 毫秒(自上次 GC 以来的 35 步中增加了 188 毫秒)[分配失败].内存分配器,使用:1091592192,可用:2121244672新空间,已用:1032320,可用:3161984旧指针,已使用:628219008,可用:16233344,浪费:0旧数据空间,已使用:318537928,可用:526904,浪费:0代码空间,已用:6039264,可用:1100064,浪费:0地图空间,已用:10276232,可用:6365816,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:212017945691646093 毫秒:Scavenge 971.6 (1041.0) -> 970.5 (1042.0) MB,13 毫秒(自上次 GC 以来的 30 步中增加了 36 毫秒)[Runtime::PerformGC].内存分配器,使用:1092640768,可用:2120196096新空间,已用:2044456,可用:6344152旧指针,已使用:628437424,可用:16014928,浪费:0旧数据空间,已使用:319366376,可用:730392,浪费:0代码空间,已用:6039264,可用:1100064,浪费:0地图空间,已用:10276232,可用:6365816,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已用:51413600,可用:211913088091646306 毫秒:Scavenge 976.5 (1042.0) -> 974.7 (1044.0) MB,1/14 毫秒(自上次 GC 以来的 67 步中增加了 114 毫秒)[分配失败].内存分配器,使用:1094737920,可用:2118098944新空间,已用:2064112,可用:6324496旧指针,已使用:630440024,可用:14012328,浪费:0旧数据空间,已使用:321653384,可用:507256,浪费:0代码空间,已用:6055936,可用:1083392,浪费:0地图空间,已使用:10278192,可用:6363856,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已用:51413600,可用:211703372891646386 毫秒:Scavenge 980.6 (1044.0) -> 979.2 (1046.0) MB,12 毫秒(自上次 GC 以来 64 步中增加了 10 毫秒)[分配失败].内存分配器,使用:1096835072,可用:2116001792新空间,已用:4127736,可用:12649480旧指针,已使用:631182984,可用:13269368,浪费:0旧数据空间,已使用:323586008,可用:638504,浪费:0代码空间,已用:6055936,可用:1083392,浪费:0地图空间,已使用:10278192,可用:6363856,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已用:51413600,可用:2114936576由于推广率高,新空间有限:1 MB91646810 ms: Mark-sweep 979.2 (1046.0) -> 973.2 (1049.0) MB, 1/422 ms (+ 2500 ms in 303 steps in 303 steps since the start of marking, max step 0.122070 ms) [StackGuard GC request] [GC in old space requested].内存分配器,使用:1099980800,可用:2112856064新空间,已使用:192,可用:1048384旧指针,已使用:636894816,可用:9621408,浪费:0旧数据空间,已使用:325256448,可用:0,浪费:0代码空间,已用:5860928,可用:1278400,浪费:0地图空间,已使用:10257976,可用:6384072,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:211179084891646825 毫秒:清除 974.2 (1049.0) -> 979.0 (1049.0) MB,7 毫秒 [分配失败].内存分配器,使用:1099980800,可用:2112856064新空间,已用:257960,可用:790616旧指针,已使用:635948464,可用:10567760,浪费:0旧数据空间,已使用:325256448,可用:0,浪费:0代码空间,已用:5873440,可用:1265888,浪费:0地图空间,已使用:10258536,可用:6383512,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:211179084891646834 毫秒:清除 979.7 (1049.0) -> 980.0 (1049.0) MB,2 毫秒 [分配失败].内存分配器,使用:1099980800,可用:2112856064新空间,已用:257968,可用:790608旧指针,已使用:635671408,可用:10844816,浪费:0旧数据空间,已使用:325256448,可用:0,浪费:0代码空间,已用:5873440,可用:1265888,浪费:0地图空间,已使用:10258536,可用:6383512,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:211179084891646842 毫秒:清除 980.7 (1049.0) -> 980.6 (1049.0) MB,2 毫秒 [分配失败].内存分配器,使用:1099980800,可用:2112856064新空间,已用:257960,可用:790616旧指针,已使用:635493872,可用:11022352,浪费:0旧数据空间,已使用:325256448,可用:0,浪费:0代码空间,已用:5873440,可用:1265888,浪费:0地图空间,已使用:10258536,可用:6383512,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:211179084891646849 毫秒:清除 981.3 (1049.0) -> 981.2 (1049.0) MB,1 毫秒 [分配失败].内存分配器,使用:1099980800,可用:2112856064新空间,已用:257968,可用:790608旧指针,已使用:635981640,可用:10534584,浪费:0旧数据空间,已使用:325256448,可用:0,浪费:0代码空间,已用:5873440,可用:1265888,浪费:0地图空间,已使用:10258536,可用:6383512,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:211179084891646863 毫秒:清除 981.9 (1049.0) -> 981.6 (1051.0) MB,1 毫秒 [分配失败].内存分配器,使用:1102077952,可用:2110758912新空间,已用:257960,可用:790616旧指针,已使用:637013288,可用:10534872,浪费:0旧数据空间,已使用:326288384,可用:0,浪费:0代码空间,已用:5873440,可用:1265888,浪费:0地图空间,已使用:10258536,可用:6383512,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:210969369691651639 毫秒:标记扫描 981.6 (1051.0) -> 924.7 (1051.0) MB,1/4775 毫秒 [最后的 gc].内存分配器,使用:1102077952,可用:2110758912新空间,已用:96,可用:1048480旧指针,已使用:626794192,可用:20753968,浪费:0旧数据空间,已使用:275760200,可用:50528184,浪费:0代码空间,已用:6182208,可用:957120,浪费:0地图空间,已使用:10257808,可用:6384240,浪费:0单元空间,已用:176192,可用:954048,浪费:0大对象空间,已使用:51413600,可用:210969369691663655 毫秒:标记扫描 924.7 (1051.0) -> 924.7 (1050.0) MB,1/12015 毫秒 [最后的 gc].内存分配器,使用:1101029376,可用:2111807488新空间,已用:0,可用:1048576旧指针,已使用:626169464,可用:21378696,浪费:0旧数据空间,已使用:275759960,可用:49496488,浪费:0代码空间,已用:5850624,可用:1288704,浪费:0地图空间,已使用:10257808,可用:6384240,浪费:

我可以做任何调整来更好地配置 v8 的内存管理吗?关于这里有什么帮助的任何想法?

解决方案

我觉得是V8的限制.它在 64 位机器上使用的 RAM 不超过 1.7 GB.引用 FAQ:

<块引用>

目前,默认情况下 v8 在 32 位上的内存限制为 512mb系统,以及 1gb 在 64 位系统上.可以通过设置来提高限制--max-old-space-size 最大为 ~1gb(32 位)和 ~1.7gb(64 位),但建议您拆分单个进程如果你达到内存限制,可以分成几个工人.

因此,在此之后,您将达到最大内存限制,并且由于垃圾收集而导致的 10 秒暂停是一个大问题.您应该考虑定期/在空闲时运行垃圾收集器,以避免达到限制并面临长时间的延迟.

您可以传递以帮助解决这种情况的参数是:(检查此 博客)

  • --nouse-idle-notification 防止不断运行 GC 和
  • --expose-gc 这将允许您从代码中运行 GC.

最重要的是调试您的代码以消除内存泄漏.使用这些包在您的代码中找到它们:

We run an XMPP server on node.js, on a machine with around 3.8 GB RAM. Here are the command line parameters we pass while invoking node : /opt/node/bin/node --max-old-space-size=3000 --trace-gc --trace-gc-verbose main.js

However, we frequently have to see more than 10 second gc pauses in the process ( sometimes as much as more than 1 minute gc pauses, where our server is doing nothing but running GC ). When this happens, our process is at it's normal memory consumption : around 1 GB heap usage. There is around 2 GB or free space available for the process, but the process just does not use it and spends a minute trying to free memory.

Looking at the gc trace given by --trace-gc-verbose option, it looks like around 2 GB free space is marked as "Large object space", and is not used, as there are not that many large objects. And though the process is in dire need of more memory for "Old pointers" and "Old data space", this free memory from "Large object space" is not used.

Here is the trace left by gc during one of those times where there was a long gc pause in the process :

    

91635809 ms: Mark-sweep 968.8 (1039.0) -> 958.5 (1038.0) MB, 1 / 410 ms (+ 2287 ms in 79 steps since start of marking, biggest step 140.227051 ms) [idle notification: finalize incremental] [GC in old space requested].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:      192, available:  8388416
Old pointers,       used: 633992112, available: 10460240, waste:        0
Old data space,     used: 315819248, available:   149776, waste:        0
Code space,         used:  5867936, available:  1271392, waste:        0
Map space,          used: 10257976, available:  6384072, waste:        0
Cell space,         used:   175936, available:   954304, waste:        0
Large object space, used: 51413600, available: 2123325184
91636499 ms: Scavenge 965.5 (1038.0) -> 964.6 (1038.0) MB, 17 ms (+ 109 ms in 10 steps since last GC) [Runtime::PerformGC].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:    41256, available:  2055896
Old pointers,       used: 628458688, available: 15993664, waste:        0
Old data space,     used: 315821792, available:   147232, waste:        0
Code space,         used:  5904256, available:  1235072, waste:        0
Map space,          used: 10263072, available:  6378976, waste:        0
Cell space,         used:   175936, available:   954304, waste:        0
Large object space, used: 51413600, available: 2123325184
91637979 ms: Scavenge 966.6 (1038.0) -> 964.7 (1038.0) MB, 1 ms (+ 1404 ms in 43 steps since last GC) [Runtime::PerformGC].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:    76736, available:  2020416
Old pointers,       used: 628458688, available: 15993664, waste:        0
Old data space,     used: 315845520, available:   123504, waste:        0
Code space,         used:  5980576, available:  1158752, waste:        0
Map space,          used: 10271416, available:  6370632, waste:        0
Cell space,         used:   175936, available:   954304, waste:        0
Large object space, used: 51413600, available: 2123325184
91639088 ms: Mark-sweep 965.2 (1038.0) -> 935.8 (1038.0) MB, 1 / 369 ms (+ 2235 ms in 71 steps since start of marking, biggest step 69.053955 ms) [idle notification: finalize incremental] [GC in old space requested].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:      168, available:  2096984
Old pointers,       used: 641099768, available:  3352584, waste:        0
Old data space,     used: 315820152, available:   148872, waste:        0
Code space,         used:  5862976, available:  1276352, waste:        0
Map space,          used: 10256744, available:  6385304, waste:        0
Cell space,         used:   175936, available:   954304, waste:        0
Large object space, used: 51413600, available: 2123325184
91640987 ms: Scavenge 966.4 (1038.0) -> 964.5 (1038.0) MB, 1 ms (+ 1275 ms in 36 steps since last GC) [allocation failure].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:   100944, available:  1996208
Old pointers,       used: 627957504, available: 16494848, waste:        0
Old data space,     used: 315830536, available:   138488, waste:        0
Code space,         used:  5951200, available:  1188128, waste:        0
Map space,          used: 10266376, available:  6375672, waste:        0
Cell space,         used:   175936, available:   954304, waste:        0
Large object space, used: 51413600, available: 2123325184
91641560 ms: Scavenge 966.5 (1038.0) -> 964.8 (1038.0) MB, 2 ms (+ 481 ms in 29 steps since last GC) [Runtime::PerformGC].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:   180712, available:  1916440
Old pointers,       used: 627957504, available: 16494848, waste:        0
Old data space,     used: 315871432, available:    97592, waste:        0
Code space,         used:  6019392, available:  1119936, waste:        0
Map space,          used: 10269848, available:  6372200, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2123325184
91642589 ms: Mark-sweep 965.9 (1038.0) -> 947.7 (1038.0) MB, 1 / 371 ms (+ 2369 ms in 89 steps since start of marking, biggest step 67.302002 ms) [idle notification: finalize incremental] [GC in old space requested].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:      264, available:  2096888
Old pointers,       used: 639592840, available:  4859512, waste:        0
Old data space,     used: 315849408, available:   119616, waste:        0
Code space,         used:  5862976, available:  1276352, waste:        0
Map space,          used: 10257136, available:  6384912, waste:        0
Cell space,         used:   175936, available:   954304, waste:        0
Large object space, used: 51413600, available: 2123325184
91643688 ms: Scavenge 966.4 (1038.0) -> 964.6 (1038.0) MB, 5 ms (+ 356 ms in 21 steps since last GC) [Runtime::PerformGC].
Memory allocator,   used: 1088446464, available: 2124390400
New space,          used:   144088, available:  1953064
Old pointers,       used: 627748368, available: 16703984, waste:        0
Old data space,     used: 315864504, available:   104520, waste:        0
Code space,         used:  5990240, available:  1149088, waste:        0
Map space,          used: 10264248, available:  6377800, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2123325184
91645276 ms: Scavenge 966.5 (1038.0) -> 964.8 (1039.0) MB, 2 ms (+ 1520 ms in 46 steps since last GC) [allocation failure].
Memory allocator,   used: 1089495040, available: 2123341824
New space,          used:   108192, available:  1988960
Old pointers,       used: 627748368, available: 16703984, waste:        0
Old data space,     used: 315978760, available:  1022200, waste:        0
Code space,         used:  6039008, available:  1100320, waste:        0
Map space,          used: 10274216, available:  6367832, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2122276608
91645577 ms: Scavenge 966.6 (1039.0) -> 965.8 (1039.0) MB, 3 ms (+ 263 ms in 23 steps since last GC) [allocation failure].
Memory allocator,   used: 1089495040, available: 2123341824
New space,          used:   516168, available:  1580984
Old pointers,       used: 627843088, available: 16609264, waste:        0
Old data space,     used: 316550680, available:   450280, waste:        0
Code space,         used:  6039008, available:  1100320, waste:        0
Map space,          used: 10275280, available:  6366768, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2122276608
91645645 ms: Scavenge 967.3 (1039.0) -> 966.8 (1039.0) MB, 5 ms (+ 8 ms in 16 steps since last GC) [allocation failure].
Memory allocator,   used: 1089495040, available: 2123341824
New space,          used:  1012304, available:  3182000               
Old pointers,       used: 627968088, available: 16484264, waste:        0
Old data space,     used: 316947304, available:    53656, waste:        0
Code space,         used:  6039008, available:  1100320, waste:        0
Map space,          used: 10275280, available:  6366768, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2122276608
91645948 ms: Scavenge 969.8 (1039.0) -> 968.6 (1041.0) MB, 9 ms (+ 188 ms in 35 steps since last GC) [allocation failure].
Memory allocator,   used: 1091592192, available: 2121244672
New space,          used:  1032320, available:  3161984
Old pointers,       used: 628219008, available: 16233344, waste:        0
Old data space,     used: 318537928, available:   526904, waste:        0
Code space,         used:  6039264, available:  1100064, waste:        0
Map space,          used: 10276232, available:  6365816, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2120179456
91646093 ms: Scavenge 971.6 (1041.0) -> 970.5 (1042.0) MB, 13 ms (+ 36 ms in 30 steps since last GC) [Runtime::PerformGC].
Memory allocator,   used: 1092640768, available: 2120196096
New space,          used:  2044456, available:  6344152
Old pointers,       used: 628437424, available: 16014928, waste:        0
Old data space,     used: 319366376, available:   730392, waste:        0
Code space,         used:  6039264, available:  1100064, waste:        0
Map space,          used: 10276232, available:  6365816, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2119130880
91646306 ms: Scavenge 976.5 (1042.0) -> 974.7 (1044.0) MB, 1 / 14 ms (+ 114 ms in 67 steps since last GC) [allocation failure].
Memory allocator,   used: 1094737920, available: 2118098944
New space,          used:  2064112, available:  6324496
Old pointers,       used: 630440024, available: 14012328, waste:        0
Old data space,     used: 321653384, available:   507256, waste:        0
Code space,         used:  6055936, available:  1083392, waste:        0
Map space,          used: 10278192, available:  6363856, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2117033728
91646386 ms: Scavenge 980.6 (1044.0) -> 979.2 (1046.0) MB, 12 ms (+ 10 ms in 64 steps since last GC) [allocation failure].
Memory allocator,   used: 1096835072, available: 2116001792
New space,          used:  4127736, available: 12649480
Old pointers,       used: 631182984, available: 13269368, waste:        0
Old data space,     used: 323586008, available:   638504, waste:        0
Code space,         used:  6055936, available:  1083392, waste:        0
Map space,          used: 10278192, available:  6363856, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2114936576
Limited new space size due to high promotion rate: 1 MB
91646810 ms: Mark-sweep 979.2 (1046.0) -> 973.2 (1049.0) MB, 1 / 422 ms (+ 2500 ms in 303 steps since start of marking, biggest step 0.122070 ms) [StackGuard GC request] [GC in old space requested].
Memory allocator,   used: 1099980800, available: 2112856064
New space,          used:      192, available:  1048384
Old pointers,       used: 636894816, available:  9621408, waste:        0
Old data space,     used: 325256448, available:        0, waste:        0
Code space,         used:  5860928, available:  1278400, waste:        0
Map space,          used: 10257976, available:  6384072, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2111790848
91646825 ms: Scavenge 974.2 (1049.0) -> 979.0 (1049.0) MB, 7 ms [allocation failure].
Memory allocator,   used: 1099980800, available: 2112856064
New space,          used:   257960, available:   790616
Old pointers,       used: 635948464, available: 10567760, waste:        0
Old data space,     used: 325256448, available:        0, waste:        0
Code space,         used:  5873440, available:  1265888, waste:        0
Map space,          used: 10258536, available:  6383512, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2111790848
91646834 ms: Scavenge 979.7 (1049.0) -> 980.0 (1049.0) MB, 2 ms [allocation failure].
Memory allocator,   used: 1099980800, available: 2112856064
New space,          used:   257968, available:   790608
Old pointers,       used: 635671408, available: 10844816, waste:        0
Old data space,     used: 325256448, available:        0, waste:        0
Code space,         used:  5873440, available:  1265888, waste:        0
Map space,          used: 10258536, available:  6383512, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2111790848
91646842 ms: Scavenge 980.7 (1049.0) -> 980.6 (1049.0) MB, 2 ms [allocation failure].
Memory allocator,   used: 1099980800, available: 2112856064
New space,          used:   257960, available:   790616
Old pointers,       used: 635493872, available: 11022352, waste:        0
Old data space,     used: 325256448, available:        0, waste:        0
Code space,         used:  5873440, available:  1265888, waste:        0
Map space,          used: 10258536, available:  6383512, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2111790848
91646849 ms: Scavenge 981.3 (1049.0) -> 981.2 (1049.0) MB, 1 ms [allocation failure].
Memory allocator,   used: 1099980800, available: 2112856064
New space,          used:   257968, available:   790608
Old pointers,       used: 635981640, available: 10534584, waste:        0
Old data space,     used: 325256448, available:        0, waste:        0
Code space,         used:  5873440, available:  1265888, waste:        0
Map space,          used: 10258536, available:  6383512, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2111790848
91646863 ms: Scavenge 981.9 (1049.0) -> 981.6 (1051.0) MB, 1 ms [allocation failure].
Memory allocator,   used: 1102077952, available: 2110758912
New space,          used:   257960, available:   790616
Old pointers,       used: 637013288, available: 10534872, waste:        0
Old data space,     used: 326288384, available:        0, waste:        0
Code space,         used:  5873440, available:  1265888, waste:        0
Map space,          used: 10258536, available:  6383512, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2109693696
91651639 ms: Mark-sweep 981.6 (1051.0) -> 924.7 (1051.0) MB, 1 / 4775 ms [last resort gc].
Memory allocator,   used: 1102077952, available: 2110758912
New space,          used:       96, available:  1048480
Old pointers,       used: 626794192, available: 20753968, waste:        0
Old data space,     used: 275760200, available: 50528184, waste:        0
Code space,         used:  6182208, available:   957120, waste:        0
Map space,          used: 10257808, available:  6384240, waste:        0
Cell space,         used:   176192, available:   954048, waste:        0
Large object space, used: 51413600, available: 2109693696
91663655 ms: Mark-sweep 924.7 (1051.0) -> 924.7 (1050.0) MB, 1 / 12015 ms [last resort gc].
Memory allocator,   used: 1101029376, available: 2111807488
New space,          used:        0, available:  1048576
Old pointers,       used: 626169464, available: 21378696, waste:        0
Old data space,     used: 275759960, available: 49496488, waste:        0
Code space,         used:  5850624, available:  1288704, waste:        0
Map space,          used: 10257808, available:  6384240, waste:                 


Is there any tuning that I can do to better configure v8's memory management ? Any ideas on what might help here ?

解决方案

I think it is a limitation of V8. It does not use more than 1.7 GB of RAM on 64 bit machines. Quote from FAQ:

Currently, by default v8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.

So following this you are hitting the maximum memory limits and the 10 second pause due to garbage collection is a big worry. You should consider running garbage collector periodically/when idle to avoid hitting the limit and facing long delays.

Parameters which you can pass to help the situation are : (Check this blog)

  • --nouse-idle-notification which prevents running GC constantly and
  • --expose-gc which will allow you to run GC from your code.

Most importantly debug your code to remove memory leaks. Use these package to find them in your code:

这篇关于将 v8 的内存管理配置为智能的 node.js 进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆