How to use the cluster.fork function in cluster

To help you get started, we’ve selected a few cluster examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github remy / nodemon / oldtests / fixtures / cluster / index.js View on Github external
require('os').cpus().forEach(function() {
    var worker = cluster.fork();
    worker.on('online', function(msg) {
      console.log('worker', worker.process.pid, 'online');
      workers[worker.process.pid] = worker;
    });
  });
  cluster.on('exit', function(worker, code, signal) {
github remy / nodemon / oldtests / fixtures / cluster / index-0.6.x.js View on Github external
require('os').cpus().forEach(function() {
    var worker = cluster.fork();
    worker.on('message', function(msg) {
      console.log('worker', worker.pid, 'online');
      workers[worker.pid] = worker;
    });
  });
github doxout / recluster / index.js View on Github external
function fork(wid) {
        var w = cluster.fork({WORKER_ID: wid});
        w._rc_wid = wid;
        w._rc_isReplaced = false;
        w.on('message', function(message) {
            emit('message', w, message);
        });
        w.process.on('exit', function() {
            utils.removeFrom(workers, w);
            deactivate(w);
        });
        workers.push(w);
        return w;
    }
github ClusterWS / ClusterWS / dist / lib / servers.js View on Github external
var launchWorker_1 = function (i) {
        var worker = workers_1[i] = cluster.fork();
        initWorkerMsg_1.data.id = i;
        worker.on('exit', function () {
            if (initWorkerMsg_1.data.restartWorkerOnFail) {
                console.log('\x1b[33m%s\x1b[0m', 'Restarting worker on fail ' + initWorkerMsg_1.data.id);
                launchWorker_1(i);
            }
        });
        handleChildMessages_1(worker);
        worker.send(initWorkerMsg_1);
    };
    process.on('message', function (message) {
github bitpay / bwdb / lib / web-workers.js View on Github external
cluster.on('exit', function(worker, code, signal) {
    if (worker.suicide !== true && (signal || code !== 0)) {
      logStatus(worker, code, signal);
      var newWorker = cluster.fork();
      var indexOfWorker = workers.indexOf(worker);
      if (indexOfWorker >= 0) {
        workers.splice(indexOfWorker, 1);
      }
      log.warn('Web cluster worker respawned with worker id: ' + newWorker.id);
      workers.push(newWorker);
      initWorker(newWorker);
    } else {
      logStatus(worker, code, signal);
    }
  });
github gourmetjs / gourmet-ssr / runtime / http-server / lib / GourmetServerLauncher.js View on Github external
forkWorkers(count) {
    for (let idx = 0; idx < count; idx++)
      cluster.fork();
  }
github node-pinus / pinus / examples / robot-sample / http.ts View on Github external
function run(num) {
    for (let i = 0; i < num; i++) {
        cluster.fork();
    }
}
github easy-team / egg-webpack / lib / node-cluster.js View on Github external
restart() {
    if (this.running && Date.now() < this.runUntil) {
      cluster.fork();
    }
  }
github sazze / node-pm / lib / master.js View on Github external
function fork(number) {
  var numProc = number || require('os').cpus().length;

  config.n = numProc;

  debug('forking %d workers', numProc);

  forkLoopProtect();

  for (var i = 0; i < numProc; i++) {
    cluster.fork({PWD: config.CWD});
  }
}

cluster

extensible multi-core server manager

MIT
Latest version published 13 years ago

Package Health Score

58 / 100
Full package analysis