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

paralio

v1.1.3

Published

Multithreaded Node.js executer

Downloads

11

Readme

Node.js multithreded executer

Classes

Paralio

The Paralio class is the heart of your application.

import { Paralio } from 'paralio'
import { resolve } from 'path'

interface Paralio<Input, Output, Context> {
  max: number // The limit of running processes
  workerPath: string // Path to the worker script
  workers: number // The number of running workers
  input: Input[] // The input data (unchanged)
  output: Output[] // The output array
  _input: Input[] // The consumed input data
  repl: repl.REPLServer // The exposed REPL server
  context: Context // The key-value map passed to every worker
  /*...*/
}

const app = new Paralio({
  max: 4, // defaults to the number of cpus
  workerPath: resolve(__dirname, './worker'),
  input: [], // or you can give it a path to a file: resolve(__dirname, 'input.txt')
  onInputLoaded(rawFile: string) {
    /*process the data*/
    return JSON.parse(rawFile)
  }
})

/* Called after initializing all of the workers */
app.on('start', self => {/*...*/})

/* Called after killing all of the workers */
app.on('end', self => {/*...*/})

/* Called when consuming an item */
app.on('consume', ([items_left, consumed_item]) => {/*...*/})

Worker

The class for worker files.

import { Worker } from "paralio"

interface Worker<MessageType, Context> {
  context: Context // Context passed from the master
  onMessage(msg: MessageType): Promise<any> | void
}

new class extends Worker {
  onMessage(msg) {
    /* It can be either a value or a Promise */
    const output = Process_the_input(msg)
    return output
  }
}()

On using the REPL

Paralio comes a built-in repl to make your (my) life easier. It lets you access the app instance and run some useful commands.

self

You can access the main app instance with the self variable. I.e.: > self.output

.save

Let's you save the output to a specified path (defaults to the cwd).

.rerun

In case you want to rerun your application, here you go!

Motivation

I was basically scraping some information of the wikipedia. It was taking a few minutes to run over just 54 pages. So I thought to myself "What can I do to speed it up?" and the obvious answer came to my mind: multi-threading. The idea itself was brilliant, but I ran into some problems, namely: overloading my cpu with 54 processes... Then I decided to limit the number of processes data at one time and it worked. After that some improvements came to my mind and bada bim, bada boom - Paralio was born.