Cluster + instance improvements

-Moved the database initialize call out of the instance code into the prestart script so that it is now only called once when you start the explorer even if you are running multiple cpus/threads
-The database connection function now uses the default connection string in the event a connection string is not supplied
-Removed unused reference to lib/explorer.js code from the cluster file
This commit is contained in:
Joe Uhren
2023-08-20 20:41:41 -06:00
parent 550b961ab3
commit 8bcb995728
4 changed files with 66 additions and 61 deletions
-1
View File
@@ -2,7 +2,6 @@ var cluster = require('cluster');
if (cluster.isMaster) {
const isWinOS = process.platform == 'win32';
const lib = require('../lib/explorer');
const instances = (process.argv[2] != null && process.argv[2] != '' && !isNaN(process.argv[2]) && Number.isInteger(parseFloat(process.argv[2])) ? parseInt(process.argv[2]) : require('os').cpus().length);
console.log('Starting cluster with pid: ' + process.pid);
+1 -10
View File
@@ -6,15 +6,7 @@ var app = require('../app');
app.set('port', process.env.PORT || settings.webserver.port);
var dbString = 'mongodb://' + encodeURIComponent(settings.dbsettings.user);
dbString = dbString + ':' + encodeURIComponent(settings.dbsettings.password);
dbString = dbString + '@' + settings.dbsettings.address;
dbString = dbString + ':' + settings.dbsettings.port;
dbString = dbString + '/' + settings.dbsettings.database;
db.connect(dbString, function() {
// initialize the database
db.initialize_data_startup(function() {
db.connect(null, function() {
var server = app.listen(app.get('port'), '::', function() {
debug('Express server listening on port ' + server.address().port);
});
@@ -32,5 +24,4 @@ db.connect(dbString, function() {
});
});
});
});
});
+7
View File
@@ -286,6 +286,13 @@ module.exports = {
connect: function(database, cb) {
mongoose.set('strictQuery', true);
if (database == null)
database = 'mongodb://' + encodeURIComponent(settings.dbsettings.user) +
':' + encodeURIComponent(settings.dbsettings.password) +
'@' + settings.dbsettings.address +
':' + settings.dbsettings.port +
'/' + settings.dbsettings.database;
mongoose.connect(database).then(() => {
return cb();
}).catch((err) => {
+9 -1
View File
@@ -10,7 +10,7 @@ var nodeVersionRevision = '0';
// check if the nodejs version # is blank or a very long string as that would usually indicate a problem
if (nodeVersion != null && nodeVersion != '' && nodeVersion.length < 16) {
// Remove the 'v' from the beginning of the version string
// remove the 'v' from the beginning of the version string
if (nodeVersion.indexOf('v') == 0)
nodeVersion = nodeVersion.slice(1);
@@ -99,6 +99,12 @@ check_arguments_passed(function(pidName, node_env) {
// compile scss to css
execSync('node ./scripts/compile_css.js', {stdio : 'inherit'});
const db = require('../lib/database');
// connect to the mongo database
db.connect(null, function() {
// initialize the database
db.initialize_data_startup(function() {
// check if the webserver should be started from here based on the pidName
switch (pidName) {
case 'pm2':
@@ -143,4 +149,6 @@ check_arguments_passed(function(pidName, node_env) {
// finished pre-loading
process.exit(0);
});
});
});