4 ms·
No the network sockets are set to non block and will return E_AGAIN once you have emptied the kernel buffer. Thats still non blocking. I dont think he is using
by justincormack 16y ago
No the network sockets are set to non block and will return E_AGAIN once you have emptied the kernel buffer. Thats still non blocking.
I dont think he is using aio_* which Linux does not really implement usefully.
- kingkilr 16y agoPython doesn't provide an API to aio_* because they're basically useless (on Linux at least).
- rdtsc 16y agoNo. They would return E_AGAIN after the data has been read or written in blocking mode. If select comes back and says "read is ready on socket 4" then user code does read on socket 4 and gets (say) 4K of data followed by E_AGAIN. Getting that 4K of data happens in a blocking mode. To make it non-blocking you would provide a pointer to your user space buffer to the kernel and it would determine when IO is ready _and_ proceed to put that data in the buffer.
- haberman 16y agoThe way you are using the term "blocking" is non-standard and not that useful. You are calling the syscall "blocking" just because it performs its work inline (in this case, copying a kernel buffer into a user-space buffer). By this definition, every syscall is blocking, even aio_read() because even aio_read() performs some work inline (namely enqueing a read request). In common usage, an I/O operation is considered "blocking" if the system call does not return until data is available. If on the other hand you set O_NONBLOCK on a fd, you will get EAGAIN when no data is available, so clearly that is the accepted meaning of "nonblocking."
- rdtsc 16y ago> You are calling the syscall "blocking" just because it performs its work inline. Yes because there is _another_ mode of IO where it doesn't have to do that. So the reason that is called "blocking" is because there is another mode of operation (albeit it is exotic) where the process does not block while performing IO -- the kernel reads/writes the data on behalf of the process. If this second mode of performing IO did not ever exist you could just interchange arbitrarily asynchronous and non-blocking as synonyms. Since you didn't bother reading the link I posted here is the basic matrix of IO operations: Synchronous Asynchronous Blocking read/write select/[e]poll Non-Blocking O_NONBLOCK+E_AGAIN aio_* There has been talk and various attempt at implementing aio_* style IO for network sockets on Linux, but nothing good so far. > Even aio_read() performs some work inline (namely enqueing a read request). Enqueuing the read request is not the same as actually copying gigabytes or terabytes of data from disk where the actual work is performed.
- tptacek 16y agoI think the DeveloperWorks article you've cited is simply wrong, and that's sent you into a tailspin. Select and poll aren't "ways to implement asynchronous blocking I/O". I think you'll find these links more helpful than the misleading one you've been using. http://www.circlemud.org/~jelson/software/fusd/docs/node36.html http://www.circlemud.org/~jelson/software/fusd/docs/node36.h... http://people.freebsd.org/~hmp/stuff/docs/freebsd_kse.pdf http://people.freebsd.org/~hmp/stuff/docs/freebsd_kse.pdf I could always be wrong about this stuff; maybe I'm the one with the broken semantics. But I'm pretty sure I'm not.
- haberman 16y ago> Since you didn't bother reading the link I posted here is the basic matrix of IO operations. Actually I did. You are misinterpreting what it is saying. The reason it is calling the select() model "blocking" is because you block during the select(), not because the read() itself is blocking. This is also non-standard usage: most people wouldn't refer to a select()-based loop as blocking I/O, because a program generally only calls select() when it has nothing else to do but service I/O, so the select() does not "block" the application.
- tptacek 16y agoA process blocks when it needs to be rescheduled, yielding back to the process scheduler pending I/O. That's what "block" means. It doesn't mean "all the time consumed by any operation performed by the process". For instance, a process doesn't "block" when a hash table lookup unexpectedly trends O(n) due to collisions. On a nonblocking socket, the I/O operations you're talking about are simple u/k and k/u buffer copies. I think between aio_+ and the C10k page, you may have gotten a bit scrambled. Whether you have an event loop or not, disk I/O is often transparently blocking, even when you try to set descriptors nonblocking. But I/O operations on a nonblocking socket don't wait the process. If there's data in the buffer, you get the data; if there isn't, you get the error.
- rdtsc 16y ago> On a nonblocking socket, the I/O operations you're talking about are simple u/k and k/u buffer copies. But because there is an IO mode where these copies are done by the kernel when data arrives not by the user process (after a kernel notification), there is now a differentiation between blocking and asynchronous. Asynchronous refers to IO readiness notifications, "blocking" refers to the copying of data (the actual IO if you will). > A process blocks when it needs to be rescheduled, yielding back to the process scheduler pending I/O. That's what "block" means. However when your process is copying data it is in the running state and preventing other processes from running. It could be doing something else or it let other processes run in the meantime. > The I/O operations you're talking about are simple u/k and k/u buffer copies. That is true, however if the data comes in very small chunks very fast you are doing a lot of switching to user space and a lot of small context switches to, say copy 1K of data. When you could just request that the kernel fill up your 10MB buffer with data from a socket and tell you when it is ready. If there is anything I learned is to never just say "it is a simple copy". Today's memory is not very fast compared to CPU speeds and copying is not something to be taking lightly. It is one thing when looking at a toy example, another thing when dealing with realtime systems or large data sets.
- tptacek 16y agoI don't believe that "blocking" refers to the copying of data. I don't believe that a process can be "blocking" and "running". Where are you getting this from?
- jessedhillon 16y agoI think you are confusing the definitions of non-blocking IO and memory-mapped IO.
- rdtsc 16y agoI am not talking about in-kernel hardware mechanisms like DMA and such. Or about memory mapping a file. It is about the system call interface to perform IO. Yeah, I guess you can call it memory-mapped but I don't think that is quite accurate in this context.
- tptacek 16y agoThe system call interface to perform I/O cannot be described as "memory mapped"; the read/write system calls are programmed I/O. The opposite of memory mapped. You're letting terminology get you into trouble. You should just let go of your definitions and make the broader point you're trying to make, which might still be salvageable.
- rdtsc 16y agoI agree, "memory mapped" is the wrong term. I was just letting the original poster who called it this way keep that as a concession or a mental model. That was my mistake as it just confuses everyone even more.