使用node.exe部署程序包时,Node Js垃圾收集器未运行

时间:2019-05-23 12:39:31

标签: node.js memory-management garbage-collection out-of-memory

使用node.exe运行服务器时,node.exe的GC未运行。但是,在安装了节点js的服务器上运行时,GC会正常运行。我得到

<--- Last few GCs --->

[4784:0000019E4B6BC630] 1216762 ms: Mark-sweep 1394.7 (1426.4) -> 1394.5 (1426.4) MB, 1840.3 / 0.0 ms (average mu = 0.060, current mu = 0.008) allocation failure scavenge might not succeed
[4784:0000019E4B6BC630] 1219409 ms: Mark-sweep 1395.4 (1426.4) -> 1395.1 (1426.9) MB, 2644.5 / 0.0 ms (average mu = 0.022, current mu = 0.001) allocation failure scavenge might not succeed

<--- JS stacktrace --->

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

一段时间后

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF6C9B625FA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4810
2: 00007FF6C9B07AA6 uv_loop_fork+80918
3: 00007FF6C9B08680 uv_loop_fork+83952
4: 00007FF6C9F8A7FE v8::internal::FatalProcessOutOfMemory+798
5: 00007FF6C9F8A737 v8::internal::FatalProcessOutOfMemory+599
6: 00007FF6CA263954 v8::internal::Heap::RootIsImmortalImmovable+14788
7: 00007FF6CA259594 v8::internal::Heap::CollectGarbage+7556
8: 00007FF6CA257C68 v8::internal::Heap::CollectGarbage+1112

我们有一个Windows节点和Express服务器。我们正在使用node.exe将其部署到最终用户。因此,最终用户无需安装节点js就可以简单地运行node.exe ./core/bin/www %hostname%。但是在这堆中不断增加。如果我们在安装了node js的情况下运行相同的程序,则GC将正常运行,并定期清理内存。我已经尝试过--expose-gc并强制清理GC

使用node.exe 内存增加如下

17:14:00.079 INFO  rss 223.87 MB 
17:14:00.079 INFO  heapTotal 152.8 MB 
17:14:00.079 INFO  heapUsed 57.8 MB 
17:14:00.079 INFO  external 69.04 MB 
17:14:00.079 INFO  ------------------------------------------------------------------------ 
17:16:00.021 INFO  
cleaningGC

17:16:00.150 INFO  rss 284.96 MB 
17:16:00.150 INFO  heapTotal 244.8 MB 
17:16:00.150 INFO  heapUsed 95.87 MB 
17:16:00.150 INFO  external 68.76 MB 
17:16:00.150 INFO  ------------------------------------------------------------------------ 
17:18:00.014 INFO  
cleaningGC

17:18:00.186 INFO  rss 412.16 MB 
17:18:00.186 INFO  heapTotal 326.4 MB 
17:18:00.186 INFO  heapUsed 129.88 MB 
17:18:00.186 INFO  external 68.91 MB 
17:18:00.186 INFO  ------------------------------------------------------------------------ 
17:20:00.001 INFO  
cleaningGC

17:20:00.136 INFO  rss 426.95 MB 
17:20:00.136 INFO  heapTotal 340.9 MB 
17:20:00.136 INFO  heapUsed 160.67 MB 
17:20:00.136 INFO  external 68.73 MB 
17:20:00.136 INFO  ------------------------------------------------------------------------ 
17:22:00.004 INFO  
cleaningGC

17:22:00.230 INFO  rss 582.23 MB 
17:22:00.230 INFO  heapTotal 431.19 MB 
17:22:00.230 INFO  heapUsed 192.28 MB 
17:22:00.230 INFO  external 69.48 MB 
17:22:00.230 INFO  ------------------------------------------------------------------------ 
17:24:00.019 INFO  
cleaningGC

17:24:00.203 INFO  rss 471.99 MB 
17:24:00.203 INFO  heapTotal 428.19 MB 
17:24:00.203 INFO  heapUsed 223.51 MB 
17:24:00.203 INFO  external 68.56 MB 
17:24:00.203 INFO  ------------------------------------------------------------------------ 
17:26:00.005 INFO  
cleaningGC

17:26:00.256 INFO  rss 515.55 MB 
17:26:00.256 INFO  heapTotal 471.63 MB 
17:26:00.256 INFO  heapUsed 255 MB 
17:26:00.256 INFO  external 68.61 MB 
17:26:00.256 INFO  ------------------------------------------------------------------------ 
17:28:00.007 INFO  
cleaningGC

17:28:00.307 INFO  rss 604.43 MB 
17:28:00.307 INFO  heapTotal 496.63 MB 
17:28:00.307 INFO  heapUsed 286.41 MB 
17:28:00.307 INFO  external 68.82 MB 
17:28:00.307 INFO  ------------------------------------------------------------------------ 
17:30:00.005 INFO  
cleaningGC

17:30:00.338 INFO  rss 643.66 MB 
17:30:00.338 INFO  heapTotal 543.78 MB 
17:30:00.338 INFO  heapUsed 318.19 MB 
17:30:00.338 INFO  external 68.8 MB 
17:30:00.338 INFO  ------------------------------------------------------------------------ 
17:32:00.019 INFO  
cleaningGC

