Helps in passing messages within a cluster between
- Master to worker(s)
- Worker to other worker(s)
Install
$ npm install mp-unit
Usage
Always call the mp-unit.init
function for master and all worker processes.
Make sure that the mp-unit.init
function for the master is called after the cluster has been created.
let os = ;let mpu = ;let cluster = ;let totalWorkers = 3; { const tabString = '\t\t\t'; console;} let FUN_KEY = "CHECK";let MSG_MAP = FUN_KEY: { ; return Promise; }; { mpu;} ifclusterisMaster forlet i = 0;i<totalWorkers;++i cluster; ;else ifclusterisWorker ; ; mpu ;
Every key in the MSG_MAP
object corresponds to a promise-based function, as shown in the above example,
FUN_KEY
is mapped to fun
. Keys in MSG_MAP
corresponds to the message that is being thrown
around in the cluster.
The above example shows how a single worker can ask all worker processes (including itself)
to execute a function. Even though every worker process is trying to ask all worker processes
to execute the fun
function, mp-unit
module makes sure that only a single call goes to all processes.
Thus, working as though only a single process called the sendToSiblings
(Worker-To-Workers) function.