0.0.3 • Published 5 years ago
hydra-framework v0.0.3
Hydra
Hydra 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.
Install
$ yarn add hydra-frameworkUsage
Master
- Create a task:
// 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 });- Create
Masterinstance and start the server.
// master/index.ts
import { Master } from 'hydra-framework';
import { task } from './tasks/example-task';
const master = new Master({ task });
master.start();Worker
Create Worker instance and connect to Master.
import { NodeWebsocketTransport, Worker } from 'hydra-framework';
const worker = new Worker({
transport: new NodeWebsocketTransport({
url: 'ws://localhost:9000'
})
});
worker.start();Concept
Hydra provides the following entities:
- Master:
- stores
Taskdefinition as well as algorithm to generateSpaceand sub-Spaces; - handles incoming connections from
Workersand stores their current work state; - provides the
Taskdefinition toWorkersas well as sub-Spacesthey should work on; - stores the
Taskcompletion state.
- stores
- Worker:
- connects to
MasterviaTransportand requests aTaskdefinition and a sub-Spaceto work on; - works on a
Taskusing provided definition and a sub-Space; - responds to
Masterwith calculation result.
- connects to
- Transport:
- allows to use
BrowserWebsocketTransportorNodeWebsocketTransportdepending on the environment.
- allows to use
- Task:
- stores
f(x)and aSpace.
- stores
- Space:
- stores
typeof theSpace,valuesarray or a value generator function.
- stores