series

  • Java NIO three roles Channel, Buffer, Selector
  • Scalable IO in Java, translated by Doug Lea
  • Reactor model do you know what they are?
  • Netty server create source code process analysis
  • What exactly is an EventLoopGroup?
  • To be continued..

Creation is not easy, if it is helpful to you, please pay attention to it. If you have any questions, you can exchange private letters. May you thrive in the Year of the Tiger.

The Linux kernel treats all external devices as one file, and reads and writes to a file are called by system commands provided by the kernel, which return a file descriptor (fd).

There is also a descriptor for reading or writing a socket, called a socketfd (Socket descriptor). The descriptor is a number that points to a structure in the kernel (file path, data area, etc.)

UNIX provides five I/O models, as follows:

Blocking the I/O model

Is the most common type of I/O model fan of blocking I/O lines, default cases, all file operations are blocked, the socket interface, for example to explain the model: in the process space call recvfrom, the system calls until packets reach and buffer is copied to the application process or an error occurs when returned, will wait during this time,The process is blocked the entire time from the call to recvFROM until it returns, and is therefore called the blocking I/O model.



Non-blocking I/O model

When recvfrom from the application layer to the kernel, an EWOULDBLOCK error is returned if there is no data in the buffer, and the user thread is given enough CPU time to continue doing other things. The first stage of the user process is not blocked and needs to constantly actively ask if the Kernal data is ready. The second phase is always blocked.



I/O multiplexing model

Linux provides select/poll, and the process blocks the SELECT operation by passing one or more FD’s to the SELECT or poll system call, so select/poll can help us detect whether multiple FD’s are in a ready state.

Select /poll is a sequential scan for fd readiness, and the number of FDS supported is limited, so its use is somewhat limited. Linux also provides an epoll system call, which uses an event-based approach instead of sequential scanning for higher performance and immediately calls back the function ROLLBACK when an FD is ready.





The select/poll | epoll contrast of faults:

The signal drives the I/O model

The socket signal-driven I/O function is enabled first, and a signal-handling function is executed through the system call SIGAction (This system call returns immediately and the process continues to work, non-blocking). When the data is ready, a SIGIO signal is generated for the process, the signal callback notifies the application to call RECvFROM to read the data, and the main loop function to process the data.



Asynchronous I/O

Tell the kernel to start an operation, and let the kernel notify us when the entire operation is complete, including copying data from the kernel to the user’s own buffer. The main differences between this model and the signal-driven model are: ** Signal-driven I/O tells the kernel when to start an I/O operation; The asynchronous I/O model lets the kernel tell us when an I/O operation is complete.





Hi everyone, I am Yigui. Thank you for your thumbs up, collection and comments. I am constantly updating the article and I will see you next time.

You can also add my personal VX for communication: LHJ502819, to make efforts to impact the big factory together. In addition, there are a lot of learning and interview materials for you.