node.js 中的工作池与 libuv 的线程池
worker pool vs libuv's threadpool in node.js
我正在阅读 node.js 关于 worker pool 的文档,遇到了两个我认为相同的术语 - worker pool
和 libuv's threadpool
。
这里是混淆点(来自 node.js 文档 url):
这些是使用此工作池的节点模块 API:
I/O-intensive
DNS: dns.lookup()
, dns.lookupService()
.
文件系统:所有文件系统 API 除了 fs.FSWatcher()
和那些显式同步的 API 都使用 libuv 的线程池。
这是我目前的理解:
event loop
-> 可以认为是主线程
worker pool
-> 它是由 libuv 实现的,所以在这种情况下工作池线程实际上是 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 关于 worker pool 的文档,遇到了两个我认为相同的术语 - worker pool
和 libuv's threadpool
。
这里是混淆点(来自 node.js 文档 url):
这些是使用此工作池的节点模块 API:
I/O-intensive
DNS: dns.lookup()
, dns.lookupService()
.
文件系统:所有文件系统 API 除了 fs.FSWatcher()
和那些显式同步的 API 都使用 libuv 的线程池。
这是我目前的理解:
event loop
-> 可以认为是主线程
worker pool
-> 它是由 libuv 实现的,所以在这种情况下工作池线程实际上是 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