Cluster multiprocess launcher
bI?
Minimalistic configurable multiprocess launcher for Node.js based on cluster. Includes built-in sticky listeners for Socket.IO.
Installation
npm i cluster-launcher --save
Usage
const launch stickyListenWorker stickyListenMaster } = ; const workerFunc = { // Use express for example. const app = ; const http = ; app; ;}; const masterFunc = { console; ;}; ;
API
.launch(opts)
@param opts { object } options object
Expected that master and worker will call listen
by themselves, because they can contain some async init functions.
Options object
- config { object }
- threads { number } count of worker processes to spawn.
default: 1
- host { object } web server configuration
- ip { string }
default: 'localhost'
- port { number }
default: 8080
- ip { string }
- threads { number } count of worker processes to spawn.
- worker
- main { function } entry point of the every worker, takes
listen
as a parameter - listen { function }
default: stickyListenWorker
- main { function } entry point of the every worker, takes
- master
- main { function } entry point of the master
- listen { function }
default: stickyListenMaster
worker
/master
's main
will be called with specified to them listen function as a parameter.
Worker's listen
Expects http
server object as a parameter.
Master's listen
Will be wrapped in a function that takes no arguments. Because of it in the master's main
you should just do listen()
. But inside it will be called by launch
with options object as a parameter:
- ip { string }
- port { number }
- workers { array }
.stickyListenWorker, .stickyListenMaster
Default built-in listen function for worker, that provide sticky connection for the client to specific worker based on the client's ip address. Usefull for Socket.IO.