backups: periodically dump heap space info

This commit is contained in:
Girish Ramakrishnan
2020-11-05 14:30:45 -08:00
parent cd95da6d35
commit f79263a92a

View File

@@ -12,7 +12,8 @@ var assert = require('assert'),
backups = require('../backups.js'),
database = require('../database.js'),
debug = require('debug')('box:backupupload'),
settings = require('../settings.js');
settings = require('../settings.js'),
v8 = require('v8');
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
@@ -52,13 +53,27 @@ function throttledProgressCallback(msecs) {
};
}
// https://github.com/josefzamrzla/gc-heap-stats#readme
// https://stackoverflow.com/questions/41541843/nodejs-v8-getheapstatistics-method
function dumpMemoryInfo() {
const mu = process.memoryUsage();
const hs = v8.getHeapStatistics();
debug(`v8 heap : used ${hs.used_heap_size} total: ${hs.total_heap_size} max: ${hs.heap_size_limit}`);
debug(`process: rss: ${mu.rss} heapTotal: ${mu.heapTotal} heapUsed: ${mu.heapUsed} external: ${mu.external}`);
}
initialize(function (error) {
if (error) throw error;
dumpMemoryInfo();
const timerId = setInterval(dumpMemoryInfo, 30000);
backups.upload(backupId, format, dataLayoutString, throttledProgressCallback(5000), function resultHandler(error) {
debug('upload completed. error: ', error);
process.send({ result: error ? error.message : '' });
clearInterval(timerId);
// https://nodejs.org/api/process.html are exit codes used by node. apps.js uses the value below
// to check apptask crashes