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

jpool

v1.0.3

Published

a threaded queue for node worker threads

Downloads

3

Readme

What is it

Jobs taking seconds to complete over time is expensive in the long run. This library makes it possible to execute thousands of in under a minute! This is the final result.

Installation

npm install jpool

Features

The amount of threads is variable, and all states are deterministic. A job will either pass, fail, or halt. This allows the pool to gracefully shut down or quit abruptly without zombies or runaway processes.

Usage

Clients need at least 2 files. The file that houses the main event loop, and the job file. Jobs are added to the queue by referencing the file name.

Basic example (Main.js)

// create a new pool. Pass options to configure the initial state.
const pool = new Pool({threads: 8});

// add a job to the queue
pool.add(path.resolve(__dirname, 'jobs/findRandomNumber.js'));

// process all jobs in queue and listen for more.
pool.start()

// jobs can be added while pool is running
pool.add(path.resolve(__dirname, 'jobs/findRandomNumber.js'));

// stop the pool
pool.stop()

Basic example (Job.js)

const {parentPort, workerData} = require("worker_threads");

// Run anything. Once the process terminates, then
// the pool will take another item from the queue.
// Calling parentPort.close(); is like resolving a promise
// but it is not required as long as the program terminates normally.

const interval = setInterval(() => {
    if (Math.random() > 0.8) {
        parentPort.postMessage("Found good number")
        clearInterval(interval) // very important!
        parentPort.close(); // optional
    }
}, 1000)

See the difference

Each terminal window is processing the same set of jobs. From left to right, the programs use 1, 8, and 256 workers. Threads increase memory usage, but the benefits are worth it! imgur

Contributions

Please use reasonable coding standards and write a test for everything you change. There should be a test for single-threaded, average-threaded (8 threads), and stress-threaded (256+ threads).

License

MIT