Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js nodejs v8内存gc分配失败_Node.js_Memory_Garbage Collection_V8 - Fatal编程技术网

Node.js nodejs v8内存gc分配失败

Node.js nodejs v8内存gc分配失败,node.js,memory,garbage-collection,v8,Node.js,Memory,Garbage Collection,V8,我试图用一个不做任何事情的服务器来评测nodejsv8内存。 我使用node memwatch获取堆差异。我在连接之前和连接断开之后收集堆信息。我用了一块手表。我从客户端尝试了200个并发连接 这是连接断开后的gc跟踪 谁能帮助我理解: 1.为什么记忆在增加?连接断开后,服务器完全不做任何事情。当垃圾被收集时,它不应该总是掉下来吗? 2.这些分配失败是什么?我如何真正解释这里的痕迹 15802 ms: Mark-sweep 8.9 (45.0) -> 8.1 (45.0) MB, 58

我试图用一个不做任何事情的服务器来评测nodejsv8内存。 我使用node memwatch获取堆差异。我在连接之前和连接断开之后收集堆信息。我用了一块手表。我从客户端尝试了200个并发连接

这是连接断开后的gc跟踪

谁能帮助我理解:

1.为什么记忆在增加?连接断开后,服务器完全不做任何事情。当垃圾被收集时,它不应该总是掉下来吗?
2.这些分配失败是什么?我如何真正解释这里的痕迹

 15802 ms: Mark-sweep 8.9 (45.0) -> 8.1 (45.0) MB, 58 ms [allocation failure] [GC in old space forced by flags].
 16144 ms: Mark-sweep 9.2 (45.0) -> 8.4 (45.0) MB, 53 ms [allocation failure] [GC in old space forced by flags].
 16495 ms: Mark-sweep 9.5 (45.0) -> 8.7 (46.0) MB, 60 ms [allocation failure] [GC in old space forced by flags].
 16837 ms: Mark-sweep 9.8 (46.0) -> 9.0 (46.0) MB, 56 ms [allocation failure] [GC in old space forced by flags].
 17197 ms: Mark-sweep 10.1 (46.0) -> 9.4 (46.0) MB, 62 ms [allocation failure] [GC in old space forced by flags].
 17905 ms: Mark-sweep 11.5 (46.0) -> 10.0 (47.0) MB, 74 ms [Runtime::PerformGC] [GC in old space forced by flags].                                                               
 18596 ms: Mark-sweep 12.2 (47.0) -> 10.7 (47.0) MB, 75 ms [Runtime::PerformGC] [GC in old space forced by flags].
 19315 ms: Mark-sweep 12.8 (47.0) -> 11.3 (48.0) MB, 83 ms [allocation failure] [GC in old space forced by flags].
 20035 ms: Mark-sweep 13.4 (48.0) -> 12.0 (49.0) MB, 90 ms [Runtime::PerformGC] [GC in old space forced by flags].
 21487 ms: Mark-sweep 16.0 (49.0) -> 13.2 (50.0) MB, 96 ms [Runtime::PerformGC] [GC in old space forced by flags].
 22950 ms: Mark-sweep 17.3 (50.0) -> 14.5 (52.0) MB, 116 ms [Runtime::PerformGC] [GC in old space forced by flags].
 24376 ms: Mark-sweep 18.8 (52.0) -> 15.9 (53.0) MB, 114 ms [allocation failure] [GC in old space forced by flags].
 25849 ms: Mark-sweep 19.9 (53.0) -> 17.2 (54.0) MB, 129 ms [Runtime::PerformGC] [GC in old space forced by flags].
 28773 ms: Mark-sweep 25.2 (54.0) -> 19.7 (57.0) MB, 149 ms [allocation failure] [GC in old space forced by flags].
 31725 ms: Mark-sweep 27.7 (57.0) -> 22.2 (59.0) MB, 172 ms [Runtime::PerformGC] [GC in old space forced by flags].
 34678 ms: Mark-sweep 30.2 (59.0) -> 24.7 (61.0) MB, 190 ms [Runtime::PerformGC] [GC in old space forced by flags].
 44045 ms: Mark-sweep 28.4 (61.0) -> 25.8 (63.0) MB, 180 ms [idle notification] [GC in old space forced by flags].
 44216 ms: Mark-sweep 25.8 (63.0) -> 25.8 (63.0) MB, 170 ms [idle notification] [GC in old space requested].
 57471 ms: Mark-sweep 26.9 (63.0) -> 25.8 (62.0) MB, 167 ms [Runtime::PerformGC] [GC in old space forced by flags].
 57651 ms: Mark-sweep 26.8 (62.0) -> 25.5 (62.0) MB, 160 ms [Runtime::PerformGC] [GC in old space forced by flags].
 57828 ms: Mark-sweep 26.5 (62.0) -> 25.5 (62.0) MB, 159 ms [Runtime::PerformGC] [GC in old space forced by flags].
谢谢,

“分配失败”听起来很戏剧性,但没有真正的失败。这只是意味着我们分配了太多的内存,现在是时候进行GC,看看我们是否可以收集一些内存

看起来您正在使用--gc全局标志(“由标志强制的gc”)运行。这对于生产来说是个坏主意,尽管在调试时可以缩小问题范围

我不知道你的进程为什么会泄漏。您可能会发现堆分析器很有用。根据代码,请参见

PrintF("%s %.1f (%.1f) -> %.1f (%.1f) MB, ",
       CollectorString(),
       static_cast<double>(start_object_size_) / MB,                                                                                    
       static_cast<double>(start_memory_size_) / MB, 
       SizeOfHeapObjects(),
       end_memory_size_mb);
总而言之:

PrintF("total_size_before=%" V8_PTR_PREFIX "d ", start_object_size_);                                                                   
PrintF("total_size_after=%" V8_PTR_PREFIX "d ", heap_->SizeOfObjects());

至于为什么在我的应用程序空闲时启动\u对象\u大小\u会增加,我猜可能是在gc期间,一些对象被提升到旧空间,导致旧空间中的对象大小增加。

是的,我使用--gc global和compact来确保在获取堆差异之前收集所有垃圾。这很小。问题是为什么在gc期间mem会增加?这对我很有用,即使是在这么多年以后,因为它给了我在代码中搜索什么的线索。以下是当前代码:
PrintF("total_size_before=%" V8_PTR_PREFIX "d ", start_object_size_);                                                                   
PrintF("total_size_after=%" V8_PTR_PREFIX "d ", heap_->SizeOfObjects());