Piscina
A popular npm library that manages a pool of Node.js worker threads, queues tasks for them and returns each result as a promise.
In more detail
It handles minimum and maximum thread counts, task queue limits, timeouts and cancellation, so application code just calls pool.run(task). Its pools can also be closed gracefully, waiting for running tasks to finish.
Related terms
- thread pool — A fixed or bounded set of reusable worker threads that take tasks from a queue, instead of creating a new thread for each task.
- worker threads — The Node.js module for running JavaScript in parallel threads inside one process, each with its own V8 isolate and event loop.
- task queue — A list of jobs waiting to be run, taken off in order by whatever runs them, such as an event loop phase or a pool of worker threads.
Taught in
- Worker Threads: worker_threads & SharedArrayBuffer — Node.js Internals & Backend Services
- Thread Pooling: Piscina & CPU-Bound Workload Pools — Node.js Internals & Backend Services