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 🙏

© 2025 – Pkg Stats / Ryan Hefner

clusterflock

v0.3.2

Published

a clustering http server for node

Downloads

6

Readme

clusterflock Build Status

flocking birds

clusterflock is a simple clustering HTTP server for Node. It accepts a single request handler and a hash of options. The goal of clusterflock is to eliminate my own repeated need for a simple clustering server that implements graceful worker shutdown and re-forking of dead workers.

This package is deprecated. I wrote a much more well-tested version without the known bugs of clusterflock called teamster.

Installation

$ npm install clusterflock --save

Usage

By default, clusterflock will fork the number of workers equal to os.cpus().length. When it receives a SIGINT or SIGTERM signal, it will begin attempting to shut down gracefully by ceasing to receive requests and closing all servers after existing requests have been completed.

The simplest use case of clusterflock is to pass it a single request handler function:

var clusterflock = require('clusterflock');

clusterflock(function (req, res) {
  res.end('ok');
});

Since clusterflock essentially just calls http.createServer in the worker process, anything that can be normally passed to that function can be passed to the clusterflock main function, including express apps:

var clusterflock = require('clusterflock'),
    express      = require('express'),
    app          = express();
    
app.use(express.bodyParser()); // &c.
clusterflock(app);

Worker Re-forking

When a worker disconnects, the master checks the value of its suicide attribute. If that value is true, master does nothing. If that value is not true (i.e. the worker died/was killed unintentionally), the master forks a new worker.

Options

The clusterflock function accepts an options object:

var clusterflock = require('clusterflock'),
    app          = require('./lib/app');
    
clusterflock(app, {
  numWorkers: 1,
  port      : 3000,
  timeout   : 5000
});

Name | Type(s) | Default | Description ------------ | ------------------ | -------------------------- | ------------------ numWorkers | Number | os.cpus().length | number of worker processes to fork port | Number, String | process.env.PORT || 5000 | port the workers will listen on timeout | Number | 1000 | amount of time after receiving a graceful shutdown signal that the master will immediately kill workers

Signals

clusterflock responds to signals. heroku, for example, sends SIGTERM to stop and restart dynos, which will cause clusterflock to initiate a graceful shutdown. SIGINT, on the other hand, will force clusterflock to shut down immediately.

Signal | Behavior --------- | -------------------------------------------------------- SIGTTIN | Fork an additonal worker SIGTTOU | Disconnect the least-recently forked worker SIGINT | Kill master process (and therefore workers) immediately. SIGTERM | Forward myself SIGQUIT. SIGQUIT | Attempt a graceful shutdown (stop serving requests, serve remaining requests, and shut down).

Testing

To run the tests:

$ npm test

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my-clusterflock)
  3. Commit your changes (git commit -am "add unicorns")
  4. Push to the branch (git push origin my-clusterflock)
  5. Open a Pull Request

Meta

The photo in this readme is by Flickr user Eugene Zemlyanskiy. It has a CC BY 2.0 license.