Piscina is a Node.js library that pools worker threads to run CPU-heavy work off the main thread. It targets Node.js 24.x and higher.
Overview
Piscina is a Node.js worker pool built on worker threads. Applications dispatch tasks to a pool of threads; each worker runs an exported function from a separate file and returns results to the main process.
The pool supports fixed and variable workloads, configurable minimum and maximum thread counts, idle timeouts, and queue limits including automatic backpressure when the queue is full. Tasks can be canceled with AbortController or EventEmitter abort signals, and the pool tracks run and wait time statistics.
Developers can use custom task queues, enforce per-worker memory limits through Node worker resource options, and optionally lower thread scheduling priority on Linux and Windows when the nice module is installed. CommonJS, ESM, and TypeScript worker modules are supported, including multiple named exports per worker file.
Piscina integrates with async tracking, emits drain and error events, and can broadcast messages across workers via BroadcastChannel on supported Node versions. It was created to encourage correct worker-thread usage after operational issues from spawning too many threads.
Key features
- Fast inter-thread communication
- Flexible minimum and maximum pool sizes
- Task cancellation via abort signals
- Run and wait time statistics
- Enforceable worker memory limits
- Custom and built-in task queues
- CommonJS, ESM, and TypeScript workers
- Optional Linux and Windows thread priorities
Use cases
- Parallel CPU-intensive Node.js workloads
- Offloading computation from the main thread
- Streaming data into a bounded worker queue
- Running multiple handler exports from one worker file
- Pooling workers with delayed readiness after init