fix!: re-create CPU profiler each time a CPU profile is collected to work around V8 CPU profiler memory leak.#142
Conversation
|
If we are publishing this, we should at least measure the overhead of repeated creation and deletion of the CPU profiler.
Otherwise, this PR LGTM. |
|
@kalyanac -- I've updated description with testing I've done. RSS is slightly higher w/ version of pprof-nodejs with the fix (relative to current pprof release). QPS is also slightly higher w/ version of pprof-nodejs (relative to current pprof release); but even statistically significant differences seem slight. |
|
Thank you for the additional data. All the values could be rounded down to fewer significant digits for readability. For 12.19.0, the first row is just AVERAGE, it should be Avg RSS (MiB). |
f3436dd to
d0504ca
Compare
d0504ca to
9612cc8
Compare
Codecov Report
@@ Coverage Diff @@
## master #142 +/- ##
=======================================
Coverage 42.21% 42.21%
=======================================
Files 14 14
Lines 2061 2061
Branches 42 42
=======================================
Hits 870 870
Misses 1173 1173
Partials 18 18 Continue to review full report at Codecov.
|
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