GithubHelp home page GithubHelp logo

shenfe / clusterun Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 11 KB

๐Ÿ’  Run tasks in cluster mode easily, for CPU-intensive programs.

License: MIT License

JavaScript 100.00%
nodejs cluster cluster-computing multiprocessing parallel-programming

clusterun's Introduction

clusterun

๐Ÿ’  Run tasks in cluster mode easily, for CPU-intensive programs.

Installation

$ npm install clusterun --save

Usage

function clusterun

Master => Workers => Master

const { clusterun, registerTask, dispatchTask } = require('clusterun');

const runner = function () {
    // run by Master, to create tasks, register and dispatch them to Workers
};

const handler = async function (taskName, taskData) {
    let result;
    // run by Workers, to process tasks and produce results
    return result;
};

const callback = function (taskName, taskSourceData, taskResultData) {
    // run by Master, to handle task results
};

clusterun(runner, handler, callback, {
    clusterNumber: 2, // number of clusters; optional; default: number of CPU
    autoRestart: true, // whether to restart a dead Worker automatically; optional; default: false
});

function registerTask

Register a type of task, with a hash-of-task-data function. Called by Master.

registerTask('my-computing-task', aHashCodeFunctionForTaskData);

function dispatchTask

Dispatch a task to Worker. Called by Master.

dispatchTask('my-computing-task', taskData);

helper functions

name function usage
whoami check the role of the current process, and output logs if any role = whoami()
whoami('computing task A')
ifMaster run if the current is Master ifMaster() && doSth()
ifMaster(doSth)
ifWorker run if the current is Worker ifWorker() && doSth()
ifWorker(doSth)

License

MIT

clusterun's People

Contributors

shenfe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

xiachuan7890

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.