Is non-blocking I/O really faster than multi-threaded blocking I/O? How?

后端 未结 9 1322
礼貌的吻别
礼貌的吻别 2020-11-29 15:09

I searched the web on some technical details about blocking I/O and non blocking I/O and I found several people stating that non-blocking I/O would be faster than blocking I

9条回答
  •  清歌不尽
    2020-11-29 15:45

    One possible implementation of non-blocking I/O is exactly what you said, with a pool of background threads that do blocking I/O and notify the thread of the originator of the I/O via some callback mechanism. In fact, this is how the AIO module in glibc works. Here are some vague details about the implementation.

    While this is a good solution that is quite portable (as long as you have threads), the OS is typically able to service non-blocking I/O more efficiently. This Wikipedia article lists possible implementations besides the thread pool.

提交回复
热议问题