Browse Source

ref start

activeAddress
Matias Alejo Garcia 8 years ago
parent
commit
fbe7dc4fa0
No known key found for this signature in database GPG Key ID: 2470DB551277AB3
  1. 58
      bws.js
  2. 4
      config.js

58
bws.js

@ -57,53 +57,37 @@ function startInstance(cb) {
expressApp.start(config, function(err) {
if (err) {
log.error('Could not start BWS instance', err);
return cb(err);
return;
}
server.listen(port);
return cb();
});
};
var logStart = function(err) {
if (err) {
log.error('Error:' + err);
var instanceInfo = cluster.worker ? ' [Instance:' + cluster.worker.id + ']' : '';
log.info('BWS running ' + instanceInfo);
return;
}
if (cluster.worker)
log.info('BWS Instance ' + cluster.worker.id + ' running');
else
log.info('BWS running');
});
};
if (config.cluster && cluster.isMaster) {
if (config.cluster) {
// Count the machine's CPUs
var instances = config.clusterInstances || require('os').cpus().length;
if (cluster.isMaster) {
log.info('Starting ' + instances + ' instances');
// Count the machine's CPUs
var instances = config.clusterInstances || require('os').cpus().length;
log.info('Starting ' + instances + ' instances on port:' + port);
// Create a worker for each CPU
for (var i = 0; i < instances; i += 1) {
cluster.fork();
}
// Listen for dying workers
cluster.on('exit', function(worker) {
// Replace the dead worker,
log.error('Worker ' + worker.id + ' died :(');
cluster.fork();
});
// Code to run if we're in a worker process
} else {
startInstance(logStart);
// Create a worker for each CPU
for (var i = 0; i < instances; i += 1) {
cluster.fork();
}
// Listen for dying workers
cluster.on('exit', function(worker) {
// Replace the dead worker,
log.error('Worker ' + worker.id + ' died :(');
cluster.fork();
});
// Code to run if we're in a worker process
} else {
log.info('Starting on port: ' + port);
startInstance(logStart);
log.info('Listening on port: ' + port);
startInstance();
};

4
config.js

@ -3,8 +3,8 @@ var config = {
disableLogs: false,
port: 3232,
// comment this to use a single process
cluster: true,
// Uncomment to make BWS a forking server
// cluster: true,
// Uncomment to set the number or process (will use the nr of availalbe CPUs by default)
// clusterInstances: 4,

Loading…
Cancel
Save