Set the heap size with large backup memory limits

I had to also give the server some more swap for the backup to succeed
This commit is contained in:
Girish Ramakrishnan
2020-11-05 15:53:02 -08:00
parent f79263a92a
commit 02eb362f37
2 changed files with 15 additions and 5 deletions
+13 -5
View File
@@ -851,15 +851,23 @@ function runBackupUpload(uploadConfig, progressCallback, callback) {
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
const { backupId, format, dataLayout, progressTag } = uploadConfig;
const { backupId, backupConfig, dataLayout, progressTag } = uploadConfig;
assert.strictEqual(typeof backupId, 'string');
assert.strictEqual(typeof format, 'string');
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof progressTag, 'string');
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
let result = ''; // the script communicates error result as a string
shell.sudo(`backup-${backupId}`, [ BACKUP_UPLOAD_CMD, backupId, format, dataLayout.toString() ], { preserveEnv: true, ipc: true }, function (error) {
// https://stackoverflow.com/questions/48387040/node-js-recommended-max-old-space-size
const envCopy = Object.assign({}, process.env);
if (backupConfig.memoryLimit && backupConfig.memoryLimit >= 2*1024*1024*1024) {
const heapSize = Math.min((backupConfig.memoryLimit/1024/1024) - 256, 8192);
debug(`runBackupUpload: adjusting heap size to ${heapSize}M`);
envCopy.NODE_OPTIONS = `--max-old-space-size=${heapSize}`;
}
shell.sudo(`backup-${backupId}`, [ BACKUP_UPLOAD_CMD, backupId, backupConfig.format, dataLayout.toString() ], { env: envCopy, ipc: true }, function (error) {
if (error && (error.code === null /* signal */ || (error.code !== 0 && error.code !== 50))) { // backuptask crashed
return callback(new BoxError(BoxError.INTERNAL_ERROR, 'Backuptask crashed'));
} else if (error && error.code === 50) { // exited with error
@@ -928,7 +936,7 @@ function uploadBoxSnapshot(backupConfig, progressCallback, callback) {
const uploadConfig = {
backupId: 'snapshot/box',
format: backupConfig.format,
backupConfig,
dataLayout: new DataLayout(boxDataDir, []),
progressTag: 'box'
};
@@ -1115,7 +1123,7 @@ function uploadAppSnapshot(backupConfig, app, progressCallback, callback) {
const uploadConfig = {
backupId,
format: backupConfig.format,
backupConfig,
dataLayout,
progressTag: app.fqdn
};