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

cluster-requiem

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cluster-requiem

high availability enhacements for clustering

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cluster-requiem

Enhacements for the cluster module in order to handle graceful shutdowns with jobs that aren't associated with a socket.

History

Node cluster modules garantees that all server sockets will be closed before exiting the process, but this doesn't extends to all other jobs that can't be interrupted. This makes the cluster module useless when combined with softwares like PM2 as long standing jobs that don't have a client requets associated with it will die when you reload the server.

This module solves this by adding trackers which holds the server up until all they finishes their jobs.

Usage

Install it

npm install --save cluster-requiem

Initialize and prepare servers

var http = require('http');
var cluster = require('cluster');
var requiem = require('cluster-requiem');

if (cluster.isMaster) {
	var worker = cluster.fork();
	
	setTimeout(function() {
		console.log('disconnecting', worker.id);
		worker.disconnect(function() {
			console.log('done');
		});
	}, 2000);
} else {
	var longJobThatCantBeInterrupted = function(callback) {
		setTimeout(function() {
			console.log('job done');
			callback();
		}, 10000);
	};

	requiem.initialize();

	requiem.on('begin', function() {
		console.log('grabs the violin')
	});

	var server = http.createServer(function(err, req) {
			req.writeHead(200);
			req.end('Hello world!');
	});

	requiem.track(function(callback) {
			longJobThatCantBeInterrupted(callback);
	});

	server.listen(8080);
	requiem.trackSocket(server);

	console.log('listening')
}

Note: You need to track server sockets in case of a graceful shutdown(PM2 for instance, sends the 'shutdown' event before trying to kill the process). If you don't do this the server will stil receive connections while it waits for all trackers to finish. Under high load this will potentially lead the server to never close, making PM2 kill long standing jobs as it can't handle they.

Keywords

FAQs

Package last updated on 07 Sep 2015

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