NodeJS 真的是单线程的吗? [英] Is NodeJS really Single-Threaded?
问题描述
Node.js 解决了每个连接一个线程的问题";通过将基于事件的模型置于其核心,使用事件循环而不是线程.所有昂贵的 I/O 操作总是异步执行,并在启动的操作完成时执行回调.
Node.js solves "One Thread per Connection Problem" by putting the event-based model at its core, using an event loop instead of threads. All the expensive I/O operations are always executed asynchronously with a callback that gets executed when the initiated operation completes.
Observation IF any Operation 发生时由epoll()
等多路复用机制处理.
The Observation IF any Operation occurs is handled by multiplexing mechanisms like epoll()
.
我现在的问题是:
为什么NodeJS在使用阻塞系统调用时不阻塞选择/epoll/kqueue?
Why doesn't NodeJS block while using the blocking Systemcalls select/epoll/kqueue?
或者根本不是 NodeJS 单线程,所以第二个线程是
有必要用 select/epoll/kqueue 观察所有的 I/O 操作吗?
Or isn't NodeJS single threaded at all, so that a second Thread is
necessary to observe all the I/O-Operations with select/epoll/kqueue?
推荐答案
NodeJS is evented(来自 网站的第二行a>),不是单线程的.它在内部处理执行 select/epoll/kqueue 处理所需的线程,而无需用户明确管理,但这并不意味着其中没有线程使用.
NodeJS is evented (2nd line from the website), not single-threaded. It internally handles threading needed to do select/epoll/kqueue handling without the user explicitly having to manage that, but that doesn't mean there is no thread usage within it.
这篇关于NodeJS 真的是单线程的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!