cluster.setupMaster()

cluster.setupMaster([settings])

  • settings <Object>
    • exec <String> file path to worker file. (Default=process.argv[1])
    • args <Array> string arguments passed to worker. (Default=process.argv.slice(2))
    • silent <Boolean> whether or not to send output to parent's stdio. (Default=false)

setupMaster is used to change the default 'fork' behavior. Once called, the settings will be present in cluster.settings.

Note that:

  • any settings changes only affect future calls to .fork() and have no effect on workers that are already running
  • The only attribute of a worker that cannot be set via .setupMaster() is the env passed to .fork()
  • the defaults above apply to the first call only, the defaults for later calls is the current value at the time of cluster.setupMaster() is called

Example:

const cluster = require('cluster');
cluster.setupMaster({
  exec: 'worker.js',
  args: ['--use', 'https'],
  silent: true
});
cluster.fork(); // https worker
cluster.setupMaster({
  exec: 'worker.js',
  args: ['--use', 'http']
});
cluster.fork(); // http worker

This can only be called from the master process.

doc_Nodejs
2016-04-30 04:38:17
Comments
Leave a Comment

Please login to continue.