server: force gc to address memory leaks

This commit is contained in:
Koushik Dutta
2021-09-27 01:14:10 -07:00
parent e87e3059af
commit 09da42c5bd
3 changed files with 13 additions and 6 deletions

View File

@@ -55,9 +55,9 @@
},
"scripts": {
"preserve": "npm run build",
"serve": "node dist/scrypted-main.js",
"serve-no-build": "node dist/scrypted-main.js",
"ts-serve": "ts-node src/scrypted-main.ts",
"serve": "node --expose-gc dist/scrypted-main.js",
"serve-no-build": "node --expose-gc dist/scrypted-main.js",
"ts-serve": "ts-node --expose-gc src/scrypted-main.ts",
"prebuild": "tsc --build --clean",
"build": "tsc --outDir dist",
"postbuild": "node test/check-build-output.js"

View File

@@ -421,7 +421,8 @@ export function startPluginClusterWorker() {
type: 'stats',
cpu: cpuUsage,
memoryUsage: process.memoryUsage(),
})
});
global?.gc();
}, 10000);
const consolePort = createConsoleServer(events);

View File

@@ -444,18 +444,24 @@ export class ScryptedRuntime {
this.invalidatePluginDevice(pluginDevice._id);
}
const execArgv = ['--expose-gc'];
if (process.argv[0].endsWith('ts-node'))
execArgv.push('-r', 'ts-node/register');
if (pluginDebug) {
console.log('plugin inspect port', pluginDebug.inspectPort)
execArgv.push('--inspect');
cluster.setupMaster({
silent: true,
inspectPort: pluginDebug.inspectPort,
execArgv: process.argv[0].endsWith('ts-node') ? ['--inspect', '-r', 'ts-node/register'] : ['--inspect'],
execArgv,
});
}
else {
cluster.setupMaster({
silent: true,
execArgv: process.argv[0].endsWith('ts-node') ? ['-r', 'ts-node/register'] : [],
execArgv,
});
}