Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clusterflock

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clusterflock

a clustering http server for node

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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.

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);

Options

NameType(s)DefaultDescription
numWorkersNumberos.cpus().lengthnumber of worker processes to fork
portNumber, Stringprocess.env.PORT || 5000port the workers will listen on
timeoutNumber1000amount of time after receiving a graceful shutdown signal that the master will immediately kill workers

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.

Keywords

FAQs

Package last updated on 04 Mar 2014

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