An attempt at giving multi process node programs a simple and efficient way to share data.
const cluster = ;const numCPUs = length;const hub = ;if clusterisMaster// Fork workers.for var i = 0; i < numCPUs; i++cluster;elsehub;// emit event to all workershub;
Node.js is a perfect candidate to developing Date Intensive Real-time Applications. Load balancing in these applications can become complicated when having to share data between processes.
A remote database can be an easy solution for this, but it's not the most optimal. Communicating with a local process is several times faster than opening remote requests from a database. And even if the database is hosted locally, the overhead of communicating with yet another program is lessened.
Note that this module is still experimental. It currently works by using a process's internal messaging system.
Clusterhub already comes with a default global hub. Use this if you want to create a custom hub.
Call to disable hub from emitting and receiving remote messages/commands.
Additionally, all functions from the regular EventEmitter are included. Plus a couple of extras.
Use this to emit an event only to the current process.
Use this to emit an event only to other worker processes and master. Or only to workers if the current process is the master.
All functions from EventVat are included as well. Their returned value can be accessed by providing a callback as the last argument. Or optionally by its returned value if called by the master.
var returnedVal = hub;// but since it's the master process it has direct access to the databaseconsole; // true
npm install clusterhub
Tests are written with mocha