当前位置:网站首页>Differences among bio, NiO and AIO
Differences among bio, NiO and AIO
2022-07-03 05:10:00 【Li Dabao】
One 、BIO、NIO、AIO characteristic
1、BIO The feature of is to access one client at a time , Create a thread on the server to serve the client , So if there are many clients , It will correspond to thousands of server threads , This will lead to excessive load on the server , Even stuck .
2、NIO It's synchronous non blocking io, Client side and server side through channel( passageway ) Communications , Multiplexing is realized
- 1. One client corresponds to one channel, Then multiplexer selector Will poll channel
- 2. Then when a request comes ,selector To create worker threads and buffer,
- 3. The worker thread will pass through buffer from channel Read the request and process it
- 4. And then pass after processing buffer Return data to channel, This thread will be released after the request is read and written
3、AIO yes NIO The upgrade , It realizes asynchronous non blocking , asynchronous IO Is based on event and callback mechanisms
Two 、buffer、channel、selector Relevant concepts
buffer It's actually a container , Internally, it is stored by a continuous byte array I/O The data on the , stay nio in ,channel In the file 、 Reading or writing data on the network must pass buffer
selector Used to detect channel Is there any on I/O events , And check the I/O The event shall be handled accordingly , So through a selector Threads can be implemented on multiple channel Management of , You don't have to Each thread creates a thread , Avoid the waste of thread resources and the overhead caused by context switching between multiple threads .seletor Only in channel When there is a read-write event on , Will call I/O To read and write , It can greatly reduce the system overhead , Improve the concurrency of the system
3、 ... and 、select、poll、epoll
- fd What is it? ? fd Both file descriptor- File descriptor .Java Use objects to represent input and output streams, etc ... stay Linux The system is not object-oriented , Everything is documented , Take the file to represent the input and output stream
- select: Its pattern is like this : The program side hands over the file descriptor set to select System call ,select After traversing each file descriptor, it returns the file descriptors that can be operated , Then the program traverses the operable file descriptor again for reading and writing .
- poll: Store a set of file descriptors in a linked list
- epoll: The kernel passes through mmap Realize shared space , There is a space shared between user mode and kernel mode , File descriptor fd There is a shared space to realize user state and kernel state sharing .epoll There are three calls , User space first epoll_create Prepare a space mmap, A red and black tree is maintained inside , The kernel state registers the connection into the red black tree ,epoll_ctl write in . When the data is ready , call epoll_wait Interrupt blocking , Take the list fd, Then call... Separately read.mmap application :kafka Realize data passing socket The process of saving to the server file is also mmap.
Four 、 cache I/O、 Memory mapped files and zero copies
- User mode : The user program runs in user mode , There are many restrictions in user mode . For example, the hardware cannot be operated directly 、 Create and switch threads 、 Open up memory and other operations ( Security ), These operations need to be completed in kernel mode
- Kernel mode : It can directly operate the hardware resources of the system , User mode can be converted to user mode through system call . For example, user mode io operation 、 Switching threads enter the kernel state through system calls kernel( kernel ) Accomplished
- For caching I/O, A read operation will have 3 Secondary data copy , disk 》 Kernel cache 》 User cache 》 Application memory
- For caching I/O, A write operation will have 3 Secondary data copy , Application memory 》 User cache 》 Kernel cache 》 disk
Memory mapped files : When the user no longer has physical memory , Directly map the logical memory address of the application to Linux The kernel buffer of the operating system , Although the application reads and writes its own memory , But this memory is just a logical address , What is actually read and written is the kernel buffer
read : disk 》 Kernel buffer
Write : Kernel buffer 》 disk
边栏推荐
- (subplots用法)matplotlib如何绘制多个子图(轴域)
- appium1.22. Appium inspector after X version needs to be installed separately
- Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
- 1111 online map (30 points)
- Audio Focus Series: write a demo to understand audio focus and audiomananger
- The 19th Zhejiang I. barbecue
- Objects. Requirenonnull method description
- JS dynamic table creation
- [research materials] 2022q1 game preferred casual game distribution circular - Download attached
- BTC-密码学原理
猜你喜欢
M1 Pro install redis
Compile and decompile GCC common instructions
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
联想R7000显卡的拆卸与安装
Introduction to deep learning (II) -- univariate linear regression
JS dynamic table creation
Shuttle + Alluxio 加速内存Shuffle起飞
Pan details of deep learning
【实战项目】自主web服务器
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
随机推荐
Flutter monitors volume to realize waveform visualization of audio
Redis 击穿穿透雪崩
Detailed explanation of yolov5 training own data set
2022-02-12 daily clock in: problem fine brush
Redis 入门和数据类型讲解
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
Interface frequency limit access
音频焦点系列:手写一个demo理解音频焦点与AudioMananger
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
Audio Focus Series: write a demo to understand audio focus and audiomananger
The 19th Zhejiang I. barbecue
Ueditor, FCKeditor, kindeditor editor vulnerability
Online VR model display - 3D visual display solution
联想R7000显卡的拆卸与安装
What is UUID
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
Keepalived热备与HAProxy
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution