An handy tool for your node servers and 0 downtime needs.
ClusterJS will take your app and spawn it in a node-cluster with as many workers you want.
You can reload the whole cluster sending a simple signal: ClusterJS will go through all your workers, reloading them one by one.
~/projects/clusterjs (master ✔) ᐅ clusterjsCluster.js help:Usage: clusterjs [path to app] [options]Options:--workers Defines how many workers we should launch (Default: CPU count)--reloadon On Which signal will the cluster be reloaded (Default: SIGUSR2)
It is recommended to install the package globally:
npm install -g clusterjs
Suppose you have an app running on an
app.js file, you
can simply decide to start it with clusterjs:
This will start a cluster of as many apps as CPU cores you have on your machine; to change the number of workers, simply specify it when launching the cluster:
clusterjs app.js --workers 5
WARNING if your path contains a symlink, clusterjs will need the full path to your app
You can reload the cluster, achieving zero-downtime deployments by
SIGUSR2 command to the master process:
~/projects/clusterjs (master ✔) ᐅ ps aux | grep cluster.js29571 2.0 0.1 659236 10440 pts/4 Sl+ 23:21 0:00 node ./bin/cluster.js test/testApp/app.js29573 1.5 0.1 656160 8564 pts/4 Sl+ 23:21 0:00 /home/local/bin/node /home/projects/clusterjs/bin/cluster.js test/testApp/app.js29574 2.0 0.1 656160 8564 pts/4 Sl+ 23:21 0:00 /home/local/bin/node /home/projects/clusterjs/bin/cluster.js test/testApp/app.js29576 1.5 0.1 656160 8564 pts/4 Sl+ 23:21 0:00 /home/local/bin/node /home/projects/clusterjs/bin/cluster.js test/testApp/app.js29577 1.5 0.1 656160 8564 pts/4 Sl+ 23:21 0:00 /home/local/bin/node /home/projects/clusterjs/bin/cluster.js test/testApp/app.js29582 0.0 0.0 13636 984 pts/5 S+ 23:21 0:00 grep cluster.js~/projects/clusterjs (master ✔) ᐅ kill -SIGUSR2 29571
This will gracefully reload your cluster, updating the app without any downtime.
You can also customize the signal used to reload the cluster:
clusterjs app.js --workers 5 --reloadon SIGUSR2
If you want to actually shutdown the app, simply issue a
You can also use cluster.js as a module in your userland code by simply requiring it:
var clusterjs = ;;
You can use the simple dummy server included in the
tests/testApp directory if you need to experiment:
git clone firstname.lastname@example.org:namshi/clusterjs.gitcd clusterjs./bin/cluster.js test/testApp/app.js
Well, the biggest effort was made by Jonathan Warner who explained how easily you could achieve ZDD with node.
We polished the code a bit as we found out that it had some glitches but the main idea remains the same (so yeah, thanks Jax!).
ClusterJS is released under the MIT license.