mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
f731125804
Change-Id: I92ae0bb6e02caef98b0d68de4424e775d8922651
27 lines
752 B
JavaScript
27 lines
752 B
JavaScript
/**
|
|
* A very basic cluster-based server runner. Restarts failed workers, but does
|
|
* not much else right now.
|
|
*/
|
|
|
|
var cluster = require('cluster');
|
|
var app = require('./ParserService.js');
|
|
// Start a few more workers than there are cpus visible to the OS, so that we
|
|
// get some degree of parallelism even on single-core systems. A single
|
|
// long-running request would otherwise hold up all concurrent short requests.
|
|
var numCPUs = require('os').cpus().length + 3;
|
|
|
|
if (cluster.isMaster) {
|
|
// Fork workers.
|
|
for (var i = 0; i < numCPUs; i++) {
|
|
cluster.fork();
|
|
}
|
|
|
|
cluster.on('death', function(worker) {
|
|
console.log('worker ' + worker.pid + ' died, restarting.');
|
|
// restart worker
|
|
cluster.fork();
|
|
});
|
|
} else {
|
|
app.listen(8000);
|
|
}
|