About Bio | NIO |the discussion of AIO is always there, and sometimes it's easy to confuse, as I understand it, to give an explanation: BIO| NIO |AIO, the description of itself is based on the Java language. While describing IO, we need to start from two levels: the programming language implements the underlying fundamentals from the programming language level bio| NIO |Aio In the Java perspective, understanding, Linux C also has the concept of AIO (library), these concepts do not know what reason is fired up, here only from the Java perspective. BIO, synchronous blocking Io, simple to understand: a connection to a thread NIO, synchronous non-blocking IO, simple understanding: A request for a thread AIO, asynchronous non-blocking IO, Simple understanding: A valid request a thread bio before JDK1.4, write a network request in Java, is to establish a serversocket, and then, the client establishes a socket will ask whether the threads can handle, if not, either wait, or be rejected. That is: A connection that requires the server to correspond to a processing thread. The origin of NiO in Java, in the JDK1.4 and later versions, provides a set of APIs to specifically operate non-blocking I/O, we can find the related classes and interfaces in the Java.nio package and its child packages. Since this API is the new I/O API provided by the JDK, it is also called New I/O, which is the origin of package name NiO. This set of APIs consists of three main components: buffer (buffers), channel (Channels), and non-blocking I/O core classes. When you understand NIO, you need to differentiate between New I/O or non-blocking io,new i/O is a Java package, NIO is a non-blocking IO concept. This is about the latter one. NiO itself is based on event-driven thinking, which is mainly to solve the large concurrency problem of bio: In the use of synchronous I/o in a network application, if you want to handle multiple client requests at the same time, or if the client wants to communicate with multiple servers at the same time, it must be processed using multithreading. That is, each client request is assigned to a thread that is processed separately. While this can meet our requirements, it will also lead to another problem. Since each thread is created, it is necessary to allocate a certain amount of memory (also known as a working memory) to the thread, and the operating system itself has a certain limit on the total number of threads. If the client has too many requests, the server may be overwhelmed to deny requests from the client, or even the servers may be paralyzed. NIO is based on reactor, when the socket has a stream-readable or writable socket, the operating system notifies the reference program to process it, and the application then reads the stream into the buffer or writes to the operating system. In other words, this time, is not a connection to a processing thread, but a valid request, corresponding to a thread, when the connection has no data, there is no working thread to handle. AIO differs from NiO in that it is only necessary to invoke the read or write method of the API directly when doing a read and write operation. Both methods are asynchronous, and for a read operation, when a stream is readable, the operating system streams the readable buffer into the Read method and notifies the application that, for a write operation, the operating system proactively notifies the application when it finishes writing the stream passed by the write method. That can be understood as, readThe/write method is asynchronous and invokes the callback function when it is finished. In JDK1.7, this part of the content is called NIO.2, the following four asynchronous channels are added mainly under the Java.nio.channels package: Asynchronoussocketchannel asynchronousserversocketchannel Asynchronousfil Echannel Asynchronousdatagramchannel One of the readThe/write method returns an object with a callback function when it finishes executing the read/call the callback function directly after the write operation. Implementing the principle of implementation principle, but also from the operating system IO model to understand according to "UNIX Network Programming" division, IO model can be divided into: blocking IO, non-blocking IO, IO multiplexing, signal driven IO and asynchronous Io, according to the POSIX standard is divided into two categories: synchronous IO and asynchronous IO. How do you differentiate it? First IO operation is actually divided into two steps: Initiate IO request and actual IO operation, the difference between synchronous IO and asynchronous IO is whether the second step is blocked, if the actual IO read/write blocking request process, then is synchronous io, so blocking IO, non-blocking IO, io multiplexing, The signal-driven IO is synchronous io, if not blocking, but the operating system to help you do the IO operation and return the results to you, then the asynchronous IO. The difference between blocking IO and non-blocking IO is that the first step is whether the initiating IO request will be blocked, and if blocking until done is the traditional blocking IO, and if it does not block, then it is non-blocking IO. Received the IO model of the operating system and had to mention select/poll/epoll/IOCP, the understanding of these four, not much to explain, they do not understand the place. The explanation is understandable: in Linux2. 6, the implementation of Java NIO is achieved through Epoll, which can be found through the source code of the JDK. AIO, which is implemented through IOCP on Windows, is implemented by Epoll on Linux. Here's one thing to emphasize: AIO, this is I/o processing mode, while Epoll is a programming model for AIO; in other words, AIO is an interface standard that can be implemented or not implemented by each operating system. It is best to use operating system recommendations in high concurrency situations on different operating systems. There is no AIO on Linux that really implements the network way. The bottom layer of the underlying foundation, to say that the Linux system programming, here itself is not familiar with, waiting for Yimeimei to add. Only General said one: AIO implementation on Windows, AIO implementation is done through IOCP, see the source code of the JDK, you can find Windowsasynchronoussocketchannelimpl see implementation interface: Implements Iocp.overlappedchannel again see the implementation method: Inside of the read0/The Write0 method is the native method, called the JVM underlying implementation, the virtual machine technology is unfamiliar, not caught dead. In Linux, the implementation of AIO is through the epoll to complete, look at the JDK source code, you can find that the realization of the source code is: Unixasynchronoussocketchannelimpl See Implementation interface: Implements Port.pollablechannel This is the biggest difference with Windows, poll implementation, after linux2.6, uses Epoll by default. That's understandable. Written in the end: Java development-based, for the underlying knowledge of the operating system is not the C language-based Daniel Good, the language determines the way of thinking, the Ancients did not bully me finally, a few explanations of the Good article: BIO NIO Aionio.2Getting Started, section1section: Asynchronous channel API using asynchronous I/o greatly improves the performance of your application
Also about bio | NIO | AIO (Java Edition--go)