node.js - node.js 中的工作池与 libuv 的线程池

标签 node.js multithreading libuv

我正在阅读有关 worker pool 的 node.js 文档并遇到了两个我认为相同的术语 - worker poollibuv'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/

相关文章:

linux - 使用libuv处理unix fifos的方法有哪些?

node.js - ExpressJs、Node Js、Passport - 注销后退按钮

html - Socket.IO - 要求未定义

angularjs - 发出 POST 请求时返回空白 PDF,但可以正常使用 GET

multithreading - QThread::quit() 是否丢弃 EventQueue 中的所有事件?

c++ - C++中的多线程效率

javascript - 以编程方式将文件从 node.js 上传到另一个 Web 服务器

c# - 旋转大量 Timers.Timer 线程

c++ - libuv线程通信

multithreading - 从多线程调用 uv_write,它的回调永远不会被调用