当前位置:网站首页>5 modes of IO model

5 modes of IO model

2022-06-22 16:29:00 The force is with you


Reference resources :unix Network programming
Preface :

stay LInux Under the system , User space and kernel space can be switched to each other

Blocking IO

Blocking IO: Switch from user space to kernel space , Kernel space is waiting for data to arrive , When the data arrives, it is copied from the network card to the memory , After copying, switch from kernel space to user space , Read . During this process, the user thread has been blocked .( Handling one event cannot handle other events )

Synchronous blocking

Non blocking IO

Non blocking IO: Wait until the data is not blocked , Data is also blocked when it reaches the replication phase .

Synchronous nonblocking

Multiplexing

selector, Stop it first , If something happens, it won't be blocked ;read Also block . It saves time waiting for events .

The essence is also synchronization

Signal driven

asynchronous IO

Threads 1 launch ( Specify the callback method ) -----> Threads 2 To get the results ( After the result comes out, it passes through the thread 1 Method return )
Asynchronism is non blocking .

Sync : The thread initiates the action itself , Get the results yourself .
asynchronous : Thread initiated action , Other threads get results .

Read file write socket flow

 Insert picture description here
java Use direct memory , There is no need to copy between the user buffer and the kernel buffer , in total 3 Time , save 1 Time .

Optimize

linux2.1 Provided sendFile Method ,java Corresponding channel Of transferTo and transFrom Method copy

linux2.4 java Called transferTo After the method , from java From user mode to kernel mode , Use DMA Read data into kernel buffer , Can't use cpu,
Only the user mode and kernel mode are switched , Data from disk to kernel buffer , From the kernel buffer to the network card ,0 Copying is not done java Of memory , Will not occupy cpu Time .DMP Will liberate cpu Time .
0 Copy is suitable for small file transfer .

原网站

版权声明
本文为[The force is with you]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221508060228.html