Distributed computing for Node.js.
npm install hydra-frameworkHydra is a distributed computing framework for Node.js and browsers. It provides a way to distribute calculation of some arbitrary function f(x) over arbitrary space S between many computation nodes (browsers or other Node.js processes) connected to master node via websockets.
``bash`
$ yarn add hydra-framework
1. Create a task:
`ts
// master/tasks/example-task.ts
import { Space, Task } from 'hydra-framework';
function f(x: number): boolean {
return x * x === 64;
}
const space = new Space({
values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
});
export const task = new Task({ f, space });
`
2. Create Master instance and start the server.
`ts
// master/index.ts
import { Master } from 'hydra-framework';
import { task } from './tasks/example-task';
const master = new Master({ task });
master.start();
`
Create Worker instance and connect to Master.
`ts
import { NodeWebsocketTransport, Worker } from 'hydra-framework';
const worker = new Worker({
transport: new NodeWebsocketTransport({
url: 'ws://localhost:9000'
})
});
worker.start();
`
Hydra provides the following entities:
- Master:
- stores Task definition as well as algorithm to generate Space and sub-Spaces;Workers
- handles incoming connections from and stores their current work state;Task
- provides the definition to Workers as well as sub-Spaces they should work on;Task
- stores the completion state.Master
- Worker:
- connects to via Transport and requests a Task definition and a sub-Space to work on;Task
- works on a using provided definition and a sub-Space;Master
- responds to with calculation result.BrowserWebsocketTransport
- Transport:
- allows to use or NodeWebsocketTransport depending on the environment.f(x)
- Task:
- stores and a Space.type
- Space:
- stores of the Space, values` array or a value generator function.