Languages and runtimesDive 03 of 08
Where await goes in Node.js
Follow a TCP read and a file read from libuv back into JavaScript. Trace both paths on Linux, then see how a busy event loop and a saturated worker pool delay different requests.
- Levels
- 8
- Reading
- 27 min
- Depth
- Idea to System
- Published
net.SocketKernel reports TCP readinessfs.promises.readFileWorker sends a completionresume after awaitOne keyword, two native paths
Imagine a request handler waiting for two things. It needs bytes from an already open TCP connection and a small settings file from disk. Both results appear to JavaScript as promises. When a file read hangs for half a second, it is tempting to describe the whole process as “blocked on I/O.” The TCP connection may still be serving requests in the same process. Where the file is waiting determines what else can run.
const packet = firstPacket(socket);
const settings = readFile('probe.txt', 'utf8');
const bytes = await packet;
const text = await settings;Here firstPacket stands for a function that resolves a promise when a stream delivers enough bytes. The call to readFile starts the file operation before either await. The order of the two awaits controls when this function observes the results. The file can finish while the function is still waiting for the socket.
await evaluates its operand, obtains a promise, attaches fulfillment and rejection reactions and suspends the async execution context. The caller gets control back. When the appropriate promise reaction runs, the function continues with the value or throws the rejection at the await site. Even an already fulfilled promise gives the continuation a separate job. The JavaScript code before the first suspension runs synchronously. ECMAScript’s Await algorithm
The functions produce the promises and arrange the I/O. The native parts take different routes. A regular TCP read waits for socket readiness from the kernel. A small file read on our runtime queues native work in libuv's shared worker pool. Both routes must return to the event-loop thread that owns the JavaScript context before an await reaction can run. libuv design overview
scratch=$(mktemp -d)
printf '%s\n' "$scratch"
cd "$scratch"
node --versionThe promise tells the function how to resume. The API that produced it determines where the underlying work waits.
A timer has a threshold
A libuv One pass through the work, poll and callback machinery of a single event loop. groups callbacks by source. Among the pieces relevant here are pending callbacks deferred from a previous pass, the poll that gathers ready I/O, the check phase for setImmediate, and timer processing. libuv also has prepare, idle and close callbacks. When the loop has nothing ready, the poll can sleep until I/O wakes it or a timer makes it necessary to return. Work can already be ready before poll begins. libuv loop iteration
A timer registers a delay threshold. Node clamps a delay of 0 to 1 millisecond. Once that threshold passes, the timer can run at the next opportunity to process it. A callback already executing, queued work, scheduling in the OS and polling all affect the actual delivery time. With libuv 1.45 and later, the normal Unix loop's timer pass is after poll and check. There is also a compatibility timer pass when entering uv_run(UV_RUN_DEFAULT). Node timer API · Pinned Unix loop implementation
setImmediate schedules a callback in check. When you schedule it and a zero-delay timeout inside this file callback, check can run the immediate before the new timer. When you move the same pair to the main module body, starting conditions and the timer threshold can change which one runs first. The source of the callback matters more than a memorized order of API names. Node’s scheduling example
const { readFile } = require('node:fs');
readFile(__filename, (error) => {
if (error) throw error;
console.log('file callback');
setTimeout(() => console.log('timeout'), 0);
setImmediate(() => console.log('immediate'));
queueMicrotask(() => console.log('microtask'));
process.nextTick(() => console.log('nextTick'));
});file callback
nextTick
microtask
immediate
timeoutDownload phases.cjs and run node phases.cjs in the scratch directory. The file read reads the script itself. The two lines between the file callback and the immediate are the work Node and V8 drain at the callback boundary.
A timer can be overdue while the event loop is busy. Its delay is the earliest eligibility threshold.
Who runs at a callback boundary?
Node owns a dedicated process.nextTick queue. V8 owns the microtask queue used by promise reactions, async continuations and queueMicrotask. Neither is a libuv phase. When normal native-to-JavaScript callback execution unwinds to Node's outer boundary, Node drains pending ticks and gives V8 a microtask checkpoint. During that checkpoint V8 can run jobs added by other microtasks. When microtasks schedule ticks, Node can process those ticks after the checkpoint. Node’s callback scope · Node’s queue drain
The boundary is the important part. CommonJS entry in this example starts in synchronous module evaluation. ES module entry is evaluated while Node is already processing microtasks. A tick queued from that ES module body waits until the active microtask drain completes. A regular I/O callback in an ES module still uses the callback boundary described above. Node’s CommonJS and ES module examples
console.log('start');
async function resume() {
await 0;
console.log('await');
}
resume();
queueMicrotask(() => console.log('queueMicrotask'));
process.nextTick(() => console.log('nextTick'));
console.log('body returned');start
body returned
nextTick
await
queueMicrotaskstart
body returned
await
queueMicrotask
nextTickDownload queues.js.txt and run the command shown above each capture. Both entry contexts print body returned before await. The continuation for await 0 was queued before queueMicrotask because the adopted value is already fulfilled.
Repeatedly queuing a tick from a tick can keep that drain busy. An unbounded chain of promise jobs can keep the V8 checkpoint busy too. await Promise.resolve() gives other microtasks a chance to run, while the loop can still be waiting to reach poll or check. To let those phases run between chunks of CPU work, schedule the next chunk via setImmediate. The chunk still occupies the loop while it executes. Node’s guide to partitioning callbacks
Predict queue order from the boundary the code is running inside. A new microtask can join a drain that's already in progress.
The socket becomes readable
The experiment makes a loopback TCP connection and sends the ASCII bytes wire. The listener accumulates chunks until it has all four bytes. TCP supplies an ordered byte stream. A message can span multiple reads even when the sender made one write. This capture happened to deliver the entire message in one read.
On Linux, libuv watches the nonblocking socket with epoll. The socket descriptor identifies kernel state for this connection. A readiness notification tells libuv it can try to read the socket. The read syscall copies available bytes into the supplied user-space buffer. A racing reader or a state change can leave no bytes available by then, so the nonblocking code also handles EAGAIN. EOF and errors have their own handling. macOS and BSD use kqueue, and Windows has completion-based IOCP. Linux poll backend · libuv Unix stream implementation
Node's native stream adapter delivers that read into JavaScript. Here the flowing net.Socket calls a data listener, which fulfills the promise that the async function is waiting on. V8 then resumes that function in a promise job. The bytes can accumulate in the kernel while JavaScript is occupied, and a busy loop can postpone both the read syscall and the application callback. Node’s stream read adapter
For this TCP read the kernel announces readiness, then libuv reads and delivers the bytes on the loop thread.
A worker reads the file
A regular file's readiness can't tell you when the backing storage will deliver the next data. A synchronous file syscall can wait in the kernel, even when user code requested a nonblocking descriptor. Node moves the wait to a worker for this async file operation. A page-cache hit can make the read fast, but the job still needs a worker. libuv file operations
In this release fs.promises.readFile(path) has a small-file fast path when it can use its own buffer and normal filesystem bindings. It creates a ReadFileJob that opens, stats, reads and closes the small regular file during one pool turn. The worker uses synchronous libuv file calls inside that job. For a file larger than one chunk, Node can return an open descriptor and the size from the first job, then use separate chunked reads. Passing an existing FileHandle takes its own read path. These choices are implementation details and affect what an async trace shows. Node’s readFile dispatch · ReadFileJob in v26.13.0
libuv queues work on a process-wide pool. The worker that finishes the job adds it to the owning loop's completion queue and calls uv_async_send. In the Linux capture it writes to an A Linux file descriptor backed by a kernel counter. A write can make the descriptor readable and wake a poller. which the loop also watches via epoll. The notification tells the loop to inspect its queue. One notification can cover multiple completions, and the bytes of the file travel in memory. Node's completion turns the result into a JavaScript value and resolves a promise back on the loop. libuv completion dispatch · libuv wakeup mechanism
This is the path the trace confirms on this runtime. Linux libuv has also supported io_uring for eligible filesystem operations. Starting in libuv 1.49, filesystem operations default back to the pool and the io_uring mode requires opting in at the loop level. Node’s captured ReadFileJob explicitly submits worker work. libuv’s version and configuration notes
The kernel still does the file I/O. The worker is where the blocking call waits, and the original loop is where JavaScript handles its result.
Find the continuation in the trace
Take one run and follow the evidence on each side of the native boundary. strace -f reports syscalls across threads and labels them with Linux thread IDs. The script prints the process ID, which is also the main thread's ID. async_hooks reports JavaScript-facing resource IDs. Those are a separate numbering system. The script marks the current async ID in each listener and continuation so you can match it to a before event for that resource. Node async hook callbacks
- Kernel
- libuv
- Node
- V8
Bytes enter the socket buffer
3553276 write(23<socket:[26857945]>, "wire", 4) = 4Readiness tells the loop where to look
3553276 epoll_pwait(15<anon_inode:[eventpoll]>, [{events=EPOLLIN, data=0x16}], 1024, 0, NULL, 8) = 1
3553276 read(22<socket:[26857944]>, "wire", 65536) = 4Deliver a chunk to the stream listener
before TCPWRAP #12
socket data callback #12Run the reaction that resumes await
before PROMISE #17
after await socket #17: wire- The accepted peer writes four bytes over loopback. The receive buffer belongs to the kernel.
- In this poll result, 0x16 is descriptor 22. libuv then reads the bytes on the loop thread. epoll supplies the readiness event, and read supplies the bytes.
- The data listener runs under the TCP resource and fulfills the promise wrapping the four-byte message.
- The continuation runs in promise context #17, after the callback that fulfilled its input promise.
- Node
- Worker
- libuv
- V8
Submit one ReadFileJob
init FSREQCALLBACK #21 trigger #6Read the file and post the completion
3553283 openat(AT_FDCWD<$scratch>, "probe.txt", O_RDONLY|O_CLOEXEC <unfinished ...>
3553283 <... openat resumed>) = 22<$scratch/probe.txt>
3553283 statx(22<$scratch/probe.txt>, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0664, stx_size=5, ...}) = 0
3553283 read(22<$scratch/probe.txt>, "file\n", 5) = 5
3553283 close(22<$scratch/probe.txt>) = 0
3553283 write(19<anon_inode:[eventfd]>, "\1\0\0\0\0\0\0\0", 8) = 8Collect the result on the owning loop
3553276 epoll_pwait(15<anon_inode:[eventpoll]>, [{events=EPOLLIN, data=0x13}, {events=EPOLLIN, data=0x15}, {events=EPOLLOUT, data=0x16}], 1024, 0, NULL, 8) = 3
3553276 read(19<anon_inode:[eventfd]>, "\1\0\0\0\0\0\0\0", 1024) = 8
before FSREQCALLBACK #21Run the reaction that resumes await
before PROMISE #22
before PROMISE #23
after await file #23: file- Node creates resource #21 for the small-file job. FSREQCALLBACK is the native resource label even when the caller uses fs.promises.
- Thread 3553283 opens, stats, reads and closes the file. When the job returns to libuv, the worker signals descriptor 19.
- The loop at TID 3553276 consumes the eventfd wakeup and drains its work-completion queue. Node enters the completion for resource #21.
- Promise #22 belongs to the internal file-read path. Promise #23 is the continuation logged after the application's await.
Thread 3553283 opens, stats, reads and closes probe.txt. It then writes to eventfd 19. Thread 3553276 reads that notification, handles resource #21 and reaches the file's continuation #23. Later the loop's poll reports readable socket descriptor 22 in hexadecimal as 0x16. The loop reads its four bytes, dispatches the TCP listener under #12 and runs continuation #17. Linux reused descriptor 22 for the TCP client after the file closed.
The FSREQCALLBACK name identifies the native request resource for this small-file path, even though our API returns a promise. init PROMISE #17 trigger #15 tells us which resource triggered creation of the socket continuation. The before line and application marker show when it ran. Neither ID encodes a libuv phase or time spent in a queue.
Combined syscall excerpt and hook output
3553283 openat(AT_FDCWD<$scratch>, "probe.txt", O_RDONLY|O_CLOEXEC <unfinished ...>
3553276 <... write resumed>) = 29
3553283 <... openat resumed>) = 22<$scratch/probe.txt>
3553283 statx(22<$scratch/probe.txt>, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0664, stx_size=5, ...}) = 0
3553283 read(22<$scratch/probe.txt>, "file\n", 5) = 5
3553283 close(22<$scratch/probe.txt>) = 0
3553283 write(19<anon_inode:[eventfd]>, "\1\0\0\0\0\0\0\0", 8) = 8
3553276 epoll_pwait(15<anon_inode:[eventpoll]>, [{events=EPOLLIN, data=0x13}, {events=EPOLLIN, data=0x15}, {events=EPOLLOUT, data=0x16}], 1024, 0, NULL, 8) = 3
3553276 read(19<anon_inode:[eventfd]>, "\1\0\0\0\0\0\0\0", 1024) = 8
3553276 write(1<routes.txt>, "before FSREQCALLBACK #21\n", 25) = 25
3553276 write(1<routes.txt>, "before PROMISE #22\n", 19) = 19
3553276 write(1<routes.txt>, "before PROMISE #23\n", 19) = 19
3553276 write(1<routes.txt>, "after await file #23: file\n", 27) = 27
3553276 write(1<routes.txt>, "before PROMISE #26\n", 19) = 19
3553276 accept4(21<socket:[26857943]>, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 23<socket:[26857945]>
3553276 write(1<routes.txt>, "init TCPWRAP #29 trigger #9\n", 28) = 28
3553276 write(23<socket:[26857945]>, "wire", 4) = 4
3553276 epoll_pwait(15<anon_inode:[eventpoll]>, [{events=EPOLLIN, data=0x16}], 1024, 0, NULL, 8) = 1
3553276 read(22<socket:[26857944]>, "wire", 65536) = 4
3553276 write(1<routes.txt>, "before TCPWRAP #12\n", 19) = 19
3553276 write(1<routes.txt>, "socket data callback #12\n", 25) = 25
3553276 write(1<routes.txt>, "before PROMISE #17\n", 19) = 19
3553276 write(1<routes.txt>, "after await socket #17: wire\n", 29) = 29Node v26.13.0 | uv 1.52.1 | pid 3553276
init PROMISE #4 trigger #1
init PROMISE #5 trigger #1
init PROMISE #6 trigger #4
init PROMISE #8 trigger #7
before PROMISE #4
init PROMISE #11 trigger #5
before PROMISE #11
before PROMISE #6
init TCPWRAP #12 trigger #6
submit socket and file
init PROMISE #14 trigger #6
init PROMISE #15 trigger #6
init PROMISE #17 trigger #15
init PROMISE #18 trigger #6
init PROMISE #19 trigger #6
init PROMISE #20 trigger #6
init FSREQCALLBACK #21 trigger #6
init PROMISE #22 trigger #20
init PROMISE #23 trigger #19
init PROMISE #24 trigger #6
init PROMISE #25 trigger #14
init PROMISE #26 trigger #18
init PROMISE #27 trigger #24
before FSREQCALLBACK #21
before PROMISE #22
before PROMISE #23
after await file #23: file
before PROMISE #26
init TCPWRAP #29 trigger #9
before TCPWRAP #12
socket data callback #12
before PROMISE #17
after await socket #17: wire
before PROMISE #25
before PROMISE #27Reproduce the socket and file trace
Download routes.cjs to the scratch directory. The synchronous logging avoids creating extra asynchronous resources inside the hook. The observer changes timing and the operating system may interleave the two operations differently on your run. Match the operations and their thread IDs even if the file and socket finish in a different order. To inspect the JS markers alone, run node routes.cjs probe.txt after creating the fixture.
printf 'file\n' > probe.txt
UV_THREADPOOL_SIZE=1 strace -f -y -s 100 -o trace.log \
-e trace=epoll_ctl,epoll_pwait,accept4,read,write,openat,close,newfstatat,fstat,statx \
node routes.cjs probe.txt > routes.txt
cat routes.txt
rg 'probe.txt|epoll_pwait|eventfd|"wire"' trace.logconst { createHook, executionAsyncId } = require('node:async_hooks');
const { once } = require('node:events');
const { writeSync } = require('node:fs');
const { readFile } = require('node:fs/promises');
const { createConnection, createServer } = require('node:net');
const log = (message) => writeSync(1, `${message}\n`);
const kinds = new Set(['TCPWRAP', 'FSREQCALLBACK', 'FSREQPROMISE', 'FILEHANDLECLOSEREQ', 'PROMISE']);
const resources = new Map();
const hook = createHook({
init(id, kind, trigger) {
if (!kinds.has(kind)) return;
resources.set(id, kind);
log(`init ${kind} #${id} trigger #${trigger}`);
},
before(id) {
if (resources.has(id)) log(`before ${resources.get(id)} #${id}`);
},
destroy(id) {
resources.delete(id);
},
});
async function main() {
const file = process.argv[2];
if (!file) throw new Error('Pass the path of a scratch fixture');
log(`Node ${process.version} | uv ${process.versions.uv} | pid ${process.pid}`);
hook.enable();
const server = createServer((peer) => peer.end('wire'));
server.listen(0, '127.0.0.1');
await once(server, 'listening');
const client = createConnection({ host: '127.0.0.1', port: server.address().port });
async function fromSocket() {
const payload = await new Promise((resolve, reject) => {
let text = '';
client.once('error', reject);
client.setEncoding('utf8');
client.on('data', (chunk) => {
log(`socket data callback #${executionAsyncId()}`);
text += chunk;
if (text.length === 4) resolve(text);
});
});
log(`after await socket #${executionAsyncId()}: ${payload}`);
}
async function fromFile() {
const contents = await readFile(file, 'utf8');
log(`after await file #${executionAsyncId()}: ${contents.trimEnd()}`);
}
log('submit socket and file');
try {
await Promise.all([fromSocket(), fromFile()]);
} finally {
hook.disable();
client.destroy();
server.close();
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});A syscall trace identifies where the native work ran. A resource trace shows where JavaScript re-entered.
Two ways to delay a callback
Imagine every read has slowed down. To tell where the wait lives, use three probes from the same point in the program: data sent on an already connected loopback socket, a read of a warmed small file, and a 10 ms timer. Each timestamp is taken when the matching JavaScript continuation executes. The file and socket can be ready earlier than their timestamps suggest.
In the CPU run, a synchronous loop holds the JavaScript thread for 220 ms after the probes are registered. In the pool run, the script submits an async pbkdf2 job ahead of the file read. Setting UV_THREADPOOL_SIZE=1 before launch makes the file wait behind that one job. The idle run supplies a baseline with the same pool size. The two load durations differ because the spin uses a time limit and PBKDF2 uses a fixed iteration count. Node’s async PBKDF2 API · libuv thread pool sizing
The loop delivers the TCP and file results within a few milliseconds. The 10 ms timer is the last probe to resume.
- TCP data
- 3.38 ms
- File result
- 2.48 ms
- 10 ms timer
- 10.85 ms
- Max loop sampling interval
- 13.36 ms
- libuv workers
- 1
The synchronous JS spin keeps the loop occupied. The file, TCP and timer continuations all run after it returns.
- TCP data
- 223.42 ms
- File result
- 222.88 ms
- 10 ms timer
- 223.47 ms
- Spin ends
- 222.34 ms
- Max loop sampling interval
- 233.83 ms
- libuv workers
- 1
The sole worker runs PBKDF2 first. The file waits while the loop is free to deliver the TCP and timer results.
- TCP data
- 4.11 ms
- File result
- 437.88 ms
- 10 ms timer
- 11.50 ms
- PBKDF2 done
- 437.77 ms
- Max loop sampling interval
- 14.15 ms
- libuv workers
- 1
With the busy loop, the timer set for 10 ms arrives more than 200 ms after its threshold, and both I/O paths are held up too. With the busy pool, the TCP and timer probes complete early while the file waits about 438 ms. The same warmed file took 2.48 ms in the idle run. The known order of the two pool submissions explains the extra wait.
The default pool has four threads. Async crypto, compression and OS name lookup can share it with file jobs. Configuring the pool size in the process environment at startup lets the setting take effect before the first use. More workers can reduce queuing when there is spare CPU or useful I/O concurrency. Keep track of CPU load, memory and downstream storage contention when you try it. A pool setting has no way to preempt a long JavaScript callback. Node’s UV_THREADPOOL_SIZE setting
Reproduce the three load captures
Download pressure.cjs to the scratch directory and start a fresh process for each workload. The output is JSON. Its ms fields are elapsed wall-clock time from the shared probe start. A different machine will finish the key-derivation job in a different amount of time.
for mode in idle cpu pool; do
UV_THREADPOOL_SIZE=1 node pressure.cjs "$mode"
doneconst { pbkdf2 } = require('node:crypto');
const { once } = require('node:events');
const { readFile } = require('node:fs/promises');
const { createConnection, createServer } = require('node:net');
const { monitorEventLoopDelay, performance } = require('node:perf_hooks');
const { setTimeout: sleep } = require('node:timers/promises');
const { promisify } = require('node:util');
const derive = promisify(pbkdf2);
const mode = process.argv[2];
const spinMs = 220;
const iterations = 1_800_000;
const round = (value) => Math.round(value * 100) / 100;
async function main() {
if (!['idle', 'cpu', 'pool'].includes(mode)) throw new Error('Use idle, cpu or pool');
const server = createServer();
server.listen(0, '127.0.0.1');
await once(server, 'listening');
const connected = once(server, 'connection');
const client = createConnection({ host: '127.0.0.1', port: server.address().port });
const [peer] = await connected;
// Warm the same file and initialize the pool before the measured window.
await readFile(__filename);
const loop = monitorEventLoopDelay({ resolution: 10 });
loop.enable();
await sleep(50);
const ms = {};
const start = performance.now();
const mark = (event) => { ms[event] = round(performance.now() - start); };
// In pool mode the single worker receives this before readFile's open.
const work = mode === 'pool'
? derive('probe', 'scratch', iterations, 32, 'sha256').then(() => mark('workDone'))
: undefined;
const socket = once(client, 'data').then(() => mark('socket'));
const file = readFile(__filename).then(() => mark('file'));
const timer = sleep(10).then(() => mark('timer'));
peer.write('probe');
if (mode === 'cpu') {
const stop = performance.now() + spinMs;
while (performance.now() < stop) { /* Hold the JavaScript thread. */ }
mark('workDone');
}
await Promise.all([socket, file, timer, work]);
// Let the monitor's timer record the stalled interval before reading it.
await sleep(25);
loop.disable();
console.log(JSON.stringify({
node: process.version, uv: process.versions.uv,
poolSize: process.env.UV_THREADPOOL_SIZE ?? 'default',
mode, ms, loopMaxMs: round(loop.max / 1e6),
}));
client.destroy();
peer.destroy();
server.close();
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});A blocked loop delays the delivery of unrelated work. A full pool primarily delays jobs that need one of its workers.
Measure the queue you suspect
monitorEventLoopDelay({ resolution: 10 }) samples the time between monitor callbacks. With this interval mode, an idle process already reports values near 10 ms. The histogram is in nanoseconds, so divide by a million for milliseconds. Our monitor warms up for 50 ms to establish a previous sample before the probes start, and runs for another 25 ms after the probes finish. Clearing a histogram resets the previous timestamp in this version. If you reset it immediately before blocking the loop, the first post-block callback may only establish the new starting point and leave the stall out of your sample. Node’s loop delay API · Histogram sampling and reset
Track loop delay alongside operation-level latency. If TCP, file and timers all drift together and the loop delay is high, look for long synchronous callbacks, sync I/O, GC pauses or scheduling delays. Compare with a CPU profile and performance.eventLoopUtilization() over the same window. Utilization describes time the loop spends outside its poll provider. A synchronous call can keep that metric high while the thread waits and uses little CPU. Event-loop utilization API
If loop delay and direct TCP timings stay near baseline while file or crypto operations slow down, inspect what those operations share. App-level elapsed time combines queueing, service time and delivery back to JavaScript. To separate them you need more evidence, such as controlled pool load, traced worker activity or an application-level scheduler where you can measure submission and start independently. Slow service and a full queue can produce the same await duration.
For substantial CPU-bound JavaScript, node:worker_threads provides separate JavaScript threads with their own V8 isolates and event loops. That API is distinct from libuv's native worker pool. Node workers in the same process still share the libuv pool for applicable native operations. A worker running your JavaScript can free the main loop to serve sockets, while sending large messages or creating workers per tiny task can introduce other costs. Node’s worker_threads API · libuv’s process-wide pool
When an await takes longer than expected, measure both the operation that produces the promise and the loop that delivers its result.
End of Node.js event loop · 8 levels, Idea to System
Where to next
Next in Languages and runtimes · 04 of 08
Go concurrency, from go keyword to OS thread
What makes goroutines and channels different, the patterns they unlock and the bugs they invite, then down through the G-M-P scheduler, the inside of a channel, OS threads and the netpoller, to the two instructions that make stacks growable.