libuv worker pool
Local practice: Node.js 22.16.0 on Linux x64; proposed teaching baseline 26.13.1 remains untested. Copy only the listed files into a fresh disposable directory. No dependency installation or external services required. These are static Node.js examples, not verified ByteMind runner tasks.
Bound a group of actual file reads
import { readFile } from 'node:fs/promises';const names = ['a.txt','b.txt','c.txt'];for (let i = 0; i < names.length; i += 2) { const group = names.slice(i, i + 2); const values = await Promise.all(group.map(name => readFile(name, 'utf8'))); console.log(values.join(','));}Run:
node main.mjsExpected stdout:
A,BCExit status: 0. Expected stderr: empty.
How it works
Many asynchronous filesystem operations, dns.lookup, selected crypto functions and asynchronous zlib APIs use the pool. Ordinary network socket I/O generally uses OS event notification mechanisms rather than one pool worker for every socket. JavaScript callbacks still execute on their isolate. The documented default pool size is four; UV_THREADPOOL_SIZE can be configured at process startup, but raising it can increase memory use and contention and cannot fix CPU-heavy JavaScript. Bound work before launching it. In the example, batches of two are fully awaited before the next batch; this simple policy trades some utilization for predictable concurrency.
Observe an asynchronous compression result
import { gzip, gunzip } from 'node:zlib';import { promisify } from 'node:util';const compress = promisify(gzip);const expand = promisify(gunzip);const data = await compress('stock:3');console.log((await expand(data)).toString('utf8'));Run:
node main.mjsExpected stdout:
stock:3Exit status: 0. Expected stderr: empty.
Common mistake
Promise.all on thousands of already-created promises is not a concurrency limiter. The pool is shared; flooding it with work can delay unrelated operations. Diagnose the actual queue or bottleneck before tuning.
Practice
Change the batch size to one and three. Explain the largest number of outstanding reads under each policy, without claiming their exact completion times.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
libuv worker pool — knowledge check
Apply the concepts and predict the behavior taught in this lesson.
Which listed task commonly uses the libuv pool?
What is the maximum number of outstanding reads in the batch example?
Will raising the pool size fix CPU-heavy JavaScript on the main isolate?