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

cluster-magic

v1.1.1

Published

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

Downloads

7

Readme

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
  • Delayed restart of failed processes to avoid infinite restart loops

Install

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

Usage

A working snippet is available in the examples directory. Just run node examples/startup.js

File: startup.js

Initializes the cluster application

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

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

File: application.js

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