fix!: re-create CPU profiler each time a CPU profile is collected to work around V8 CPU profiler memory leak. #142
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work around memory leak in V8 CPU profiler (https://bugs.chromium.org/p/v8/issues/detail?id=11051) by creating and destroying the CPU profiler each time a CPU profile is collected.
BREAKING:
With this change, an error will now occur when one attempts to collect 2 CPU profiles in parallel.
TESTED: Confirmed pprof-nodejs no longer had memory leak by running small express application with a version of pprof-nodejs without this change and with the currently release version. When running this application with Node 14 overnight, a memory leak was no longer apparent. I added log statements to confirm the fix is included when this native portion is compiled for Node 12.
Other potential consequences of this change:
Measurements from this change:
Applications used attached (using an express application which returns between the 20th and 30th value in the Fibonacci's sequence on each request, and application sends queries to that app).
Results (RSS sampled ~200 times throughout run of each application; all applications run at same time):
Node 12.14.1 (version of Node.js w/o leak)
Node 12.19.0 (version of Node.js w/ leak):
Looking at the charts above, it doesn't seem like performance w/ and w/o fix is very different.
express_app.js.txt
express_app-no-pprof.js.txt