Giter Site home page Giter Site logo

pwm's Introduction

Maintainability Test Coverage

PWM - Parallel Worker Manager

PWM is a node.js worker manager for distributed batch processing.

Features

  • Maintains constant amount of workers
  • Automatically manages batch data collection

Installation

yarn add parallel-wm

Create worker file:

// worker.js
const { Worker } = require('parallel-wm')
const worker = new Worker(
  ({ a, b }) =>
    new Promise((resolve, reject) => {
      resolve(a + b)
    })
)
module.exports = worker

Fetching batches on demand:

Create main file:

// index.js
const PWM = require('parallel-wm')

const getBatch = async () => {
  if (_done >= 100) return []
  let a = []
  for (let i = 0; i < n; i++) {
    a.push({ a: Math.random(), b: Math.random() })
  }
  _done += n
  inputs = inputs.concat(a)
  return a
}

const pwm = new PWM({
  path: 'path/to/worker.js',
  workers: 10,
  nextBatch: () => getBatch(10),
  done: ({ input, output }) => {
    if (output.error) {
      return console.error(error)
    }
    console.log(output.result, output.stats)
  },
})

Process array:

Create main file:

// index.js
const PWM = require('parallel-wm')

const pwm = new PWM({
  path: 'path/to/worker.js',
  workers: 10,
  queue: [{ a: 1, b: 2 }, { a: 0, b: 1 }],
  done: ({ input, output }) => {
    if (output.error) {
      return console.error(error)
    }
    console.log(output.result, output.stats)
  },
})

Output Format

  • result: response from the Worker task if any
  • error: error if any
  • stats:
    • started: timestamp in JS date format
    • finished: timestamp in JS date format
    • ms: how much operation took in ms

Roadmap

  • Basic features
  • Processing speed stats
  • Export Worker from index file
  • Static array processing

pwm's People

Contributors

valeriavg avatar

Watchers

 avatar  avatar

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.