/division

Simple yet powerful wrapper over node.js cluster API.

Primary LanguageCoffeeScriptMIT LicenseMIT

division

Overview

Simple yet powerful wrapper over node.js cluster API.
This module is inspired by impressive, but abandoned project Cluster created by TJ Holowaychuk.

Installation

$ npm install division

Running Tests

First go to module directory and install development dependencies:

$ npm install

Then you can test module typing:

$ npm test
Code coverage

To get code coverage results run:

$ npm run coverage

Reports are in coverage directory.

Features

The most valuable feature: you don't need to change your code to working within cluster.

Other features:

  • works with node version ≥ 0.10
  • compatible with io.js (all tests green)
  • standalone (i.e. without 3rd-party dependencies)
  • zero-downtime restart
  • maintains worker count
  • forceful shutdown support
  • graceful shutdown support
  • bundled extensions
    • debug: enable verbose debugging informations
    • watch: reload cluster when files was changed
    • signals: add ability to control cluster with POSIX signals

Examples

More examples you can find in examples directory.

Standard configuration example

var division = require('division');
var cluster = new division();

// Configuration for development environment
cluster.configure('development', function () {
  // Put your development configuration here
  cluster.set('args', ['--some-process-args', 'send-to-workers']);
});

// Configuration for production environment
cluster.configure('production', function () {
  // Put your production configuration here
  cluster.enable('silent');
});

// Configuration for all environments
// TIP: this is pointing to cluster
cluster.configure(function () {
  this.set('path', 'app.js');
});

// You can also set settings without configuration block
cluster.set('size', 2);

// Use extensions
// TIP: You can chain (almost) all methods
cluster.use('debug').use('signals');

// Start your application as a cluster!
cluster.run(function () {
  // `this` is pointing to the Master instance
});

You can set environment while launching application - in this way:

$ NODE_ENV=production node cluster.js

Minimal configuration example

var division = require('division');
// You can pass settings in constructor
var cluster = new division({ path : 'app.js' });

cluster.run();

API Reference

For API reference take a look at docs directory.