Permalink
Browse files

org-ids/web-ide-issues#1215: Use graceful server to restart on a cert…

…ain memory threshold
  • Loading branch information...
grant-g committed Sep 18, 2018
1 parent 70efda4 commit c406dfd773ab67bf3af86ee20f44cb789cac6e8c
Showing with 10 additions and 6 deletions.
  1. +2 −1 modules/orionode/lib/graceful-cluster/graceful-cluster.js
  2. +8 −5 modules/orionode/server.js
@@ -36,6 +36,7 @@ GracefulCluster.start = function(options) {
var exitFunction = options.exitFunction || (function gracefulClusterExit () { process.exit(0); });
var log = options.log || console.log;
var errorLog = options.errorLog || log;
var shutdownTimeout = options.shutdownTimeout || 5000;
var disableGraceful = options.disableGraceful;
var workersCount = options.workersCount || numCPUs;
@@ -195,7 +196,7 @@ GracefulCluster.start = function(options) {
setInterval(function() {
var mem = process.memoryUsage().rss;
if (mem > options.restartOnMemory) {
log('Cluster: worker ' + process.pid + ' used too much memory (' + Math.round(mem / (1024*1024)) + ' MB), restarting...');
errorLog('Cluster: worker ' + process.pid + ' used too much memory (' + Math.round(mem / (1024*1024)) + ' MB), restarting...');
GracefulCluster.gracefullyRestartCurrentWorker();
}
View
@@ -50,10 +50,6 @@ var cluster, clusterParam = configParams.get("orion_cluster");
if (clusterParam) {
cluster = require('cluster');
}
var restartOnMemoryLimit = parseInt(configParams.get("orion_threshold_memory_mb"));
if (restartOnMemoryLimit) {
restartOnMemoryLimit = restartOnMemoryLimit * 1024 * 1024; /* bytes */
}
var homeDir = os.homedir();
if (process.versions.electron) {
@@ -77,6 +73,12 @@ if (process.versions.electron) {
var logger = log4js.getLogger('server');
var restartOnMemoryLimit = parseInt(configParams.get("orion_threshold_memory_mb"));
if (restartOnMemoryLimit) {
logger.info("Process memory limit: " + restartOnMemoryLimit + "MB");
restartOnMemoryLimit = restartOnMemoryLimit * 1024 * 1024; /* bytes */
}
function startServer(cb) {
var workspaceArg = configParams.any("workspace", "w") || configParams.get("_")[0];
var workspaceDir;
@@ -250,7 +252,8 @@ try {
log: logger.info.bind(logger),
shutdownTimeout: configParams.get("shutdown.timeout"),
workersCount: numCPUs,
restartOnMemory: restartOnMemoryLimit
restartOnMemory: restartOnMemoryLimit,
errorLog: function(value) {logger.error(value);}
});
} else {
start(process.versions.electron);

0 comments on commit c406dfd

Please sign in to comment.