2. Tong brother said five models of IO netty Series

netty

Hello, I am a brother Tong herein, this is the second in the series netty.

Brief introduction

This article will introduce five kinds of linux IO model, but also describes the difference between blocking / non-blocking and synchronous / asynchronous.

What is the IO model

For one IO operation, data is first copied into kernel space, and then copied from the kernel space to user space, so that a read operation, will experience two stages:

(1) wait for data preparation

(2) copy data from user space to kernel space

Based on the above two stages to produce five different IO mode.

Blocking IO

From the process initiated IO operation, we have been waiting for these two phases.

Blocked with two stages.

blocking-io

Non-blocking IO

IO process has been asked not ready, ready to re-initiate a read operation, then and only then copy data from kernel space to user space.

The first phase of polling is not blocked but the second stage blocking.

nonblocking-io

IO multiplexing

A plurality of connections use the same query to select IO ready or not, if there are ready, they return data is ready, then the corresponding connection re-initiate a read operation, the data is copied from the kernel space to user space.

Blocking two separate stages.

multiplexing-io

IO drive signal

The process of initiating a read operation will return immediately, when the data is ready to be told in the form of notification process, the process of re-initiate a read operation, the data is copied from kernel space to user space.

The first stage is not blocked, the second phase of obstruction.

signal-I

Asynchronous IO

The process of initiating a read operation will return immediately, wait until the data is ready and has been copied to the user space to get re-notification process data.

Two stages are not blocked.

asynchronous-io

IO contrast mode

Various IO model year are as follows:

model

Synchronous asynchronous difference is that the operating system call recvfrom (), when not blocked, the visible except the last synchronization are other asynchronous IO IO.

select poll epoll

select limited maximum file descriptors, file descriptors can only listen to a few ready, and have to get through all the file descriptors ready IO.

poll is no limit on the maximum file descriptors, and select, can only listen to a few file descriptor is ready, and have to get through all the file descriptors ready IO.

epoll is no limit on the maximum file descriptors, it is through the callback mechanism, once a file descriptor is ready, and rapid activation of this file descriptors, when the process calls epoll_wait once () when it was notified.

So, when there is plenty of free connection, epoll efficiency is much higher .

Egg

The use of Java nio what kind of IO model it?

A: Java nio in fact new io abbreviation, it uses the IO Model multiplexed .

reference

In this paper, five models IO made a very brief summary, did not understand the students can look at the following article, very detailed.

https://segmentfault.com/a/1190000003063859

Finally, the public is also welcome to come to my number from Tong brother read the source code systematic study of the source code & architecture knowledge.

code

Guess you like

Origin www.cnblogs.com/tong-yuan/p/11854235.html