Giter Club home page Giter Club logo

clusterize's Introduction

klusterize

a node cluster helper

###Usage typical server.js:

var klusterize = require('klusterize');

klusterize({
	worker: function() {
	    console.log('I am a worker');
	},
	master: function() {
		console.log('I am the master');
	},
	reforkOnDeath: false,
	workersToCoresRatio: 0.5
});

//on a 4 cores system will (eventually) print 'I am a worker' twice and 'I am the master' once

Same as the above only this time called directly:

var klusterize = require('klusterize');

klusterize(
	function() {
	    console.log('I am a worker');
	}, 
	function() {
		console.log('I am the master');
	},
	false,
	0.5);

files instead of functions:

var klusterize = require('klusterize');

klusterize({
	worker: 'worker.js',
	master: 'master.js'
});

options reference:

  • worker - required, a function to invoke on worker processes or a name of a javascript filename

  • master - optional, will be fired after forking code, can be a function or a javascript filename

  • reforkOnDeath - optional, whether to refork processes when a worker dies, defaults to true

  • workersToCoresRatio - optional, workers to cores ratio expressed in numerical notation (i.e 0.5 = 50% of the cores etc.), default is 1 (100%). In any case there will always be a minimum of one worker. Values over 100% are acceptable and will spawn more workers than cores. The calculation will round the result down (i.e on a system with 5 cores, 0.5 will be rounded down to 2)

  • workersCount - optional, en explicit number of worker to start, this will override workersToCoresRatio. as with workerstoCoresRation a minumum of 1 worker is enforced.

  • workerDeathCallback - optional, a callback to invoke on worker death. specifying this param will override reforkOnDeath behavior.

  • env - optional, environment of the worker

###TODO expand tests

clusterize's People

Contributors

kessler avatar

Watchers

 avatar  avatar

Forkers

levyitay

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.