Search code examples
node.jsmultithreadinglibuv

worker pool vs libuv's threadpool in node.js


I was reading node.js docs about worker pool and faced two term which I thought both are same - worker pool and libuv's threadpool.

Here is the point of confusion (from node.js doc url):

These are the Node module APIs that make use of this Worker Pool:

I/O-intensive

DNS: dns.lookup(), dns.lookupService().

File System: All file system APIs except fs.FSWatcher() and those that are explicitly synchronous use libuv's threadpool.

Here is my understanding so far:

event loop -> can be considered main thread

worker pool -> which is implemented by libuv, so in that case worker pool thread is actually libuv thread.

So, how workers pool does something without libuv's thread?


Solution

  • The "Worker Pool" and "libuv's threadpool" are the same. The reason you're misunderstanding is due to the formulation of that sentence. As a non-native English speaker myself, I can see why.

    This:

    File System: All file system APIs except fs.FSWatcher() and those that are explicitly synchronous use libuv's threadpool.

    could instead be formulated like this:

    File System: All file system APIs use libuv's threadpool, except fs.FSWatcher() and those that are explicitly synchronous.

    A better formulation can be seen on the docs for UV_THREADPOOL_SIZE cli option, as seen here:

    Node.js APIs that use the threadpool are:

    • ...
    • all zlib APIs, other than those that are explicitly synchronous