npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multi-cluster

v1.0.1

Published

Create robust node.js applications with automatic forking of multiple processes and multiple apps, signal handling and reforking. All in a couple of lines and without changing your existing code!

Downloads

20

Readme

NPM version

multi-cluster

NOTICE: Stats has been removed and can now be found in a seperate module: stats-server

Create robust node.js applications with automatic forking of multiple processes and multiple apps, signal handling and reforking.

All in a couple of lines and without changing your existing code!

CAUTION:

The watch feature can cause problems under certain versions of node.js.

Make sure to test it with the node.js version and the OS you intend to use it under.

What to look for when testing: When a file changes, the main process will die and throw this error: Bus error 10

Known problem versions are: 0.10.17 - 0.10.20 both included. Version 0.10.21 are known to work. UPDATE: package.json updated to reflect the need for node 0.10.21

You really shouldn't use watchers on live systems! At least not for systems that has a lot of file updates.

Out of BETA

After having run applications in live environments for years, using multi-cluster to make them stabil and multi-core friendly, it should be safe to call this module production ready.

Possible pitfall

You can NOT run 2 different applications, that both starts an HTTP (or TCP) server and tries to listen on the same port!!!

This would not fail when trying - just give you some weird results!

The reason for this lies in the node.js cluster handler, which CAN split incoming requests between processes, but can't know, which application should get which requests.

This will of course result in unwanted results, where you will see all requests being handled by one app and suddenly shift to the other app.

The thoughts behind

Basically the module will enable you to seperate your app code from cluster and signal handling code. You can start 1 or many apps with a single script. The module will keep track on which processes (app childs) dies, which to restart and enables you to live reload all apps at once.

You don't need to change a single line of code

The architecture of this module simplifies development by seperating everything completely! You can write your app as if it should run by itself, without signal handling and clustering.

Once you want to put it live, you can just write a start script like this:

var MultiCluster = require('multi-cluster');
var multiCluster = new MultiCluster('myapp.js');

That's it!

--

If you want to automate 3 more apps, it will look something like this:

var MultiCluster = require('multi-cluster');
var multiCluster1 = new MultiCluster('myapp.js');
var multiCluster2 = new MultiCluster('my_second_app.js');
var multiCluster3 = new MultiCluster('my_third_app.js');

// The second argument with a value of 10 is the amount of children to start
// Default is to start as many children as there is CPUs
var multiCluster4 = new MultiCluster('my_fourth_app.js', 10);

Can it get any simpler?

Reload on file change

This is a simple implementation for now.

The following will look for file changes in the current working dir and reload the child processes. It will wait for up to 5 secs, for all connections to close properly.

var MultiCluster = require('multi-cluster');
var multiCluster = new MultiCluster('myapp.js');
multiCluster.watch(__dirname);

Broadcast to all workers

You can synchronize state between all the workers by broadcasting a message to all sibling processes.

// example
process.on('message', function (msg) {
  if (msg.broadcast && msg.broadcast == 'sync') {
    synchronize();
  }
});
if (process.send) process.send({broadcast: 'sync'});

Which would make all worker processes call the synchronize() function.