当前位置:网站首页>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
边栏推荐
- Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
- 编译GCC遇到的“pthread.h” not found问题
- What is UUID
- Webapidom get page elements
- Notes | numpy-09 Broadcast
- Detailed explanation of yolov5 training own data set
- On typescript and grammar
- 1087 all roads lead to Rome (30 points)
- Force GCC to compile 32-bit programs on 64 bit platform
- Problems encountered in fuzzy query of SQL statements
猜你喜欢

Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)

Retirement plan fails, 64 year old programmer starts work again

Cross platform plug-in flutter for displaying local notifications_ local_ notifications

Yolov5 network structure + code + application details | CSDN creation punch in

Learn to use the idea breakpoint debugging tool

乾元通多卡聚合路由器的技术解析

(subplots用法)matplotlib如何绘制多个子图(轴域)
![[research materials] 2021 China's game industry brand report - Download attached](/img/b7/a377b0b7c742078e2feb28ebfbca62.jpg)
[research materials] 2021 China's game industry brand report - Download attached

小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计

Unity tool Luban learning notes 1
随机推荐
The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
[develop wechat applet local storage with uni app]
Market status and development prospect prediction of global fermentation acid industry in 2022
Distinguish between releases and snapshots in nexus private library
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
JQ style, element operation, effect, filtering method and transformation, event object
Market status and development prospects of the global automatic tea picker industry in 2022
study hard and make progress every day
Detailed explanation of yolov5 training own data set
Notes | numpy-09 Broadcast
最大连续子段和(动态规划,递归,递推)
Market status and development prospect prediction of global colorimetric cup cover industry in 2022
Redis 入門和數據類型講解
BTC-密码学原理
Class loading mechanism (detailed explanation of the whole process)
@RequestMapping
Gbase8s composite index (I)
Unity tool Luban learning notes 1
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南