Skip to content
Avarok-CybersecurityPublic

About

Drop-in replacement for piscina 5.3.2: a Node.js worker thread pool with a lock-free shared-memory core, in plain JS (default) or Rust/WebAssembly, passing piscina's own test suite unmodified.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

61 Commits

Folders and files

vortex

vortex

A drop-in replacement for piscina 5.3.2: a Node.js worker thread pool with a lock-free shared-memory core.

Same API, same options, same events. piscina's own test suite runs against it unmodified and passes. MIT OR Apache-2.0.

npm CI license node piscina speed

Quick start  ·  Migrating from piscina  ·  Benchmarks  ·  Limits  ·  FAQ  ·  Website: vortex.avarok.net


What it is. vortex runs JavaScript functions on a pool of Node.js worker_threads, with the public interface of piscina 5.3.2: run(), close(), destroy(), abort signals, move(), task queues, custom load balancers, histograms and every option piscina accepts. Underneath, queues, placement, completion and worker accounting live in one SharedArrayBuffer. Workers take tasks from their own inbox in shared memory, and small arguments and results (undefined, null, booleans, numbers, strings up to 240 UTF-8 bytes) never touch a MessagePort.

Status. Version 0.1.1, on npm. The shared-memory core comes in two implementations of one specification: plain JavaScript (the default) and Rust (no_std, no allocator, no locks) compiled to WebAssembly, chosen with core: 'rust'. piscina's suite passes on both, and every benchmark below is reported for both.

Quick start

npm install @avarok/vortex   # Node.js 20 or newer
// worker.js
module.exports = ({ a, b }) => a + b;

// main.mjs
import Piscina from '@avarok/vortex';
const pool = new Piscina({ filename: new URL('./worker.js', import.meta.url).href });
console.log(await pool.run({ a: 4, b: 6 })); // 10
await pool.close();

CommonJS works the same way: const Piscina = require('@avarok/vortex'). The named exports are piscina's: Piscina, move, isWorkerThread, workerData, FixedQueue, ArrayTaskQueue and the symbols.

Migrating from piscina

Change the import. Nothing else.

- const Piscina = require('piscina');
+ const Piscina = require('@avarok/vortex');
- import { Piscina } from 'piscina';
+ import { Piscina } from '@avarok/vortex';
  • piscina options are unchanged. Same names, same defaults, same validation and the same error messages; worker files written for piscina run as they are.
  • spin (vortex only, default true): an idle worker spins briefly, adaptively and at most 50 µs, before it sleeps. spin: false turns that off.
  • core (vortex only, default 'js'): 'rust' runs the pool on the Rust/wasm core instead. Both implement the same memory layout and protocol (docs/design/10-core-spec.md); a differential test holds them to byte-identical results. On the measured cells the Rust core was as fast or faster, by up to 2× at 8 threads (below).
  • Known differences are listed, every one, in docs/COMPAT.md. The two most likely to matter: maxThreads is capped at 2047, and at most 4096 tasks are in flight at once (the default balancer never reaches that limit unless maxThreads × concurrentTasksPerWorker exceeds it).

Benchmarks

Measured on one machine: Apple M4 Pro (12 cores, 8P + 4E), 48 GB, macOS, Node.js v22.23.3, both vortex cores (build ce, commit e90e5f4). Fixed iterations (echo 200,000 tasks, obj 100,000, spin50 40,000, 1,024 in flight; latency 20,000 sequential round trips). Every cell runs in a fresh process, with a warmup and five repetitions, all implementations interleaved within each repetition. A load gate (1-minute load under 15, no CI job on the machine) was checked before and after every cell; none was discarded. Pools run at minThreads = maxThreads = threads, library defaults otherwise.

Throughput in tasks per second, median of five, in the order vortex JS core, vortex Rust core, piscina, tinypool, workerpool. echo at 4 threads: 622k, 686k, 131k, 207k, 182k; at 8 threads: 274k, 559k, 107k, 182k, 163k. obj at 4 threads: 405k, 428k, 123k, 202k, 176k; at 8 threads: 227k, 355k, 102k, 181k, 155k. spin50 at 4 threads: 74.9k, 74.7k, 55.7k, 56.1k, 55.8k; at 8 threads: 143k, 142k, 80.9k, 97.6k, 89.7k. Sequential round-trip latency in microseconds, p50 / p99, in the order vortex JS core, vortex Rust core, piscina, tinypool, workerpool. 4 threads: 4.4 / 12.1, 4.4 / 10.7, 11.7 / 19.9, 10.3 / 17.2, 9.5 / 17.4. 8 threads: 4.5 / 13.2, 4.5 / 12.1, 13.7 / 24.3, 10.6 / 17.6, 9.5 / 18.0.

Median of five repetitions. Bold marks the best in that row.

workload threads vortex, JS core (default) vortex, Rust/wasm core piscina 5.3.2 tinypool 2.2.0 workerpool 10.0.3
echo, tasks/s 4 622k 686k 131k 207k 182k
echo, tasks/s 8 274k 559k 107k 182k 163k
obj, tasks/s 4 405k 428k 123k 202k 176k
obj, tasks/s 8 227k 355k 102k 181k 155k
spin50, tasks/s (ideal 80k) 4 74.9k 74.7k 55.7k 56.1k 55.8k
spin50, tasks/s (ideal 160k) 8 143k 142k 80.9k 97.6k 89.7k
latency p50, µs 4 4.4 4.4 11.7 10.3 9.5
latency p50, µs 8 4.5 4.5 13.7 10.6 9.5
latency p99, µs 4 12.1 10.7 19.9 17.2 17.4
latency p99, µs 8 13.2 12.1 24.3 17.6 18.0

