@@ -39,7 +39,7 @@ setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
3939[23521:0x10268b000] 120 ms: Mark-sweep 100.7 (122.7) -> 100.6 (122.7) MB, 0.15 / 0.0 ms (average mu = 0.132, current mu = 0.137) deserialize GC in old space requested
4040```
4141
42- 这里给出如何解析这些信息(以第二行数据举例) :
42+ 以上面第二行数据举例, 这里给出如何解析这些信息:
4343
4444<table >
4545 <tr >
@@ -48,7 +48,7 @@ setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
4848 </tr >
4949 <tr >
5050 <td>23521</td>
51- <td>正在运行的进程号 </td>
51+ <td>正在运行的线程号 </td>
5252 </tr >
5353 <tr >
5454 <td>0x10268db0</td>
@@ -64,25 +64,32 @@ setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
6464 </tr >
6565 <tr >
6666 <td>100.7</td>
67- <td>GC 运行前占有内存(MB )</td>
67+ <td>GC 运行前占有内存(MiB )</td>
6868 </tr >
6969 <tr >
7070 <td>122.7</td>
71- <td>GC 运行前总占有内存(MB )</td>
71+ <td>GC 运行前总占有内存(MiB )</td>
7272 </tr >
7373 <tr >
7474 <td>100.6</td>
75- <td>GC 运行后占有内存(MB )</td>
75+ <td>GC 运行后占有内存(MiB )</td>
7676 </tr >
7777 <tr >
7878 <td>122.7</td>
79- <td>GC 运行后总占有内存(MB )</td>
79+ <td>GC 运行后总占有内存(MiB )</td>
8080 </tr >
8181 <tr >
82- <td>0.15 / 0.0 <br/>
83- (average mu = 0.132, current mu = 0.137)</td>
82+ <td>0.15</td>
8483 <td>GC 所耗费时间(毫秒)</td>
8584 </tr >
85+ <tr >
86+ <td>0.0</td>
87+ <td>GC 垃圾回收回调所话费的时间(毫秒)</td>
88+ </tr >
89+ <tr >
90+ <td>(average mu = 0.132, current mu = 0.137)</td>
91+ <td>增变因子利用率(0 —— 1 之间)</td>
92+ </tr >
8693 <tr >
8794 <td>deserialize GC in old space requested</td>
8895 <td>GC 原因</td>
@@ -100,8 +107,8 @@ const { PerformanceObserver } = require('perf_hooks');
100107const obs = new PerformanceObserver ((list ) => {
101108 const entry = list .getEntries ()[0 ];
102109 /*
103- The entry would be an instance of PerformanceEntry containing
104- metrics of garbage collection.
110+ The entry is an instance of PerformanceEntry containing
111+ metrics of a single garbage collection event .
105112 For example:
106113 PerformanceEntry {
107114 name: 'gc',
@@ -113,7 +120,7 @@ const obs = new PerformanceObserver((list) => {
113120 */
114121});
115122
116- // Subscribe notifications of GCs
123+ // Subscribe to notifications of GCs
117124obs .observe ({ entryTypes: [' gc' ] });
118125
119126// Stop subscription
@@ -175,15 +182,15 @@ A. 如何获取糟糕的内存分配的上下文信息?
1751821 . 假定我们观察到旧内存持续增长。
1761832 . 但根据 GC 的负重来看,堆的最大值并未达到,但进程慢。
1771843 . 回看跟踪的数据,找出在 GC 前后总的堆占用量。
178- 4 . 使用 ` --max-old-space-size ` 降低内存,使得总的内存堆更接近于极限值。
179- 5 . 再次运行程序,达到内存耗尽 。
185+ 4 . 使用 [ ` --max-old-space-size ` ] [ ] 降低内存,使得总的内存堆更接近于极限值。
186+ 5 . 再次不断地运行程序,直到内存耗尽 。
1801876 . 该过程的日志将显示失败的上下文信息。
181188
182189B. 如何确定在堆增长之时,存在内存泄露现象?
1831901 . 假定我们观察到旧内存持续增长。
1841912 . 但根据 GC 的负重来看,堆的最大值并未达到,但进程慢。
1851923 . 回看跟踪的数据,找出在 GC 前后总的堆占用量。
186- 4 . 使用 ` --max-old-space-size ` 降低内存,使得总的内存堆更接近于极限值。
193+ 4 . 使用 [ ` --max-old-space-size ` ] [ ] 降低内存,使得总的内存堆更接近于极限值。
1871945 . 再次运行程序,观察是否内存耗尽。
1881956 . 如果发生内存耗尽,尝试每次提升 10% 的堆内存,反复数次。
189196如果之前的现象复现被观察到,这就能证明存在内存泄露。
@@ -196,6 +203,7 @@ C. 如何断定是否存在太多次的垃圾回收,或者因为太多次垃
1962034 . 如果两次 GC 间隙时间和所话费的时间都非常高,证明该程序应该用一个更小点的堆。
1972045 . 如果两次 GC 的时间远大于 GC 运行的时间,应用程序则相对比较健康。
198205
199- [ performance hooks ] : https://nodejs.org/api/perf_hooks.html
200206[ PerformanceEntry ] : https://nodejs.org/api/perf_hooks.html#perf_hooks_class_performanceentry
201207[ PerformanceObserver ] : https://nodejs.org/api/perf_hooks.html#perf_hooks_class_performanceobserver
208+ [ `--max-old-space-size` ] : https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes
209+ [ performance hooks ] : https://nodejs.org/api/perf_hooks.html
0 commit comments