当前位置:网站首页>Thinking about the cooperation process of Network Library -- Some Thoughts on reading brpc
Thinking about the cooperation process of Network Library -- Some Thoughts on reading brpc
2022-06-12 10:40:00 【saddlesad】
bthread One of the functions of : take Reactor Synchronization in IO Change asynchronous IO.
Theoretically Reactor Not as efficient as Proactor, The concrete manifestation is that although Reactor The model avoids waiting to be readable / The time when the writable event is ready , however read/write The timing of the call itself is inevitable ( That is, the data copy between the kernel buffer and the user buffer occupies the current thread CPU The time of the ), and Proactor But this time can be avoided , So it's more efficient .
So why do you say Proactor More efficient ? although Proactor No need to wait read/write In itself , But only the read and write processing time is transferred to the operating system kernel thread , The total processing time does not decrease .
The key is to put read/write The time is transferred to the operating system , The current thread can continue to process the next connection , Although the total throughput has not changed , But the average processing delay per request is reduced . therefore brpc Zhongba IO Operation to new bthread perform (https://github.com/apache/incubator-brpc/blob/master/docs/cn/io.md#%E6%94%B6%E6%B6%88%E6%81%AF) It is equivalent to handing over to support asynchronous IO Operating system to execute , Both of them can reduce the average request delay .
hook system call
With asynchrony IO and bthread The Apocalypse of , We would think of rewriting all system calls that would block in this way , This leads to hook.
Simply speaking hook Library code is a wrapper around system calls , The purpose is to block the system call , Not directly blocking the current thread , It blocks the current bthread, The current thread immediately executes another bthread, This avoids thread blocking .
This is equivalent to calling the system + The thread model is delegated to hook System call after + coroutines .( Thread switching occurs when the system call is blocked ,hook When the subsequent system call is blocked, a coprocessor switch occurs , The cost of CO process switching is less than that of threads , So the latter has better performance ).
however brpc did not hook system call , This is because :
- bthread Blocking may switch system threads , Dependent systems TLS The behavior of the function of is undefined .
- And blocking pthread May deadlock when mixed functions of .
- This kind of hook Functions themselves are generally less efficient , Because there are often additional system calls , Such as epoll.
边栏推荐
- 对网络库协程的思考——读brpc有感
- XML Parsing Error: mismatched tag. Expected
- 在一个“去QA化”的项目中,QA能做什么?
- PHP Apple purchase verification steps
- M-Arch(番外13)GD32L233评测-来点音乐
- k53.第二章 基于二进制包安装kubernetes v1.22 --集群部署
- PHP interface generates cache and MD5 encryption uniformly
- How Qualcomm platform modifies special voltage
- Pagoda chevereto1.6.2 the latest version of stepping on the pit tutorial in Chinese
- This and final keywords
猜你喜欢

Why check the @nonnull annotation at run time- Why @Nonnull annotation checked at runtime?

Index query efficiency of MySQL

Distributed storage exploration

Stream as a return value in WCF - who disposes of it- Stream as a return value in WCF - who disposes it?

MySQL performance test (slow query log)

Malicious code analysis practice -- using apatedns and inetsim to simulate network environment
![[machine learning] practice of logistic regression classification based on Iris data set](/img/c6/0233545d917691b8336f30707e4636.png)
[machine learning] practice of logistic regression classification based on Iris data set

Leetcode 2169. Get operands of 0

Pycharm view the current version of opencv

Vite Basics
随机推荐
A few secrets - a special day
2022淘宝618超级喵运会怎么玩?2022淘宝618喵运会玩法技巧
PHP can load different new data methods for each refresh
2022 Taobao 618 Super Cat Games introduction 618 super cat games playing skills
See if you fall into the trap of "labeling" customers and users?
Reverse analysis of Huawei housekeeper software [transfer]
Php:redis uses geospatial
How the ArrayList collection implements ascending and descending order
This and final keywords
PHP generate schedule
Class. Forname connection MySQL driver keeps throwing classnotfoundexception exception solution
890. 查找和替换模式
数组,整型,字符变量在全局和局部的存在形式
浅谈调和形状上下文特征HSC对3DSC的改进
Collation of common functions in JS
file_ get_ Contents() JSON after reading_ Decode cannot be converted to array
Set SVG color
基于QT的旅行查询与模拟系统
Common port description
JS obtains the time period of this week and last week (one time period is from Monday to Sunday)