Node.js Developer interview question · Most asked

What does libuv's thread pool do, and which operations use it?

Summary

libuv maintains a thread pool (default 4 threads, configurable with UV_THREADPOOL_SIZE up to 1024) for operations that lack non-blocking OS APIs: most fs operations, dns.lookup, some crypto functions (pbkdf2, scrypt, randomBytes async) and zlib compression.

Longer Answer

Network I/O (TCP/HTTP sockets) doesn't use the pool; it uses OS event notification. If many slow fs or crypto calls saturate the 4 threads, other pool tasks queue up, causing surprising latency, e.g. DNS lookups delayed by bcrypt hashing. Increase the pool size or move heavy work elsewhere.

Key Points

  • Default 4 threads (UV_THREADPOOL_SIZE)
  • fs, dns.lookup, crypto, zlib
  • Network sockets don't use it
  • Saturation causes hidden latency

More most-asked Node.js Developer questions

← All Node.js Developer questions