npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tiemma/sonic-distribute

v1.0.3

Published

Accelerate your DB backup and restore processes

Downloads

3

Readme

sonic < distribute >

image

Accelerate your linear processes with MapReduce.

CodeQL Node.js CI

What does this do?

It sets up a cluster of workers with a single master node and deploys each task to each worker, adds the results to a queue and processes that based on the specification of your reduce operation.

In simple terms, it's a framework for MapReduce based on Node's cluster.

How to use it

  • Install the package
  • Create the masterFn, workerFn and reduceFn methods
  • Call the MapReduce method with the functions and a set of args
  • Process the final output as needed

Install the package

To install the package, run

npm install --save @tiemma/sonic-distribute

Create the masterFn, workerFn and reduceFn methods

Create a set of methods which implement the Master, Worker and Reduce tasks.

Note the signatures of the methods during your implementation

export type MasterFn = (workerQueue: Queue, args: any) => any;
export type WorkerFn = (event: MapReduceEvent, args: any) => any;
export type ReduceFn = (resultQueue: Queue) => any;

Call the MapReduce method with the functions and a set of args

Then proceed to import and call the MapReduce method as desired

import {MapReduce} from "@tiemma/sonic-distribute";

//...describe masterFn, workerFn and reduceFn methods
// the workerFns are pipelined ... event.data -> workerFn[0] -> workerFn[1] ... workerFn[n-1] -> response
const response = await MapReduce(masterFn, [workerFn], reduceFn, { response: ....anything, numWorkers: desired_number_of_workers})

NOTE: The arg numWorkers is reserved to specify the desired number of workers to deploy

Process the final output as needed

Due to the nature of the fork, you would be required to access the output of the MapReduce operation as so:

import {MapReduce, isMaster()} from "@tiemma/sonic-distribute";

//...describe masterFn, workerFn and reduceFn methods
const response = await MapReduce(masterFn, [workerFn], reduceFn, { response: ....anything, numWorkers: desired_number_of_workers})
if(isMaster()) {
    //....process response output of map reduce
}

Environment variables

You can configure the environment to use the QUIET environment variable if you choose to not see any logs.

Why did I do this?

I was working on another package to assist with logical dumps of database tables in the required foreign key order.

This package was born out of the need to optimise the performance of the linear dump process in a configurable way.

Best Practices

Synchronization is your job

The entire framework serves to make it easy to just focus on your distributed processing tasks.

There is a good focus on preserving processing order hence why the result is queued, rather than sorted.

Any synchronization primitives required by you across workers would need to be implemented by you.

Since the fork is process based, I advise external systems capable of locking based on some shm e.g sqlite file db, some instance of zookeeper etc.

All of this is left to you to implement.

If you have some method by which it can be simply implemented here, do create a PR using the ISSUE TEMPLATE here.

Future Plans

Multi-master and tagged worker setups

There might be a case to run multiple masters and support pushing jobs to certain tagged workers with various workerFns based on the pipeline workers job feature described above.

This is an async pipeline and would be effectively represented by DAGs with various logic for traversing across job in either the worker or reduce stage and across those stages respectively.

If you have some method by which it can be simply implemented here, do create a PR using the ISSUE TEMPLATE here.

Debugging

By default, logs are shown.

If you prefer no logs, kindly set the QUIET env variable.

export QUIET=true

I found a bug, how can I contribute?

Open up a PR using the ISSUE TEMPLATE here