当前位置:网站首页>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
边栏推荐
- Wechat applet waterfall flow and pull up to the bottom
- Distinguish between releases and snapshots in nexus private library
- [backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
- Redis expiration elimination mechanism
- Notes | numpy-10 Iterative array
- 1099 build a binary search tree (30 points)
- Pan details of deep learning
- Yolov5 input (II) | CSDN creative punch in
- Silent authorization login and registration of wechat applet
- [set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
猜你喜欢

Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution

cookie session jwt

Silent authorization login and registration of wechat applet

leetcode406. Rebuild the queue based on height

Concurrent operation memory interaction
![[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

How to connect the network: Chapter 1 CSDN creation punch in
![[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached](/img/95/833f5ec20207ee5d7e6cdfa7208c5e.jpg)
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached

Kept hot standby and haproxy
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
随机推荐
Pan details of deep learning
Handler understands the record
On typescript and grammar
Overview of basic knowledge of C language
Notes | numpy-10 Iterative array
(完美解决)matplotlib图例(legend)如何自由设置其位置
Unity tool Luban learning notes 1
MySQL master-slave configuration
Based on RFC 3986 (unified resource descriptor (URI): general syntax)
Notes | numpy-08 Advanced index
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Yolov5 network structure + code + application details | CSDN creation punch in
Distinguish between releases and snapshots in nexus private library
JS function algorithm interview case
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Learning record of arouter principle
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Compile and decompile GCC common instructions
"Pthread.h" not found problem encountered in compiling GCC
Maximum continuous sub segment sum (dynamic programming, recursive, recursive)