1. @akryum/tinypool
A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features
@akryum/tinypool
Package: @akryum/tinypool
Created by: aslemammad
Last modified: Fri, 17 Feb 2023 00:28:28 GMT
Version: 0.3.1
License: MIT
Downloads: 142,634
Repository: https://github.com/aslemammad/tinypool

Install

npm install @akryum/tinypool
yarn add @akryum/tinypool

Tinypool - the node.js worker pool šŸ§µ

Piscina: A fast, efficient Node.js Worker Thread Pool implementation

Tinypool is a fork of piscina. What we try to achieve in this library, is to eliminate some dependencies and features that our target users don't need (currently, our main user will be Vitest). Tinypool's install size (38KB) can then be smaller than Piscina's install size (6MB). If you need features like utilization or NAPI, Piscina is a better choice for you. We think that Piscina is an amazing library, and we may try to upstream some of the dependencies optimization in this fork.

  • āœ… Smaller install size, 38KB

  • āœ… Minimal

  • āœ… No dependencies

  • āœ… Physical cores instead of Logical cores with physical-cpu-count

  • āŒ No utilization

  • āŒ No NAPI

  • Written in TypeScript, and ESM support only. For Node.js 14.x and higher.

In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an RFC

Example

In main.js:

 import Tinypool from 'tinypool'

const pool = new Tinypool({
  filename: new URL('./worker.js', import.meta.url).href,
})

const result = await pool.run({ a: 4, b: 6 })
console.log(result) // Prints 10

In worker.js:

 export default ({ a, b }) => {
  return a + b
}

API

We have a similar API to Piscina, so for more information, you can read Piscina's detailed documentation and apply the same techniques here.

Additional Options
  • isolateWorkers: Default to false. Always starts with a fresh worker when running tasks to isolate the environment.
  • workerId: Each worker now has an id ( <= maxThreads) that can be imported
    from tinypool in the worker itself (or process.__tinypool_state__.workerId)

Authors


Mohammad Bagher

Credits

The Vitest team for giving me the chance of creating and maintaing this project for vitest.

Piscina, because Tinypool is not more than a friendly fork of piscina.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code