diff --git a/src/scripts/backupupload.js b/src/scripts/backupupload.js index 413ee6665..440d9d26a 100755 --- a/src/scripts/backupupload.js +++ b/src/scripts/backupupload.js @@ -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