https://github.com/kessler/clusterize
a simple node cluster helper
https://github.com/kessler/clusterize
Last synced: about 2 months ago
JSON representation
a simple node cluster helper
- Host: GitHub
- URL: https://github.com/kessler/clusterize
- Owner: kessler
- Created: 2012-09-17T12:03:43.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-06-22T16:33:39.000Z (almost 12 years ago)
- Last Synced: 2025-03-08T08:12:39.988Z (about 2 months ago)
- Language: JavaScript
- Size: 142 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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