Skip to content
Phillip Kovalev edited this page Jul 13, 2015 · 2 revisions

Quick start

$ npm install --save luster
$ echo '{ "app": "worker.js" }' >./luster.conf.json
$ ./node_modules/.bin/luster

Cluster of the web workers

{ "server": { "port": 12345 } }
{ "server": { "port": "/var/run/node/unix.*.sock" } }

In the worker.js use the port value provided by the master:

server.listen(process.env.port);

Load balancing workaround

"workers": 10,
"server": { "port": 10000, "groups": 2 },

Workers 1–5 will listen 10000, 6–10 will listen 10001.

Setup the reverse proxy (nginx, haproxy, ...) of your choice with the round-robin balancing.

Debug the workers

{ "debug": { "port": 9000 } }

Master will start the workers with the option --debug.

1st on the port 9000, 2nd on the port 9001, …

Install a 3rd-party extension

npm install luster-some-extension

Add the extensions section to the config:

extensions: {
    "luster-some-extension": { <CONFIG> }
} 

Write an extension!

Extension for the luster is the regular Node.js module, which exports an object including the configure function.

module.exports = {
    configure: function(config, clusterProcess) {
        // setup the extension
    }
}

Remote procedure call

master.registerRemoteCommand('pong', function(sender, state) {
    console.log('worker %s is %s', sender.wid, state);
}).remoteCallToAll('ping');

worker.registerRemoteCommand('ping', function(sender) {
    sender.remoteCall('pong', 'alive');
});

Need for custom master?

Master = require('luster/master');
MyMaster = Master.create();

MyMaster.configure(config).run();

When to use a custom master?

  • Queues
  • Multiple masters in the one process
  • Whatever you want!

Summary

  • Clusterize your app in a minute.
  • Attach a remote debugger to any worker.
  • Partially managable load balancing.
  • Write an extension and distribute it as a Node.js module.
  • Compose you own master to orchestrate complex apps.

Any questions?

  • Read the docs in the README and JSDoc in the sources.
  • Ask in the GitHub issues.