我正在阅读有关 worker pool 的 node.js 文档并遇到了两个我认为相同的术语 - worker pool
和 libuv's threadpool
。
这里是混淆点(来自 node.js 文档 url):
这些是使用这个 Worker Pool 的 Node 模块 API:
I/O 密集型
DNS: dns.lookup()
, dns.lookupService()
。
文件系统:所有文件系统 APIfs.FSWatcher()
和那些显式同步的 API 都使用 libuv 的线程池。
这是我目前的理解:
事件循环
-> 可以认为是主线程
worker pool
-> 由 libuv 实现,所以在这种情况下,worker pool 线程实际上是 libuv 线程。
那么,在没有 libuv 线程的情况下,worker pool 是如何做的呢?
最佳答案
“Worker Pool”和“libuv's threadpool”是一样的。您误解的原因是该句子的表述。作为一个非英语母语的人,我明白为什么。
这个:
File System: All file system APIs except
fs.FSWatcher()
and those that are explicitly synchronous use libuv's threadpool.
可以这样表述:
File System: All file system APIs use libuv's threadpool, except
fs.FSWatcher()
and those that are explicitly synchronous.
可以在 UV_THREADPOOL_SIZE
的文档中看到更好的公式cli 选项,如下所示:
Node.js APIs that use the threadpool are:
- ...
- all zlib APIs, other than those that are explicitly synchronous
关于node.js - node.js 中的工作池与 libuv 的线程池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50190009/