2012-12-20 101 views
9

我試圖用一個什麼都不做的服務器來配置nodejs v8內存。 我用節點memwatch來獲取堆差異。在連接之前和連接斷開之後,我收集堆信息。我用節點memwatch。我從客戶端嘗試了200個併發連接。nodejs v8內存gc分配失敗

這是連接撕下後的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]. 

感謝,

回答

1

據代碼:

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); 

每一行是一個GC,當GC開始,

start_object_size_ = heap_->SizeOfObjects(); 

在GC總結:

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

至於爲什麼start_object_size_的當我的應用程序閒置的時間增加,我猜可能在gc期間,一些對象得到親對舊空間的注意力增加,並導致舊空間中的物體尺寸增加。

5

「分配失敗」 聽起來很戲劇性,但是沒有涉及真正的失敗。這只是意味着我們分配了太多的內存,以至於我們需要做一次GC來查看是否可以收集一些內存。

它看起來像你用--gc-global標誌運行(「GC被標誌強制」)。對於生產來說這是一個壞主意,儘管在調試時縮小問題可能沒有問題。

我不知道你的過程爲什麼會泄漏。您可能會發現堆分析器很有用。見https://github.com/felixge/node-memory-leak-tutorial

+0

是的,我正在使用--gc-global和compact以確保在採取堆比較之前收集的所有垃圾。那很小。問題是爲什麼mem在gc期間增加了? – haijin