当前位置:网站首页>I/o multiplexing & event driven yyds dry inventory
I/o multiplexing & event driven yyds dry inventory
2022-07-02 06:06:00 【Soda 233】
Event driven
Definition
A driver architecture , Decoupling the generation and consumption of events . You can refer to Release / Subscription model
The core
I/O Operations are abstracted into events , Each event corresponds to Callback function To deal with it . Distribute by event , These events can be detected one by one , And call the corresponding callback function to handle .
Lord - from reactor+worker threads Pattern
Definition
The main reactor thread is only responsible for distributing Acceptor Connection is established , Connected... On socket I/O The incident was handed over to from -reactor Responsible for distribution . take CPU Intensive work is entrusted to worker Thread pool to handle , And these tasks are divided into one sub task .encode After that, the completed results are determined by sub-reactor Of I/O Thread send out .
solve the problem
It's solved I/O The efficiency of distribution , Business logic and I/O Coupling between distributions .
I/O Multiplexing
select & poll
technological process
1. User thread call select, take fd_set Copy from user space to kernel space
2. The kernel is in kernel space for fd_set Go through it , Check to see if there are any ready socket The descriptor , If not , It goes into sleep , Until there's something ready socket The descriptor
3. The kernel returns select To the user thread , The number of ready file descriptors
4. After the user gets the number of ready file descriptors , Again fd_set Traversal , Find the file descriptor in place
5. The user thread reads and writes the ready file descriptor
shortcoming
1、 Every time you call select function , All of them fd_set from User mode copy to Kernel mode , influence performance .
2、 have O(n) The undifferentiated polling time complexity of , Poll all fd_set, Long polling time .
3、select maximum connection ( Maximum number of file descriptors supported ) Limited , It's usually 1024
difference
poll Use pollfd Structure, not select Of fd_set structure ,pollfd Structures use linked lists instead of arrays ,pollfd There is no limit to the length of
epoll( Synchronous nonblocking 、 subscribe 、 Callback 、 Red and black trees 、 Linked list )
Implement and use :
1、 call epoll_create Build a epoll Handle object
2、 call epoll_ctl Add a new socket , Add monitoring events and register callback functions
3、 When a file descriptor is ready , The kernel will use something like callback The callback mechanism of , Quickly activate the file descriptor , The event triggered will be Callback function Join in eventpoll Of Linked list rdlist in .
4、 call epoll_wait Collect connections for events that occur ( Check eventpoll Object rdlist Whether there are elements in the linked list )
Level trigger 、 edge-triggered
Level trigger :epoll_wait Monitoring , Data that has not been processed will always be returned
edge-triggered : Pay attention to whether there are new events in the file descriptor , What has been returned will not be returned
Red and black tree root node rbr: The root node of the red black tree , This tree stores everything added to epoll Events to be monitored in
Linked list rdlist: In the linked list are stored the information to be passed through epoll_wait Events that meet the conditions returned to the user
shortcoming
Above 3 Both are synchronous for the caller
边栏推荐
- 【C语言】简单实现扫雷游戏
- Some descriptions of Mipi protocol of LCD
- Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
- Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
- ZABBIX server trap command injection vulnerability (cve-2017-2824)
- LCD之MIPI协议的一些说明
- php读文件(读取文件内含有某字符串的指定行)
- Deep learning classification network -- Network in network
- PHP read file (read JSON file, convert to array)
- MySQL transaction and isolation level
猜你喜欢
Deep learning classification network -- alexnet
Unity shader learning notes (3) URP rendering pipeline shaded PBR shader template (ASE optimized version)
神机百炼3.53-Kruskal
深度学习分类网络--VGGNet
uni-app开发中遇到的问题(持续更新)
PHP development and testing WebService (soap) -win
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
官方零基础入门 Jetpack Compose 的中文课程来啦!
Mathematical statistics and machine learning
Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
随机推荐
php按照指定字符,获取字符串中的部分值,并重组剩余字符串为新的数组
Can't the dist packaged by vite be opened directly in the browser
Eco express micro engine system has supported one click deployment to cloud hosting
Lambda expressions and method references
Mock simulate the background return data with mockjs
Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
使用HBuilderX的一些常用功能
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
线性dp(拆分篇)
Jetpack Compose 与 Material You 常见问题解答
PHP obtains some values in the string according to the specified characters, and reorganizes the remaining strings into a new array
[C language] screening method for prime numbers
经典文献阅读之--Deformable DETR
数据库学习总结5
STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
1035 Password
STC8H8K系列汇编和C51实战——数码管显示ADC、按键串口回复按键号与ADC数值
500. Keyboard line
复杂 json数据 js前台解析 详细步骤《案例:一》
Some experience of exercise and fitness