Piscina, a Node.js worker pool you can read from the outside
A fast, efficient Node.js Worker Thread Pool implementation
At a glance
- What is it?
- Piscina keeps Node.js worker threads busy and exposes the counters behind them. This walk through the pool covers the two Node.js version floors in the repository, named task exports, cancellation, worker readiness, and the numbers you can read off a live pool.
- Who is it for?
- Piscina suits Node.js services whose bottleneck is CPU work spread across many short tasks, and it hands you enough counters to notice when the queue is doing the waiting instead of your code. Before adopting it, check the Node.js version you actually run against the two floors the repository states, and check the licence for the exact release you deploy; the current repository's package manifest and licence file both identify MIT.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- piscinajs/piscina5,245 ★ · +38
| Repository | 2026-09-23 | 2026-11-25 |
|---|---|---|
| piscinajs/piscina | 5.2k | 5.2k |
38 Stars in the last 63 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Node.js 24.x in the README, 22.x in engines
The README states the requirement in one line: For Node.js 24.x and higher. The package manifest is looser. The engines field in package.json reads ">=22.x", so an install on Node 22 passes the engine check without complaint. Both statements sit in the repository, and nothing in the README explains the gap, so a Node 22 team ends up finding out at runtime whether the documented behaviour holds.
The manifest also tells you how the package resolves. main points at ./dist/main.js, types at ./dist/index.d.ts, and the exports map splits by module system: import resolves to ./dist/esm-wrapper.mjs, require resolves to ./dist/main.js. That wrapper is generated by the build script rather than committed, so a fresh checkout with no dist directory has nothing for an import to resolve to.
Two smaller signals about age and ownership: the version field still reads 5.1.1, and the keywords array lists fast, worker threads, thread pool and wade wilson. The default branch is named current, not main.
Two files, one run call, and a filename that resolves
The package name in package.json is piscina, and the smallest setup worth copying is two files on disk. One builds a pool with a filename option and awaits a single call. The other exports the function that runs on the thread.
npm install piscinaconst path = require("path");
const Piscina = require("piscina");
const piscina = new Piscina({
filename: path.resolve(__dirname, "worker.js"),
});
(async function () {
const result = await piscina.run({ a: 4, b: 6 });
console.log(result); // Prints 10
})();module.exports = ({ a, b }) => {
return a + b;
};The filename option is the whole connection between the two halves. Point it at a resolvable path, and the pool loads that module and keeps a reference to the exported function. The README does not spell out what a wrong path produces, or what happens when the worker file throws while loading, so keep a trivial smoke test until the pool is wired into real work.
The name option picks which export runs
One worker file can carry several handlers. The README attaches the extra handlers as properties on the exported function, then selects one per task through the name option of run. Two tasks with different names go to the same file and land on different functions, which lets you drop a small pool of mixed task types behind a single constructor.
"use strict";
function add({ a, b }) {
return a + b;
}
function multiply({ a, b }) {
return a * b;
}
add.add = add;
add.multiply = multiply;
module.exports = add;"use strict";
const Piscina = require("piscina");
const { resolve } = require("path");
const piscina = new Piscina({
filename: resolve(__dirname, "worker.js"),
});
(async function () {
const res = await Promise.all([
piscina.run({ a: 4, b: 6 }, { name: "add" }),
piscina.run({ a: 4, b: 6 }, { name: "multiply" }),
]);
})();Two limits are worth knowing before you commit to this shape. The pattern shown is CommonJS, where handlers hang off the exported function, while the ESM example at the top of the README exports a single default handler. And the tree carries a dedicated examples/multiple-workers-one-file/ directory, which tells you the pattern is supported but not how many names per file are sensible before the file stops loading quickly.
signal or an EventEmitter cancels a queued task
A submitted task can be cancelled by passing a signal in the options object of run. The standard AbortController works, and so does any EventEmitter that emits an abort event, which lets an existing emitter in your service stand in for a controller without wrapping it.
"use strict";
const Piscina = require("piscina");
const { resolve } = require("path");
const piscina = new Piscina({
filename: resolve(__dirname, "worker.js"),
});
(async function () {
const abortController = new AbortController();
try {
const { signal } = abortController;
const task = piscina.run({ a: 4, b: 6 }, { signal });
abortController.abort();
await task;
} catch (err) {
console.log("The task was canceled");
}
})();The example aborts before the task starts, so check the full documentation for what happens to a task that is already running inside a worker when the signal fires. The examples/abort/ directory exists if you want to see how the maintainers exercise the path.
A worker counts as ready only once Piscina holds the handler
A worker thread stays out of rotation until Piscina decides it is ready. By default that happens the moment the pool loads the module and acquires a reference to the exported handler function. When a worker needs to open connections, read configuration, or warm a cache before it can accept anything, the module can export a promise that resolves to the handler instead, and the pool waits on that promise.
The same decision shapes what a handler may look like. It can be a plain function, an async function, or a function returning a promise:
const { setTimeout } = require("timers/promises");
module.exports = async ({ a, b }) => {
// Fake some async activity
await setTimeout(100);
return a + b;
};Work that the handler awaits is part of the task. Work it starts and forgets is not, and the README has a section headed Out of scope asynchronous code for that boundary. The tree also carries examples/async_load/ for the promise-returning form.
drain, needsDrain and queueSize are the pressure gauges
The pool publishes enough counters to tell a busy queue from an idle one. The readonly properties include completed, duration, runTime, waitTime, threads, idleThreads, queueSize, needsDrain and utilization, and the events include error, drain, needsDrain and message. runTime and waitTime are the pair that matters most: a high waitTime with a high queueSize means your tasks are waiting for a thread, while a low waitTime with high runTime means the work itself is slow.
Two README sections, Queue Size and Queue Pressure and Idle Threads, sit under a heading called Performance Notes, so where to tune those numbers is discussed in prose rather than in an option list. The queue implementation is replaceable too: a Custom Task Queues section documents built-in queues including a FixedQueue example, and the tree has examples/task-queue/ and examples/resourceLimits/.
The README's index also has Backpressure and Queue Size sections, which are where to look for queue limits. CPU scheduling priorities are listed as optional on Linux.
Three release tags share one August date
The release list is short and strange: v6.0.0-rc.5, v5.3.2 and v4.9.4 were all published on 28 August 2026, within about a minute of each other. Three lines of a major line, a patch line and a release candidate sharing one date is what a bulk tag or publish looks like, and it means the list tells you little about which line is the one you should pin. The default branch recorded here is current, and the most recent push on it is dated 2 November 2026.
The current branch's package.json identifies the licence as MIT, and the top-level LICENSE contains the MIT text. Check the files for the specific release you distribute; an automated repository classification is not the same thing as the package's licence field.
Documentation lives in two places. The homepage field points at piscinajs.dev, while the README links a generated site at piscinajs.github.io/piscina/. Between them, the API surface you will actually call is small: run, destroy, close, four events, the counter properties, the static flags isWorkerThread and version, and the static move for Transferable values. Benchmark and test commands come from the scripts block, including a queue-only scope:
npm run build
npm run lint
npm run benchmark:queue
npm run benchmark:startupEditorial conclusion
Piscina suits Node.js services whose bottleneck is CPU work spread across many short tasks, and it hands you enough counters to notice when the queue is doing the waiting instead of your code. Before adopting it, check the Node.js version you actually run against the two floors the repository states, and check the licence for the exact release you deploy; the current repository's package manifest and licence file both identify MIT. If your workload is dominated by I/O, a pool of worker threads costs you memory and startup time without much parallelism to show for it.
Frequently asked questions
What is the piscina package in Node.js?
Piscina is a worker thread pool for Node.js written in TypeScript. It keeps worker threads warm, takes work through piscina.run(task), and publishes queueSize, threads, idleThreads and utilization so you can see whether the pool is busy or starved.
Does piscina mean pool in the Node.js ecosystem?
The pool it manages is a set of worker threads. Tasks go in with run(), the pool reports threads, idleThreads and queueSize, and each thread runs the function your worker file exports, or the one your worker file promises.
What does the name piscina mean here?
In this repository the name belongs to a Node.js worker thread pool whose feature set covers cancellation, enforcing memory resource limits, custom task queues and optional CPU scheduling priorities on Linux, with CommonJS, ESM and TypeScript all supported.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/piscinajs-piscina)Star history chart for your README
[](https://hysenlabs.com/projects/piscinajs-piscina)Was this useful?