何时使用非阻塞I / O?

时间:2021-11-13 20:19:23

I am trying to understand in which cases nodejs will be faster than its pros. I completely understood the terms Asynchronous I/O and non-blocking I/O but cant think of a use case where it is be useful. can somebody give me an example ?

我试图了解nodejs在哪些情况下会比其专业人员更快。我完全理解术语异步I / O和非阻塞I / O,但不能想到它有用的用例。有人可以举个例子吗?

2 个解决方案

#1


3  

Node is a prime example why async I/O is useful.

节点是异步I / O有用的一个主要示例。

Node is (as far as the user is concerned) single threaded, so waiting for synchronous I/O would stop the only thread that is executing code. Since there are no guarantees how long I/O will take, that could/would make Node code run extremely slowly.

节点是(就用户而言)单线程,因此等待同步I / O将停止执行代码的唯一线程。由于无法保证I / O需要多长时间,因此可能会使节点代码运行得非常慢。

That's why Node pretty much uses only async I/O, it allows the single thread to quickly offload I/O work to the operating system while continuing code execution without interruption until the operating system notifies Node that the I/O operation is done.

这就是Node几乎只使用异步I / O的原因,它允许单个线程快速将I / O工作卸载到操作系统,同时继续执行代码而不会中断,直到操作系统通知Node I / O操作完成。

#2


0  

NodeJS is basically a server side coding which is based on single threaded concept, so we have to manage all the I/O and CPU works on this thread itself.

NodeJS基本上是基于单线程概念的服务器端编码,因此我们必须管理此线程本身的所有I / O和CPU工作。

We know, I/O operations are basic blocking operation for the running thread (example: I/O operation may include getting an input from a user, or reading a large file from the data center; this operations may hang up the thread for sometime, which may results in hanging up many client request).

我们知道,I / O操作是正在运行的线程的基本阻塞操作(例如:I / O操作可能包括从用户获取输入,或从数据中心读取大文件;此操作可能会挂起线程一段时间,这可能导致挂起许多客户请求)。

To avoid this above cases, NodeJS came up with the concept of single thread asynchronous non-blocking I/O (also overcoming the overhead of creating multiple threads in case of multi-threading).

为了避免上述情况,NodeJS提出了单线程异步非阻塞I / O的概念(也克服了在多线程情况下创建多个线程的开销)。

#1


3  

Node is a prime example why async I/O is useful.

节点是异步I / O有用的一个主要示例。

Node is (as far as the user is concerned) single threaded, so waiting for synchronous I/O would stop the only thread that is executing code. Since there are no guarantees how long I/O will take, that could/would make Node code run extremely slowly.

节点是(就用户而言)单线程,因此等待同步I / O将停止执行代码的唯一线程。由于无法保证I / O需要多长时间,因此可能会使节点代码运行得非常慢。

That's why Node pretty much uses only async I/O, it allows the single thread to quickly offload I/O work to the operating system while continuing code execution without interruption until the operating system notifies Node that the I/O operation is done.

这就是Node几乎只使用异步I / O的原因,它允许单个线程快速将I / O工作卸载到操作系统,同时继续执行代码而不会中断,直到操作系统通知Node I / O操作完成。

#2


0  

NodeJS is basically a server side coding which is based on single threaded concept, so we have to manage all the I/O and CPU works on this thread itself.

NodeJS基本上是基于单线程概念的服务器端编码,因此我们必须管理此线程本身的所有I / O和CPU工作。

We know, I/O operations are basic blocking operation for the running thread (example: I/O operation may include getting an input from a user, or reading a large file from the data center; this operations may hang up the thread for sometime, which may results in hanging up many client request).

我们知道,I / O操作是正在运行的线程的基本阻塞操作(例如:I / O操作可能包括从用户获取输入,或从数据中心读取大文件;此操作可能会挂起线程一段时间,这可能导致挂起许多客户请求)。

To avoid this above cases, NodeJS came up with the concept of single thread asynchronous non-blocking I/O (also overcoming the overhead of creating multiple threads in case of multi-threading).

为了避免上述情况,NodeJS提出了单线程异步非阻塞I / O的概念(也克服了在多线程情况下创建多个线程的开销)。