Your socket based application which should be multiplexed
const net = require('net');function startup(){ const server = net.createServer((socket) => { // connections never end }); server.listen(8000);}module.exports = { // init hook init: startup};
Hot-Restart / Hot-Reload
To hot-restart (zero downtime) an application, just send a SIGHUP to the master process.
This spawns new workers and disconnects all current workers from the cluster-proxy
Example
# send SIGHUP to process 12345kill -HUP 12345
Signals
SIGHUP Restart workers
SIGTERM Gracefull application shutdown
SIGINT Gracefull application shutdown
Delayed Restarts
cluster-magic comes with as simple delayed-restart policy which suppresses infinite restart loops.
In case a process dies, an internal counter will be incremented.
If a threshold of 10 is reached the process restart is delayed by counter*200ms to avoid infinite restart loops on internal application errors.
Well..this is may not what you expect from a "clustered application" but such an error requires that a manual fix will take place by the operations team (_logger.alert event is triggerd which SHOULD be observed)
The counter is decremented by 1 once per minute.
Environment
To specify the number of workers you can easily pass the environment variable NUM_WORKERS to the nodejs process. Default is set to num_cpus*2
License
cluster-magic is OpenSource and licensed under the Terms of The MIT License (X11) - your're welcome to contribute