You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Javascript Library to easily parallelize your code and execute it
Master Slave architecture
Job distribution via ronund robin
Low latency transfer via sockets.
Pre-requisites
You need a Master server setup with at least 1 slave connected to it
The slaves need not be accessible publicly and can be behind a firewall or NAT
The master should be accessible by the client
Your parallelizable jobs must be defined in a class
Setup
Step 1: Setup Master
importMasterfrom"../server";/** * port used is controlled by process.env.PORT * default value is 3000 * */constmaster=newMaster();
Step 2: Setup Slave
/** * @arg1 URL string * specifies the URL of the master * * @arg2 boolean logging * false by default. set to True to see execution logs * */constslave2=newSlave(process.env.MASTER_URL||"http://localhost:3000",true);
Step 3: Setup Client
importLibraryfrom"../library";import{SlaveResponse}from"../protocol";/** * We define a class with the functions to be distributed across the nodes * The @lib.exec decorator is used to mark a function as ready for distribution * */classJob{
@lib.execstaticsquare(x: number): any{returnx**2;}
@lib.execstaticcube(x: number): any{returnx**3;}
@lib.execstaticsqrt(x: number): any{returnMath.sqrt(x);}
@lib.execstaticarrayMult(x: number[],y: number[]): any{letans=[];for(leti=0;i<x.length;i++){ans.push(x[i]*y[i]);}returnans;}}