Skip to content
This repository

Methods

clu.createCluster(options)

Creates a new cluster.

Options

  • exec - the file to execute (required)
  • workers - Number of workers, will default to the number of cores
  • silent - Boolean: Makes the master & workers silent (default: false)
  • silentWorkers - Boolean: If true workers output won't be displayed (default: true)
  • cli - Boolean: Enables the CLI. (default: true)

clu.restart(cb)

Respawns all workers one after one and calls the callback after all workers have been respawned.

clu.restartMaster(cb)

Restarts the master process. Calls the callback when all workers have disconnected.

clu.stop(cb)

Stops the master process and all workers. Callback gets called when all workers disconnect.

clu.stopWorkers(cb)

Stops the all workers but not the master process. Callback gets called when all workers disconnect.

clu.scaleUp(num, cb)

Spawns x new workers. Will cb after all new workers are listening.

clu.scaleDown(num, cb)

Stops x amount of workers. Will cb after all workers have disconnected. Will throw if you stop more workers than available.

clu.workers(cb)

Calls back with an array of workers. Returns workesr if no callback is given.

clu.status()

Returns some status data. Example:

{ 
    workers: { 
        total: 2,
        active: 2,
        pending: 0,
        averageUptime: 22.2365 
    },
    master: {
        uptime: 22.4090,
        memoryUsage: {
            rss: 17698816,
            heapTotal: 12376832,
            heapUsed: 4889800 
        }
    }
}

clu.use(plugin)

Use given Plugin. This will just call it with plugin.call(clu, clu)

Events

Event emitted by clu. Uses the node EventEmitter. Listen on events like:

clu.on("progress", fuction(data){
    console.log(data);
});

progress

  • data Object - Holds task progress

Emitted if a task makes progress. Example data from a scaleUp task:

{
    task: "scaleUp",
    total: 4, // scaling up by 4
    current: 2 // to new worker are online yet
}

Attributes

clu.[attribute]

cluster

The underlying node cluster.

logger

A crappy logger. Uses util.format to output the message. It has the folling methods:

  • logger.log(msg)
  • logger.info(msg)
  • logger.warn(msg)
  • logger.debug(msg)

dir

Absolute .clu directory where the pids live.

options

The options the cluster was started with. Example:

{
    exec: '/tmp/test/app.js',
    workers: 2,
    silent: false,
    silentWorkers: true,
    cli: true
}
Something went wrong with that request. Please try again.