当前位置:网站首页>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
边栏推荐
- [basic grammar] C language uses for loop to print Pentagram
- Notes | numpy-10 Iterative array
- Burp suite plug-in based on actual combat uses tips
- Distinguish between releases and snapshots in nexus private library
- 1094 the largest generation (25 points)
- Compile and decompile GCC common instructions
- Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
- Learning record of arouter principle
- "Pthread.h" not found problem encountered in compiling GCC
- SSM framework integration
猜你喜欢

Unity tool Luban learning notes 1

Make your own dataset

Gbase8s unique index and non unique index

(完美解决)matplotlib图例(legend)如何自由设置其位置
![[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
![[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached](/img/01/052928e7f20ca671cdc4c30ae55258.jpg)
[research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached

Burp suite plug-in based on actual combat uses tips

Celebrate the new year together

Shuttle + alluxio accelerated memory shuffle take-off
![[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree](/img/0f/bc8c44aee7a2c9dccac050b1060017.jpg)
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
随机推荐
Market status and development prospect prediction of global fermentation acid industry in 2022
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
Common methods of JS array
Yolov5 model construction source code details | CSDN creation punch in
Rust基础入门之(基本类型)
1106 lowest price in supply chain (25 points)
Compile and decompile GCC common instructions
Mobile terminal - uniapp development record (public request encapsulation)
Detailed explanation of yolov5 training own data set
Unity tool Luban learning notes 1
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
How to connect the network: Chapter 1 CSDN creation punch in
XML配置文件
Redis Introduction et explication des types de données
Go language interface learning notes
Keepalived热备与HAProxy
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
[basic grammar] C language uses for loop to print Pentagram
乾元通多卡聚合路由器的技术解析