Skip to content
Optimal Lab

Node.js · interactive

The libuv thread pool

Your JavaScript runs on one thread, but some async calls run on a small pool of worker threads: 4 by default. Fill the pool with slow crypto and watch a quick file read wait its turn.

Main thread

your JS + event loop

Work queue

3 waiting

Thread pool

4/4 busy

OS kernel

epoll / kqueue

Timeline

  • crypto.pbkdf2
  • fs.readFile
  • dns.lookup
  • http.get
Thread 1
hash 1hash 5
Thread 2
hash 2hash 6
Thread 3
hash 3read
Thread 4
hash 4

Tick 0: all 7 calls start at once. 4 get a thread, 3 wait in the queue.

Work

Tick 0 of 8
  1. 1

    The call returns at once. The work itself happens somewhere else, and your callback or promise waits for it.

    crypto.pbkdf2 · crypto.pbkdf2 · crypto.pbkdf2 · crypto.pbkdf2 · crypto.pbkdf2 · crypto.pbkdf2 · fs.readFile

  2. 2

  3. 3

  4. 4

  5. 5

In production

Tools and technologies

Any runtime with one event loop needs somewhere to put blocking work: a pool, a worker, or the OS.

Not tied to one language — use these names when you search docs or design a system.