Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can regular file reading benefited from nonblocking-IO?

Tags:

io

nonblocking

It seems not to me and I found a link that supports my opinion. What do you think?

like image 651
Cheng Avatar asked Apr 10 '11 17:04

Cheng


People also ask

Does blocking IO use CPU?

If a process is I/O blocked, the kernel will just set it aside (put it in the "waiting" state) and not even consider giving it time in the CPU. When the I/O has finished, the kernel moves the blocked process from the "waiting" state to the "ready" state so it can have its turn ("running") in the CPU.

What are the differences between a blocking I O and a nonblocking I O?

Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn't block execution.

Is Java blocking or nonblocking?

Java NIO is an asynchronous IO or non-blocking IO. For instance, a thread needs some data from the buffer. While the channel reads data into the buffer, the thread can do something else. Once data is read into the buffer, the thread can then continue processing it.

What do you mean by non-blocking IO?

APIs that use blocking IO will block the thread until data from IO has returned. So what happens when you call a non-blocking API? Very well, it returns instantly and will not block the thread. This means the thread can immediately continue executing the code that comes after calling the API.


2 Answers

The content of the link you posted is correct. A regular file socket, opened in non-blocking mode, will always be "ready" for reading; when you actually try to read it, blocking (or more accurately as your source points out, sleeping) will occur until the operation can succeed.

In any case, I think your source needs some sedatives. One angry person, that is.

like image 111
kqnr Avatar answered Jan 02 '23 20:01

kqnr


I've been digging into this quite heavily for the past few hours and can attest that the author of the link you cited is correct. However, the appears to be "better" (using that term very loosely) support for non-blocking IO against regular files in native Linux Kernel for v2.6+. The "libaio" package contains a library that exposes the functionality offered by the kernel, but it has some caveats about the different types of file systems which are supported and it's not portable to anything outside of Linux 2.6+.

And here's another good article on the subject.

like image 40
Jonathan Oliver Avatar answered Jan 02 '23 20:01

Jonathan Oliver