Code Monkey home page Code Monkey logo

ncluster's Introduction

Cluster solution based on node's cluster module.

Build Status

#Features

  • Restarts workers that die
  • Zero downtime reloading of application when receiving SIGHUP
  • Gracefully dies when receiving SIGQUIT
  • Correctly reloads code when deployed with capistrano

Hacks

  • Overrides net._createServerHandle to track sockets open by master so they can be closed during graceful shutdown. If they are not closed then new clients will hang instead of receiving connection refused.
  • Overrides net.Server.prototype.listen in worker to ensure an error is generated if a port cannot be bound to

#Issues

  • Not enough testing
  • Nodejs's cluster module doesn't appear to be fair (possibly why people have created their own nodejs http proxy balancers)

#Related

#Usage

Example app.js

var ncluster = require('ncluster');
ncluster('./server.js', {workers: 5});

Example server.js

var http = require('http');
var http_server = http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello From Worker\n');
});

http_server.listen(3000);


module.exports = http_server;

Default Configuration

var defaults = {
  workers: os.cpus().length,
  dir: path.dirname(process.argv[1]),
  heartbeat_timeout: 10 * 1000,
  startup_timeout: 60 * 1000,
  log_dir: "log",
  kill_wait_timeout: 30 * 1000,
  heartbeat_interval: 500
};

Examples

https://github.com/benmmurphy/nodejs_vagrant_helloworld

ncluster's People

Contributors

benmmurphy avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.