node.js中的事件循环是什么意思? javascript事件循环或libuv事件循环? [英] what is mean by event loop in node.js ? javascript event loop or libuv event loop?
问题描述
在Node.js中,我们谈论事件循环很多,所以我想知道我们正在谈论哪个事件循环,Javascript事件循环还是libuv事件循环? 我猜想libuv事件循环可以为复用I/O的多个操作系统提供抽象吗?我对吗?如果不是这样,请解释一下这些东西是如何工作的?我需要一些内部知识,我知道什么是事件循环,我只想知道它是如何连接的?
In Node.js we a lot talk about the event loop, so I want to know which event loop we are talking about, the Javascript event loop or the libuv event loop ? I guess libuv event loop that provides abstraction for multiple operating system of multiplexing i/o ? Am I right? If not so please explain how this stuff works? I need some internal knowledge, I know what an event loop is, I just want to know how it is connected?
推荐答案
当前,节点使用libuv提供的事件循环-即其默认事件循环:uv_default_loop()
.请参阅:Nikhil Marathe libuv简介:
Currently Node uses the the event loop provided by libuv - namely its default event loop: uv_default_loop()
. See: An Introduction to libuv by Nikhil Marathe:
libuv提供了一个默认循环,可以使用以下命令进行访问 uv_default_loop().如果您只想要一个,则应使用此循环 循环.
A default loop is provided by libuv and can be accessed using uv_default_loop(). You should use this loop if you only want a single loop.
注意:node.js使用默认循环作为其主循环.如果你是 编写绑定时,您应该意识到这一点.
Note: node.js uses the default loop as its main loop. If you are writing bindings you should be aware of this.
设计概述页面上有一个linuv体系结构图.在libuv API文档中:
There is a linuv architecture diagram on the Design overview page in the libuv API documentation:
过去,libev的事件循环是在Node中使用的.请参见了解node.js事件循环高田美纪(Mikito Takada):
In the past, libev's event loop was used in Node. See Understanding the node.js event loop by Mikito Takada:
在内部,node.js依靠libev提供事件循环,该事件循环 由libeio补充,后者使用池线程来提供 异步I/O.要了解更多,请查看libev 文档.
Internally, node.js relies on libev to provide the event loop, which is supplemented by libeio which uses pooled threads to provide asynchronous I/O. To learn even more, have a look at the libev documentation.
有关Node事件循环的一些很好的资源:
Some good resources on the Node event loop:
- 了解node.js事件高田信树(Mikito Takada)的循环
- 了解node.js 费利克斯·盖森德尔弗(FelixGeisendörfer)
- 了解Tre.Norris的Node.js事件循环 /li>
- libhil简介,作者Nikhil Marathe
- libuv API文档
- Understanding the node.js event loop by Mikito Takada
- Understanding node.js by Felix Geisendörfer
- Understanding the Node.js Event Loop by Trevor Norris
- Node.js itself is blocking, only its I/O is non-blocking by Jeremy Epstein
- An Introduction to libuv by Nikhil Marathe
- The libuv API documentation
感谢SaúlIbarraCorretgé在评论中的澄清.
Thanks to Saúl Ibarra Corretgé for the clarification in the comments.
这篇关于node.js中的事件循环是什么意思? javascript事件循环或libuv事件循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!