node-oom-heapdump 2.1.0-progress.1 → 3.0.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -1,3 +1,3 @@
1
- module.exports = {
2
- "extends": "google"
1
+ module.exports = {
2
+ "extends": "google"
3
3
  };
package/.travis.yml CHANGED
@@ -1,9 +1,13 @@
1
- language: node_js
2
- node_js:
3
- - "7"
4
- - "8"
5
- - "9"
6
- - "10"
7
- - "11"
8
- - "12"
9
- script: npm run dummy
1
+ language: node_js
2
+ node_js:
3
+ - "7"
4
+ - "8"
5
+ - "9"
6
+ - "10"
7
+ - "11"
8
+ - "12"
9
+ - "13"
10
+ - "14"
11
+ - "15"
12
+ - "16"
13
+ script: npm run dummy
package/CHANGELOG.md CHANGED
@@ -1,84 +1,107 @@
1
- 20-07-2020 Paul Rütter
2
- - 2.0
3
- - Added prebuilt binaries again, in a new major version. To "solve" https://github.com/blueconic/node-oom-heapdump/issues/13.
4
-
5
- 20-07-2020 Paul Rütter
6
- - 1.3.1
7
- - Revert prebuilt binaries, since it's a breaking change.
8
-
9
- 24-06-2020 Stuart Miller / Paul Rütter
10
- - 1.3.0
11
- - Stuart Miller added support for having prebuilt binaries for all supported Node.js versions.
12
-
13
- 16-10-2019 Paul Rütter
14
- - 1.2.0
15
- - Node 12 support.
16
- - Still some deprecated API's are used, which should be avoided.
17
- See https://github.com/joyeecheung/node/blob/v8-maybe-doc/CPP_STYLE_GUIDE.md#use-maybe-version-of-v8-apis
18
- - Adjusted test script a bit, by removing some flags which seem to complicate nodejs 12 support.
19
-
20
- 02-09-2019 Paul Rütter
21
- - 1.2.0-beta.0
22
- - Updated dependencies (nan update is needed for nodejs 12)
23
- - Add nodejs 12 to travis
24
- - Add experimental node 12 support. Still some deprecated API's are used, which should be avoided.
25
- See https://github.com/joyeecheung/node/blob/v8-maybe-doc/CPP_STYLE_GUIDE.md#use-maybe-version-of-v8-apis
26
-
27
- 02-01-2019 Paul Rütter
28
- - 1.1.4
29
- - Updated dependencies
30
- - Add travis file to trigger a build. Just run a dummy script which does nothing; the default "npm install" will check if the native module compiles.
31
-
32
- 09-06-2018 Paul Rütter
33
- - 1.1.3 - Updated dependencies, to mitigate security issues.
34
-
35
- 02-20-2018 Paul Rütter
36
- - 1.1.2 - Fixed heapdump generation on Unix machines.
37
- - Added option to use the "old" implementation (GCmonitoring), as the new implementatuion is more prone to run in with the OoM killer when in memory restricted environments (like Docker). The old implementation was less impacted by this, because the "threshold" parameter can be used to create the heapdump earlier.
38
- You can specify which OoM implementation to use, either: "NATIVE_HOOK" (default) or "GC_MONITORING" (old implementation).
39
-
40
- 02-19-2018 Paul Rütter
41
- - 1.1.0 - Changed the way the "out of memory" heapdump is created, based on the work of 'trevnorris' (https://github.com/trevnorris/node-ofe/blob/master/ofe.cc). Using V8 engine isolate.SetOOMErrorHandler() to hook in on the out of memory event.
42
- - Updated readme and removed deprecated 'limit' and 'threshold' parameters.
43
- - Removed 'gc-stats' module, as we no longer need it with the native C++ add-on.
44
-
45
- 02-13-2018 - Paul Rütter
46
- - 1.0.12 - Use 'require-main-filename' instead of require.main.filename, to resolve 'https://github.com/blueconic/node-oom-heapdump/issues/3'.
47
- - Upgrade dependencies
48
-
49
- 11-21-2017 - Paul Rütter
50
- - 1.0.11 - Added port verification; when the module is loaded, the configured WebSocket port is verified. If the websocket responds with ECONNREFUSED, the process might have been started without the --inspect flag.
51
-
52
- 11-17-2017 - Paul Rütter
53
- - 1.0.10 - Use gc-stats to calculate when to make a OoM heapdumo instead of process.memoryUsage() as this memory information (heapTotal) is growing over time, which is not expected.
54
- - Stringify gc-stats output, so it runs over only 1 line.
55
-
56
- 06-10-2017 - Paul Rütter
57
- - 1.0.9 - Handle exit codes better and reject promise if so.
58
-
59
- 05-10-2017 - Paul Rütter
60
- - 1.0.8 - Add CPU profile functionality.
61
-
62
- 04-10-2017 - Paul Rütter
63
- - 1.0.7 - Add addTimestamp option.
64
-
65
- 04-10-2017 - Paul Rütter
66
- - 1.0.6 - Add limit option.
67
-
68
- 03-10-2017 - Paul Rütter
69
- - 1.0.5 - Change heap calculation.
70
-
71
- 03-10-2017 - Paul Rütter
72
- - 1.0.4 - Add error handler in case the calling process is not running anymore. Also, block execution a while to allow heapdump to be created.
73
-
74
- 01-10-2017 - Paul Rütter
75
- - 1.0.3 - Minor doc changes.
76
-
77
- 01-10-2017 - Paul Rütter
78
- - 1.0.2 - Refactored code; split up API and implementation. Also added API for creating heapdumps on the fly. Documentation updated.
79
-
80
- 29-09-2017 - Paul Rütter
81
- - 1.0.1 - minor changed
82
-
83
- 29-09-2017 - Paul Rütter
84
- - 1.0.1 - initial version
1
+ 09-02-2022 Paul Rütter
2
+ - 3.0.0
3
+ - Updated dependencies to resolve https://github.com/blueconic/node-oom-heapdump/issues/19
4
+ - Removed `gc-stats` as it was not used a lot anymore (breaking change) and contained security issues.
5
+ - Removed creating heapdumps on out of memory, as this is superseeded by native node functionality.
6
+ - Remove unused dependencies and native code.
7
+
8
+ 21-12-2020 Paul Rütter
9
+ - 2.2.0
10
+ - Updated ini
11
+
12
+ 12-10-2020 Paul Rütter
13
+ - 2.1.0
14
+ - Added Node 14 support
15
+
16
+ 12-10-2020 Paul Rütter
17
+ - 2.0.2
18
+ - Fix latest published version, was replaced with beta.
19
+
20
+ 02-08-2020 Paul Rütter
21
+ - 2.0.1
22
+ - Fixed prebuilt binaries path.
23
+
24
+ 20-07-2020 Paul Rütter
25
+ - 2.0
26
+ - Added prebuilt binaries again, in a new major version. To "solve" https://github.com/blueconic/node-oom-heapdump/issues/13.
27
+
28
+ 20-07-2020 Paul Rütter
29
+ - 1.3.1
30
+ - Revert prebuilt binaries, since it's a breaking change.
31
+
32
+ 24-06-2020 Stuart Miller / Paul Rütter
33
+ - 1.3.0
34
+ - Stuart Miller added support for having prebuilt binaries for all supported Node.js versions.
35
+
36
+ 16-10-2019 Paul Rütter
37
+ - 1.2.0
38
+ - Node 12 support.
39
+ - Still some deprecated API's are used, which should be avoided.
40
+ See https://github.com/joyeecheung/node/blob/v8-maybe-doc/CPP_STYLE_GUIDE.md#use-maybe-version-of-v8-apis
41
+ - Adjusted test script a bit, by removing some flags which seem to complicate nodejs 12 support.
42
+
43
+ 02-09-2019 Paul Rütter
44
+ - 1.2.0-beta.0
45
+ - Updated dependencies (nan update is needed for nodejs 12)
46
+ - Add nodejs 12 to travis
47
+ - Add experimental node 12 support. Still some deprecated API's are used, which should be avoided.
48
+ See https://github.com/joyeecheung/node/blob/v8-maybe-doc/CPP_STYLE_GUIDE.md#use-maybe-version-of-v8-apis
49
+
50
+ 02-01-2019 Paul Rütter
51
+ - 1.1.4
52
+ - Updated dependencies
53
+ - Add travis file to trigger a build. Just run a dummy script which does nothing; the default "npm install" will check if the native module compiles.
54
+
55
+ 09-06-2018 Paul Rütter
56
+ - 1.1.3 - Updated dependencies, to mitigate security issues.
57
+
58
+ 02-20-2018 Paul Rütter
59
+ - 1.1.2 - Fixed heapdump generation on Unix machines.
60
+ - Added option to use the "old" implementation (GCmonitoring), as the new implementatuion is more prone to run in with the OoM killer when in memory restricted environments (like Docker). The old implementation was less impacted by this, because the "threshold" parameter can be used to create the heapdump earlier.
61
+ You can specify which OoM implementation to use, either: "NATIVE_HOOK" (default) or "GC_MONITORING" (old implementation).
62
+
63
+ 02-19-2018 Paul Rütter
64
+ - 1.1.0 - Changed the way the "out of memory" heapdump is created, based on the work of 'trevnorris' (https://github.com/trevnorris/node-ofe/blob/master/ofe.cc). Using V8 engine isolate.SetOOMErrorHandler() to hook in on the out of memory event.
65
+ - Updated readme and removed deprecated 'limit' and 'threshold' parameters.
66
+ - Removed 'gc-stats' module, as we no longer need it with the native C++ add-on.
67
+
68
+ 02-13-2018 - Paul Rütter
69
+ - 1.0.12 - Use 'require-main-filename' instead of require.main.filename, to resolve 'https://github.com/blueconic/node-oom-heapdump/issues/3'.
70
+ - Upgrade dependencies
71
+
72
+ 11-21-2017 - Paul Rütter
73
+ - 1.0.11 - Added port verification; when the module is loaded, the configured WebSocket port is verified. If the websocket responds with ECONNREFUSED, the process might have been started without the --inspect flag.
74
+
75
+ 11-17-2017 - Paul Rütter
76
+ - 1.0.10 - Use gc-stats to calculate when to make a OoM heapdumo instead of process.memoryUsage() as this memory information (heapTotal) is growing over time, which is not expected.
77
+ - Stringify gc-stats output, so it runs over only 1 line.
78
+
79
+ 06-10-2017 - Paul Rütter
80
+ - 1.0.9 - Handle exit codes better and reject promise if so.
81
+
82
+ 05-10-2017 - Paul Rütter
83
+ - 1.0.8 - Add CPU profile functionality.
84
+
85
+ 04-10-2017 - Paul Rütter
86
+ - 1.0.7 - Add addTimestamp option.
87
+
88
+ 04-10-2017 - Paul Rütter
89
+ - 1.0.6 - Add limit option.
90
+
91
+ 03-10-2017 - Paul Rütter
92
+ - 1.0.5 - Change heap calculation.
93
+
94
+ 03-10-2017 - Paul Rütter
95
+ - 1.0.4 - Add error handler in case the calling process is not running anymore. Also, block execution a while to allow heapdump to be created.
96
+
97
+ 01-10-2017 - Paul Rütter
98
+ - 1.0.3 - Minor doc changes.
99
+
100
+ 01-10-2017 - Paul Rütter
101
+ - 1.0.2 - Refactored code; split up API and implementation. Also added API for creating heapdumps on the fly. Documentation updated.
102
+
103
+ 29-09-2017 - Paul Rütter
104
+ - 1.0.1 - minor changed
105
+
106
+ 29-09-2017 - Paul Rütter
107
+ - 1.0.1 - initial version
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 BlueConic
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2017 BlueConic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,143 +1,129 @@
1
- [![TravisCI Build Status](https://travis-ci.org/blueconic/node-oom-heapdump.svg?branch=master)](https://travis-ci.org/blueconic/node-oom-heapdump)
2
-
3
- # node-oom-heapdump
4
- Node module which will create a V8 heap snapshot right before an "Out of Memory" error occurs.
5
-
6
- It can also create heapdumps and CPU profiles on request like 'v8-profiler', but does this off-process so it doesn't interfere with execution of the main process.
7
-
8
- Tested on Node.js 7.x, 8.x, 9.x, 10.x, 11.x and 12.x.
9
- No support for Node.js < 7.0 at the moment (although this can be fixed if needed).
10
-
11
- Also comes with prebuilt binaries (hosted on Github releases), thanks to Stuart Miller (https://github.com/spmiller).
12
-
13
- # Why?
14
- When running nodejs processes in a low memory environment, every out of memory that occurs is interesting.
15
- To figure out why a process went out of memory, a heap snapshot (e.g. heapdump) can help a lot.
16
- This module creates a heap snapshot right before an out of memory error occurs (by leveraging 'SetOOMErrorHandler' of the V8 engine).
17
- It shows what the heap was filled with right before the out of memory error occured and can be opened with Chrome DevTools (Memory tab).
18
-
19
- There are several modules around which can create heapdumps (v8-profiler, node-heapdump), but these run in the same process as the one going out of memory. Often, creating heapdump won't work when the node process is already struggling.
20
- This module creates the heap snapshot from a separate process, which solves this issue.
21
- Also, these modules are not able to create a heapdump when an out of memory occurs.
22
-
23
- # What?
24
- Based on the work of 'trevnorris' (https://github.com/trevnorris/node-ofe/), this module uses 'isolate.SetOOMErrorHandler' (https://v8docs.nodesource.com/node-8.9/d5/dda/classv8_1_1_isolate.html#a08fd4087f39c33b4ac1c20ad953ce4e3) of the V8 engine, and then creates a heapdump when an actual Out of Memory occurs. To make this happen, a native C++ add-on is used.
25
- Node-gyp is needed to compile this add-on.
26
-
27
- When creating a heapdump of CPU profile on request, the DevTools protocol is used to create these files (no native add-on).
28
- The --inspect node.js flag is needed to make this work (which is validated on startup).
29
-
30
- # Example
31
- Just run "npm test" to see it in action. It creates a heapdump named "my_heapdump.heapsnapshot" in the 'tests' directory of this module.
32
-
33
- # Usage
34
-
35
- ```javascript
36
- npm install node-oom-heapdump
37
- ```
38
-
39
- Just add the following snippet to your node process.
40
-
41
- ```javascript
42
- let path = require('path');
43
- require('node-oom-heapdump')({
44
- path: path.resolve(__dirname, 'my_heapdump')
45
- });
46
- ```
47
-
48
- To make heapdumps and CPU profiles on request, your node process should at least be started with the "--inspect" (or --inspect=port) flag. When the module is loaded, the configured port is verified. If it doesn't respond correctly, a console warning will be shown.
49
-
50
- When running in a low memory environment, the following flags are advised:
51
-
52
- * --max_old_space_size=60 - this will limit your heapsize on 60MB
53
- * --optimize_for_size - keep memory as low as possible (GC more often than usual)
54
- * --always_compact - keep memory as low as possible (do compactions each GC)
55
-
56
- These might impact performance though.
57
- On Node.js 12.x the latter two flags seem to cause some stability issues (see https://github.com/nodejs/node/issues/27552#issuecomment-542695931). So, if you encounter issues on Node.js 12.x in combination with those flags, please refrain from using these.
58
-
59
- # Options
60
- * heapdumpOnOOM - boolean whether to create a heapdump when an out of memory occurs. Default true.
61
- * OOMImplementation - Either "NATIVE_HOOK" or "GC_MONITORING".
62
- "NATIVE_HOOK" relies on the native v8 hook and makes sure that the heapdump is actually created when the OoM occurs. It's more impacted by the OoMKiller of Unix systems though, when being run in memory restricted environments like Docker.
63
- "GC_MONITORING" is the old implementation, which relies on GC monitoring. It's less impacted by OoMKiller, because the 'threshold' parameter determines when to create the heapdump. Use this option when you run into the OoMKiller of the Unix OS. Default is "NATIVE_HOOK".
64
- * path - the path where the heapdump ends up when an out of memory error occurs. '.heapsnapshot' is automatically appended. Defaults to this modules' directory.
65
- * addTimestamp - add a timestamp to the out of memory heapdump filename, to make it unique. Default is false.
66
- * port - optionally, the alternative DevTools protocol port. Defaults to 9229. Should map on the port given to the --inspect arg.
67
-
68
- The following options are only relevant when OOMImplementation="GC_MONITORING".
69
- * limit - optionally, specify a limit to how many heapdumps will be created when being above the threshold. Default is 3.
70
- * threshold - integer between 0 and 100 (%) which determines when to make the heapdump. When the used heapSize exceeds the threshold, a heapdump is made. This value can be tuned depending on your configuration; if memory usage is very volatile, a lower value might make more sense. Default is 70.
71
-
72
- # API
73
- Besides creating heapdumps when an out of memory error occurs, there also is an API for creating heapdumps and CPU profiles on request. See below for the currently available API.
74
-
75
- Notice that you cannot create a heapdump while a CPU profile is being generated and vice versa; an Error will be thrown if this is the case.
76
-
77
- ```javascript
78
- let nodeOomHeapdump = require("node-oom-heapdump")({
79
- heapdumpOnOOM: false
80
- });
81
-
82
- /**
83
- * Returns the path to the created heap snapshot in a promise, or rejects on error
84
- * @param {String} snapshotPath - path of the snapshot
85
- * @return {Promise} Promise containing the heap snapshot path on success or error on rejection
86
- */
87
- nodeOomHeapdump.createHeapSnapshot("myheapsnapshotpath").then((snapshotPath) => {
88
- // do something with heap snapshot
89
-
90
- // and delete again from disk
91
- nodeOomHeapdump.deleteHeapSnapshot(snapshotPath);
92
- }).catch((err) => {
93
- // handle error
94
- });
95
-
96
- /**
97
- * Deletes all previously created heapsnapshots from disk
98
- */
99
- nodeOomHeapdump.deleteAllHeapSnapshots();
100
-
101
- /**
102
- * Deletes a particular snapshot from disk
103
- * @param {String} snapshotPath - path of the heap snapshot to delete
104
- * @return {Promise}
105
- */
106
- nodeOomHeapdump.deleteHeapSnapshot(snapshotPath);
107
-
108
- /**
109
- * Returns the path to the created CPU profile in a promise, or rejects on error
110
- * @param {String} cpuProfilePath - path of the CPU profile
111
- * @param {number} duration - the duration of the CPU profile in ms (default: 30000ms)
112
- * @return {Promise} the CPU profile path on success or error on rejection
113
- */
114
- nodeOomHeapdump.createCpuProfile("mycpuprofilepath", 10000).then((cpuProfilePath) => {
115
- // do something with CPU profile
116
-
117
- // and delete again from disk
118
- nodeOomHeapdump.deleteCpuProfile(cpuProfilePath);
119
- }).catch((err) => {
120
- // handle error
121
- });
122
-
123
- /**
124
- * Deletes all previously created CPU profiles from disk
125
- */
126
- nodeOomHeapdump.deleteAllCpuProfiles();
127
-
128
- /**
129
- * Deletes a particular CPU profile from disk
130
- * @param {String} cpuProfilePath - path to the CPU profile to delete from disk
131
- * @return {Promise}
132
- */
133
- nodeOomHeapdump.deleteCpuProfile(cpuProfilePath);
134
- ```
135
-
136
- # Known issues and limitations
137
-
138
- ## Memory usage
139
- When creating a heapdump on request, it's notorious for using a lot of memory. This is caused by a bug in V8/DevTools protocol and is reported here (https://bugs.chromium.org/p/chromium/issues/detail?id=768355); the protocol has no backpressure mechanism, which causes the heapdump to be pushed faster than the DevTools client can handle, causing in-memory buffering.
140
-
141
- This is not a problem if your server/machine has memory to spare, but can cause issues in memory restricted environments like a Docker container. Once the process exceeds the container memory threshold, it will be killed by OoMKiller (if enabled). This leads to an empty heapsnapshot file (0 bytes).
142
-
143
- Please vote for that issue to be fixed!
1
+ [![TravisCI Build Status](https://travis-ci.org/blueconic/node-oom-heapdump.svg?branch=master)](https://travis-ci.org/blueconic/node-oom-heapdump)
2
+
3
+ # node-oom-heapdump
4
+ Node module that can create heapdumps and CPU profiles on request like 'v8-profiler', but does this off-process so it doesn't interfere with execution of the main process.
5
+
6
+ Tested on Node.js 7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x and 16.x.
7
+ No support for Node.js < 7.0 at the moment (although this can be fixed if needed).
8
+
9
+ Also comes with prebuilt binaries (hosted on Github releases), thanks to Stuart Miller (https://github.com/spmiller).
10
+
11
+ ## Node.js 14.18.x and higher
12
+ https://github.com/nodejs/node/pull/33010 landed in Node.js 14.18.0, which makes this module no longer needed for heapdumps on out of memory.
13
+ One can use the `--heapsnapshot-near-heap-limit` Node.js CLI option as an native alternative.
14
+ See https://nodejs.org/dist/latest-v14.x/docs/api/cli.html#cli_heapsnapshot_near_heap_limit_max_count.
15
+
16
+ For Node versions older than 14, use the `2.2.0` release, where this functionality is still present (not maintained anymore).
17
+ For Node versions 14 and up, use `--heapsnapshot-near-heap-limit` for out-of-memory heapdumps. This functionality has been removed from `3.0.0`.
18
+
19
+ One can still use the API of this module to create CPU profiles and heapdumps on request
20
+
21
+ # Why?
22
+ There are several modules around which can create heapdumps (v8-profiler, node-heapdump), although this module creates the heap snapshot from a separate process which performs better and doesn't affect the main event loop.
23
+
24
+ # What?
25
+ When creating a heapdump of CPU profile on request, the DevTools protocol is used to create these files (no native add-on needed).
26
+ The --inspect node.js flag is needed to make this work (which is validated on startup).
27
+
28
+ # Usage
29
+
30
+ ```javascript
31
+ npm install node-oom-heapdump
32
+ ```
33
+
34
+ Just add the following snippet to your node process.
35
+
36
+ ```javascript
37
+ let path = require('path');
38
+ require('node-oom-heapdump')({
39
+ path: path.resolve(__dirname, 'my_heapdump')
40
+ });
41
+ ```
42
+
43
+ To make heapdumps and CPU profiles on request, your node process should at least be started with the "--inspect" (or --inspect=port) flag. When the module is loaded, the configured port is verified. If it doesn't respond correctly, a console warning will be shown.
44
+
45
+ When running in a low memory environment, the following flags are advised:
46
+
47
+ * --max_old_space_size=60 - this will limit your heapsize on 60MB
48
+ * --optimize_for_size - keep memory as low as possible (GC more often than usual)
49
+ * --always_compact - keep memory as low as possible (do compactions each GC)
50
+
51
+ These might impact performance though.
52
+ On Node.js 12.x the latter two flags seem to cause some stability issues (see https://github.com/nodejs/node/issues/27552#issuecomment-542695931). So, if you encounter issues on Node.js 12.x in combination with those flags, please refrain from using these.
53
+
54
+ # Options
55
+ * addTimestamp - add a timestamp to the heapdump filename, to make it unique. Default is false.
56
+ * port - optionally, the alternative DevTools protocol port. Defaults to 9229. Should map on the port given to the --inspect arg.
57
+
58
+ # API
59
+ The API for creating heapdumps and CPU profiles on request. See below for the currently available API.
60
+
61
+ Notice that you cannot create a heapdump while a CPU profile is being generated and vice versa; an Error will be thrown if this is the case.
62
+
63
+ ```javascript
64
+ let nodeOomHeapdump = require("node-oom-heapdump")({
65
+ heapdumpOnOOM: false
66
+ });
67
+
68
+ /**
69
+ * Returns the path to the created heap snapshot in a promise, or rejects on error
70
+ * @param {String} snapshotPath - path of the snapshot
71
+ * @return {Promise} Promise containing the heap snapshot path on success or error on rejection
72
+ */
73
+ nodeOomHeapdump.createHeapSnapshot("myheapsnapshotpath").then((snapshotPath) => {
74
+ // do something with heap snapshot
75
+
76
+ // and delete again from disk
77
+ nodeOomHeapdump.deleteHeapSnapshot(snapshotPath);
78
+ }).catch((err) => {
79
+ // handle error
80
+ });
81
+
82
+ /**
83
+ * Deletes all previously created heapsnapshots from disk
84
+ */
85
+ nodeOomHeapdump.deleteAllHeapSnapshots();
86
+
87
+ /**
88
+ * Deletes a particular snapshot from disk
89
+ * @param {String} snapshotPath - path of the heap snapshot to delete
90
+ * @return {Promise}
91
+ */
92
+ nodeOomHeapdump.deleteHeapSnapshot(snapshotPath);
93
+
94
+ /**
95
+ * Returns the path to the created CPU profile in a promise, or rejects on error
96
+ * @param {String} cpuProfilePath - path of the CPU profile
97
+ * @param {number} duration - the duration of the CPU profile in ms (default: 30000ms)
98
+ * @return {Promise} the CPU profile path on success or error on rejection
99
+ */
100
+ nodeOomHeapdump.createCpuProfile("mycpuprofilepath", 10000).then((cpuProfilePath) => {
101
+ // do something with CPU profile
102
+
103
+ // and delete again from disk
104
+ nodeOomHeapdump.deleteCpuProfile(cpuProfilePath);
105
+ }).catch((err) => {
106
+ // handle error
107
+ });
108
+
109
+ /**
110
+ * Deletes all previously created CPU profiles from disk
111
+ */
112
+ nodeOomHeapdump.deleteAllCpuProfiles();
113
+
114
+ /**
115
+ * Deletes a particular CPU profile from disk
116
+ * @param {String} cpuProfilePath - path to the CPU profile to delete from disk
117
+ * @return {Promise}
118
+ */
119
+ nodeOomHeapdump.deleteCpuProfile(cpuProfilePath);
120
+ ```
121
+
122
+ # Known issues and limitations
123
+
124
+ ## Memory usage
125
+ When creating a heapdump on request, it's notorious for using a lot of memory. This is caused by a bug in V8/DevTools protocol and is reported here (https://bugs.chromium.org/p/chromium/issues/detail?id=768355); the protocol has no backpressure mechanism, which causes the heapdump to be pushed faster than the DevTools client can handle, causing in-memory buffering.
126
+
127
+ This is not a problem if your server/machine has memory to spare, but can cause issues in memory restricted environments like a Docker container. Once the process exceeds the container memory threshold, it will be killed by OoMKiller (if enabled). This leads to an empty heapsnapshot file (0 bytes).
128
+
129
+ Please vote for that issue to be fixed!
@@ -0,0 +1,19 @@
1
+ Microsoft Visual Studio Solution File, Format Version 12.00
2
+ # Visual Studio 2015
3
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "node_oom_heapdump_native", "node_oom_heapdump_native.vcxproj", "{B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}"
4
+ EndProject
5
+ Global
6
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
7
+ Debug|x64 = Debug|x64
8
+ Release|x64 = Release|x64
9
+ EndGlobalSection
10
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
11
+ {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Debug|x64.ActiveCfg = Debug|x64
12
+ {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Debug|x64.Build.0 = Debug|x64
13
+ {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Release|x64.ActiveCfg = Release|x64
14
+ {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Release|x64.Build.0 = Release|x64
15
+ EndGlobalSection
16
+ GlobalSection(SolutionProperties) = preSolution
17
+ HideSolutionNode = FALSE
18
+ EndGlobalSection
19
+ EndGlobal