17:32:00.376 INFO  rss 687 MB 
17:32:00.376 INFO  heapTotal 589.78 MB 
17:32:00.376 INFO  heapUsed 349.49 MB 
17:32:00.376 INFO  external 68.78 MB 
17:32:00.376 INFO  ------------------------------------------------------------------------ 
17:34:00.004 INFO  
cleaningGC

17:34:00.387 INFO  rss 680.7 MB 
17:34:00.387 INFO  heapTotal 636.28 MB 
17:34:00.387 INFO  heapUsed 380.73 MB 
17:34:00.387 INFO  external 68.74 MB 
17:34:00.387 INFO  ------------------------------------------------------------------------ 
17:36:00.002 INFO  
cleaningGC

17:36:00.462 INFO  rss 749.16 MB 
17:36:00.462 INFO  heapTotal 689.28 MB 
17:36:00.462 INFO  heapUsed 411.89 MB 
17:36:00.462 INFO  external 68.71 MB 
17:36:00.462 INFO  ------------------------------------------------------------------------ 
17:38:00.004 INFO  
cleaningGC

17:38:00.454 INFO  rss 796.45 MB 
17:38:00.454 INFO  heapTotal 718.28 MB 
17:38:00.454 INFO  heapUsed 443.08 MB 
17:38:00.454 INFO  external 69.25 MB 
17:38:00.454 INFO  ------------------------------------------------------------------------ 
17:40:00.016 INFO  
cleaningGC

17:40:00.487 INFO  rss 838.95 MB 
17:40:00.487 INFO  heapTotal 776.76 MB 
17:40:00.487 INFO  heapUsed 475.28 MB 
17:40:00.487 INFO  external 68.63 MB 
17:40:00.487 INFO  ------------------------------------------------------------------------ 
17:42:00.003 INFO  
cleaningGC

17:42:00.476 INFO  rss 895.23 MB 
17:42:00.476 INFO  heapTotal 809.26 MB 
17:42:00.476 INFO  heapUsed 506.29 MB 
17:42:00.476 INFO  external 68.62 MB 
17:42:00.476 INFO  ------------------------------------------------------------------------ 
17:44:00.017 INFO  
cleaningGC

17:44:00.406 INFO  rss 904.31 MB 
17:44:00.406 INFO  heapTotal 830.26 MB 
17:44:00.406 INFO  heapUsed 537.07 MB 
17:44:00.406 INFO  external 68.54 MB 
17:44:00.406 INFO  ------------------------------------------------------------------------ 
17:46:00.005 INFO  
cleaningGC

17:46:00.410 INFO  rss 933.79 MB 
17:46:00.410 INFO  heapTotal 859.26 MB 
17:46:00.410 INFO  heapUsed 568.46 MB 
17:46:00.410 INFO  external 68.54 MB 
17:46:00.410 INFO  ------------------------------------------------------------------------ 
17:48:00.005 INFO  
cleaningGC

17:48:00.581 INFO  rss 952.95 MB 
17:48:00.581 INFO  heapTotal 880.76 MB 
17:48:00.581 INFO  heapUsed 600.24 MB 
17:48:00.581 INFO  external 68.67 MB 
17:48:00.581 INFO  ------------------------------------------------------------------------ 
17:50:00.008 INFO  
cleaningGC

17:50:00.525 INFO  rss 966.46 MB 
17:50:00.525 INFO  heapTotal 902.76 MB 
17:50:00.525 INFO  heapUsed 631.18 MB 
17:50:00.525 INFO  external 68.64 MB 
17:50:00.525 INFO  ------------------------------------------------------------------------ 
17:52:00.008 INFO  
cleaningGC

17:52:00.592 INFO  rss 986.26 MB 
17:52:00.592 INFO  heapTotal 935.24 MB 
17:52:00.592 INFO  heapUsed 664.11 MB 
17:52:00.592 INFO  external 68.61 MB 
17:52:00.592 INFO  ------------------------------------------------------------------------ 
17:54:00.007 INFO  
cleaningGC

17:54:00.554 INFO  rss 1023.01 MB 
17:54:00.554 INFO  heapTotal 971.74 MB 
17:54:00.554 INFO  heapUsed 695.08 MB 
17:54:00.554 INFO  external 68.58 MB 
17:54:00.554 INFO  ------------------------------------------------------------------------ 
17:56:00.026 INFO  
cleaningGC

17:56:00.610 INFO  rss 1058.05 MB 
17:56:00.610 INFO  heapTotal 983.74 MB 
17:56:00.610 INFO  heapUsed 726.55 MB 
17:56:00.610 INFO  external 68.56 MB 

使用节点.js

内存保持恒定〜250MB

启动命令为node.exe ./core/bin/www %hostname%

我该如何解决这个问题 我尝试过

--expose-gc
require('expose-gc');
   if (global.gc) { global.gc(); }
            var used = process.memoryUsage();
            for (var key in used) {
                console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
            }

0 个答案:

没有答案