echo returns its argument, obj returns a small object (it travels through the port), spin50 busy-waits 50 µs. On these workloads both vortex cores had higher throughput than the other three pools in every cell (1.3–5.2× piscina, 1.25–3.3× tinypool) and the lowest p50 and p99 latency. The JS core is the slower of the two at 8 threads (echo 274k against 559k, obj 227k against 355k) and its 8-thread throughput varies between runs (echo 270k–381k over five repetitions); the cause has not been investigated yet.

Raw data, one line per cell with CPU, Node version and load: bench/results/cores-t4.jsonl and cores-t8.jsonl (the run also measured every intermediate build). Method, fix series and step-by-step analysis: docs/design/09-bench.md. One script draws the charts and the table from the jsonl (bench/charts.json); CI fails if they differ:

node scripts/bench-charts.mjs bench/charts.json assets

How the four compare

vortex piscina tinypool workerpool
API piscina 5.3.2's, tested by piscina's suite its own piscina-like, not identical its own
Version measured 0.1.0 (pre-release) 5.3.2 2.2.0 10.0.3
Licence MIT OR Apache-2.0 MIT MIT Apache-2.0
Task transport shared-memory slots for small values, postMessage otherwise postMessage postMessage postMessage

What this does not prove

  • No "fastest" claim beyond these cells. One machine (Apple M4 Pro), one OS (macOS), one Node.js version (22.23.3), four workloads, 4 and 8 threads, library defaults. Not measured: Linux or x86, Node.js 20 or 24, payloads over 240 bytes beyond obj, transfer lists, abortable tasks, custom balancers, concurrentTasksPerWorker > 1, atomics: 'async', many pools in one process, long mixed workloads.
  • Most of the latest gain is one shim change, not the core. Step by step: the Rust core's call-cost work took echo at 4 threads from 395k to 432k; waking the main thread by port message alone (no Atomics.waitAsync) took it to 686k and p99 from 28 to 11 µs.
  • Builds before commit 9a39534 can hang: a lost wake-up in the main thread's completion wait (both cores; 2 of 40 cold obj cells). Fixed; modelled in loom_main_wait.rs.
  • 0.1.0 can hang in destroy(); fixed in 0.1.1. With source maps enabled (--enable-source-maps, or the tsx loader), Node can lose a terminate() that lands while V8 compiles code from a string (eval, new Function), and the worker keeps running. This is Node's behaviour; piscina 5.3.2 is exposed too. 0.1.1 repeats terminate() until the worker exits: 0 of 3200 runs on each core, against 28 (Rust core) and 45 (JS core) before the fix: docs/design/08-node-shim.md §8.8.

Compatibility

piscina 5.3.2's test suite is vendored unmodified in compat/piscina-5.3.2/ (pinned by sha256) and runs against vortex and against piscina itself through the same harness. On Node.js 22.23.3 (macOS, arm64): 154 tests, 149 pass, 5 skipped, 0 fail, for both. The skips are the suite's own conditions (nice tests that run only on Linux or Windows, Node.js 24-only dispose tests, a test for machines with at most 8 CPUs). The same counts hold on Node.js 20.20.2 and 25.1.0. The Node.js 24-only tests have not been run against vortex yet.

npm run build && node scripts/compat.mjs vortex 4   # vortex
node scripts/compat.mjs piscina 4                   # piscina, same harness

How it works

  • js/src/core: the core interface (CoreApi) and the JS core, the default.
  • crates/vortex-core: the Rust core. no_std, no allocator, no locks, no I/O. A worker can die at any instruction and the core recovers its tasks. Checked with loom models, property tests and native stress tests in crates/vortex-core-tests.
  • crates/vortex-wasm: the core compiled for wasm32-unknown-unknown with shared memory, behind a flat FFI. No wasm-bindgen.
  • js/src: the TypeScript shim that is piscina's interface: options, queues, balancers, abort, histograms, async resources, close and destroy.

Design notes, proofs and measurements: docs/DESIGN.md.

Questions people ask

Is vortex a drop-in replacement for piscina? For piscina 5.3.2, yes: change the import. piscina's own suite passes unmodified; the differences we know of are in docs/COMPAT.md.

Is it faster than piscina? On the measured cells (Apple M4 Pro, Node.js 22.23.3, 4 and 8 threads), throughput was 1.3–5.2× piscina's, and p50 and p99 latency were the lowest of the pools measured. Nothing else has been measured.

Which core should I use? Both pass the same suite. core: 'rust' was as fast or faster on every measured cell, up to 2× at 8 threads.

Does it need Rust at runtime? No. The core ships as a .wasm file inside dist/. Rust is needed only to build from source.

How do I build it from source? npm ci && npm run build in a clone. That needs the Rust toolchain pinned in rust-toolchain.toml, with the wasm32-unknown-unknown target.

Which Node.js versions? 20 and newer (engines). The piscina suite has been run on 20.20.2, 22.23.3 and 25.1.0.

Contributing and security

See CONTRIBUTING.md and the code of conduct. Report vulnerabilities privately, as described in SECURITY.md.

vortex is a project of Avarok Cybersecurity.

License

Licensed under either of

at your option. Material from piscina and Node.js is credited in THIRD-PARTY-NOTICES.md; see also NOTICE.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Drop-in replacement for piscina 5.3.2: a Node.js worker thread pool with a lock-free shared-memory core, in plain JS (default) or Rust/WebAssembly, passing piscina's own test suite unmodified.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages