Skip to content

Instantly share code, notes, and snippets.

@bencmbrook
Last active February 20, 2019 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bencmbrook/b2a44139be4b025ece63b29d3669f8f1 to your computer and use it in GitHub Desktop.
Save bencmbrook/b2a44139be4b025ece63b29d3669f8f1 to your computer and use it in GitHub Desktop.
Check Node stream memory usage
// https://nodejs.org/api/process.html#process_process_memoryusage
let rssMax = heapTotalMax = heapUsedMax = externalMax = 0;
let rssMin = heapTotalMin = heapUsedMin = externalMin = Number.MAX_SAFE_INTEGER;
readable.on('data', () => {
const x = process.memoryUsage();
if (x.rss > rssMax) rssMax = x.rss;
if (x.heapTotal > heapTotalMax) heapTotalMax = x.heapTotal;
if (x.heapUsed > heapUsedMax) heapUsedMax = x.heapUsed;
if (x.external > externalMax) externalMax = x.external;
if (x.rss < rssMin) rssMin = x.rss;
if (x.heapTotal < heapTotalMin) heapTotalMin = x.heapTotal;
if (x.heapUsed < heapUsedMin) heapUsedMin = x.heapUsed;
if (x.external < externalMin) externalMin = x.external;
});
readable.on('end', () => {
console.log({rssMin, heapTotalMin, heapUsedMin, externalMin});
console.log({rssMax, heapTotalMax, heapUsedMax, externalMax});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment