Piscina is a Node.js worker thread pool that runs CPU-intensive JavaScript functions across multiple threads for parallel execution. It manages a dynamic pool of worker threads with configurable size, handling task submission, cancellation, and lifecycle management through a promise-based interface.
The pool supports AbortController-based task cancellation, enabling clean termination of submitted or running tasks without disrupting other work. It enforces per-worker memory limits through V8 resource caps and applies backpressure with a configurable maximum queue size that emits a drain event when capacity becomes available. Piscina allows pluggable queue ordering to replace the default FIFO behavior with custom priority or deadline logic, and supports pluggable load balancing algorithms for assigning tasks to workers. Transferable objects like binary buffers can be passed between threads with zero-copy messaging, reducing memory overhead during data transfer.
Additional capabilities include deferred worker readiness through an asynchronous initialization protocol, performance monitoring with run-time and wait-time histograms, thread priority control on Linux, and the ability to customize worker environment setup with native addon loading. Piscina exposes a straightforward API for submitting functions to workers and retrieving results, with documentation and install instructions available through its npm package.