node-cluster-app
v0.0.3
Published
Basic nodejs application using cluster
Downloads
3
Readme
node-cluster-app
#Basic nodejs application using cluster
Install
npm install node-cluster-app
##Usage:
var ClusterApp = require('node-cluster-app')
var app = new ClusterApp({
workers: 2,
timeout: 2000,
restart: true,
evlog: false
})
app.init('worker.js')
app.start()
Also view sample app in the examples directory
##Constructor options
workers
- workers number (default: cpu number)timeout
- timeout fortimeout
eventrestart
- automatically restart died workersevlog
- log native cluster events to console
##Methods
ClusterApp is EventEmitter, so we have all it methods as emit
, on
etc.
init
- assign workerworker
- path to worker's js file
start
- forks neccessary number of workersstop
- kill all workersrestart
- Sequentially run ofstop
andstart
setEvlog
- Set mode of logging all inherited from cluster events by util.logvalue
- boolean value(default: false)
##Events ClusterApp reemitted all native cluster events:
fork
- new worker forkedonline
- worker become onlinelistening
- worker become listendisconnect
- worker disconnectexit
- worker exitedsetup
- clustersetupMaster
was executed
Also it has a number own events:
timeout
- Emited on worker not emitlisten
event longer than timeout valueworker
- Worker objecttimeout
- Value of applied timeout in ms
start
- Emited on app startedstop
- Emited on app stoppednoworkers
- Emitted on last workerexit
log
- worker initiatelog
actionmsg
- message by worker provided
Worker API
Worker is a simple nodejs executable.
It can to talk with a ClusterApp throw standard process.send(msg)
mechanism
Commands transferred by msg.actions
param
For now supports next commands:
stop
- Initiate stopping of the ClusterApprestart
- Initiate restarting of the ClusterApplog
- Transfer some data to ClusterApplog
eventmsg
- Provided data For details you can review sample httpworker in/tests
directory of this repo