New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cluster-magic

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cluster-magic

run multi-threaded node.js network applications using the native cluster module

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

cluster-magic

run multi-threaded node.js network applications using the native cluster module

Features

  • Run network applications within multiple processes multiplexed by node.js
  • Easy to use, configless
  • Standalone, no external process managers required
  • Respawn dead/failed workers
  • Gracefull application shutdown via sigterm
  • Hot-Reload/Hot-Restart via sighup

Install

$ npm install cluster-magic --save
$ yarn add cluster-magic

Usage

File: application.js

const net = require('net');

function startup(){
    const server = net.createServer((socket) => {
        // connections never end
    });
    
    server.listen(8000);
}

module.exports = {
    // init hook
    init: startup
};

File: startup.js

const _cluster = require('cluster-magic');
const _app = require('./application.js');

// start the clustered app (8 workers)
_cluster.init(_app, {
    numWorkers: 8
});

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 12345
kill -HUP 12345

Signals

  • SIGHUP Restart workers
  • SIGTERM Gracefull application shutdown

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

FAQs

Package last updated on 30 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc