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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-concurrent-worker-tasks

v0.1.3

Published

This library provides a solution for managing concurrent tasks in a Node.js environment. It leverages a combination of worker threads organized into a pool and a task queue system to efficiently execute tasks, ensuring optimal utilization of system resour

Readme

node-concurrent-worker-tasks

This library provides a solution for managing concurrent tasks in a Node.js environment. It leverages a combination of worker threads organized into a pool and a task queue system to efficiently execute tasks, ensuring optimal utilization of system resources and enhancing application performance.

Table of Contents

About

node-concurrent-worker-tasks is specifically designed for Node.js environments and utilizes the native worker_threads module from Node.js (https://nodejs.org/api/worker_threads.html).

Features:

  • Worker Pool Management: Efficiently manages a pool of worker threads, dynamically scaling the pool size based on demand.
  • Task Queue System: Implements a queue mechanism to handle tasks that cannot be processed immediately, ensuring reliable task execution.
  • Dynamic Worker Pool Scaling: Adjusts the worker pool size dynamically to optimize resource utilization.

Installation and usage

  • Install the Worker Pool Module

First, install the worker-pool-task-queue module using npm:

$ npm install node-concurrent-worker-tasks
$ pnpm install node-concurrent-worker-tasks
  • Create a Worker Pool

Import the WorkerPool class from the installed module and set up a worker pool with a specific pool size, worker script file path, and maximum number of workers:

const WorkerPool = require('node-concurrent-worker-tasks');
// Create a worker pool with 30 workers, using 'Worker.js' as the worker script
const TaskPool = new WorkerPool(poolSize = 30, './Worker.js', returnLog = false, memThreshold = 90);
  • Create the Worker.js File in ypur repro containing your functions. Note that functions can be handled in external libraries and classes (fn is representative for your functions, used with a delay in the example)
const { parentPort } = require('worker_threads');

parentPort.on('message', async (message) => {
    const { fn } = message;
    // execute 'myfunc' here, return result in postMessage
    setTimeout(() => {
        parentPort.postMessage({ executed: `function ${fn} true` });
    }, 1000);
});
  • Define and Execute Tasks

Create functions to execute tasks using the worker pool. For example, you can define an executeTask function that runs a specific function called 'myfunc' in the worker pool:

async function executeTask() {
    try {
        const result = await TaskPool.run({ fn: 'myfunc', params: { set: true } });
        console.log(result);
    } catch (error) {
        console.error(error);
    }
}

You can then call this function multiple times using a loop or any other logic as needed:

async function executeTasksMultipleTimes() {
    for (let i = 0; i < 4; i++) {
        await executeTask();
    }
}

executeTasksMultipleTimes();

Output

  • status: 200 - default task
  • status: 429 - concurrent task, maybe add pool extension later
returnLog = false
{
  status: 200,
  result: { 
    execute: true,
    taskId: 'd92fb982-02bc-4af0-a241-869dacb9f6ba',
    capacity: true 
    }
}
returnLog = true
{
  status: 429,
  result: {
    execute: true,
    taskId: 'c0d2085a-8ab8-4aeb-ae37-f734bc65f814',
    log: { worker: '-1-', poolLength: '30 worker', executed: '99 tasks' },
    capacity: true
  }
}

Support

This library used jsdoc types and is tested in Chrome https://www.npmjs.com/package/node-concurrent-worker-tasks

How to Use Apache Benchmark (ab) for Testing

To test the performance of your Node.js application using Apache Benchmark (ab), follow these steps:

Install Apache Benchmark (ab): If ab is not already installed on your system, you can typically install it via your package manager. For instance, on Ubuntu:

sudo apt-get install apache2-utils

Run the Benchmark Test: Open your terminal and use the following command to start testing your application:

ab -n <number_of_requests> -c <concurrent_requests> http://localhost:3000/task
ab -n 100 -c 20 http://localhost:3000/task

This command will send 100 requests to the server, with 20 requests being processed concurrently at any given time.

Interpret the Results: After running ab, it will display various statistics such as requests per second, response times, and the number of failed requests. Use this data to gauge the performance of your application under load.

Changelog

Version 0.1.0:

  • entryTask() > run()

Version 0.0.2:

  • Initial release with worker pool management.
  • Implemented task queue system.
  • Dynamic scaling of worker pool based on demand.