Poolio
=> a versatile process pool for Node.js
- create a pool of N workers
- define the start script for each worker in the pool
- kill workers after each task and automatically generate a new worker on exit, or more likely, reuse the same workers for the lifecycle of the worker pool.
- dynamically add or remove workers at will
This module behaves much like these two pre-existing modules:
- core: https://nodejs.org/api/cluster.html#cluster_cluster_setupmaster_settings
- userland: https://github.com/thisandagain/fork-pool
This module strives for a better implementation and simpler API. Like the above, this lib utilizes a child_process pool, using child_process.fork() like so:
const cp = ;const n = cp;
Installation
npm install -S poolio
Basic Use
const Pool = ; // in the current process, we initialize a poolconst pool = filePath: 'child.js' //path is relative to root of your project, but it's best to pass in an absolute path size: 3; { return pool ; } // in a child process - simple example process;
Advanced use
// in the parent process, we require the module and initialize a pool const Pool = ; const pool = filePath: 'child.js' //path is relative to root of your project size: 5; { return pool; // return the promise} // in a child process - advanced example const _ = ;const domain = ; process;