当前位置:网站首页>Brpc understanding
Brpc understanding
2022-07-01 19:34:00 【lcyw】
We only have three user classes :Server、Channel and Controller, They correspond to each other server End ,client End and adjustment parameter set .
There is no need to deliberate, such as “Client How to initialize ”,“XXXManager What's the usage? ”,“Context and Controller What is the relationship of ” And so on
It's easy to do :
Build service #include <baidu/rpc/server.h>, And use... According to notes or examples server object
Access to the service is #include <baidu/rpc/channel.h>, And use... According to notes or examples Channel object
Want to control once RPC Parameters to access , Just look at it. baidu/rpc/controller.h What's in it . Please note that , This class is Server and Channel Public , It is divided into three paragraphs , They are marked as Client-side,Server-sdie and Both-side methods
One 、Channel
Channel Can be shared by all threads , You don't need to create separate for each thread Channel, There is no need to lock mutual exclusion . however Channel The creation and Init Not thread safe , Please make sure that Init After success, it will be accessed by multiple threads , Destruct after no thread access .
management client, Number of threads configured 、 To join or place in length brpc::ChannelOptions, Or through gflags Global configuration
Init The function is divided into connecting to a server or service cluster
1. Connect to a server
// options by NULL The default value int Init(EndPoint server_addr_and_port, const ChannelOptions* options);
int Init(const char* server_addr_and_port, const ChannelOptions* options);
int Init(const char* server_addr, int port, const ChannelOptions* options);
This kind of Init The connected servers often have fixed servers ip Address , There is no need for naming services and load balancing , It's relatively light to create .
However, do not frequently create domain names Channel. This requires a query dns, It may take up to 10 second ( Inquire about DNS The default timeout for )
2. Connect clusters
int Init(const char* naming_service_url,
const char* load_balancer_name,
const ChannelOptions* options);
This kind of Channel It is necessary to start from... On a regular basis naming_service_url Get the list of servers from the specified naming service , And pass load_balancer_name The specified load balancing algorithm selects a machine to send requests .
You shouldn't create this class dynamically before every request ( Connect to the service cluster )Channel. Because creating and destructing this kind of Channel Involve more resources , For example, you have to access the naming service once when creating ,
Otherwise, you don't know which servers are available . because Channel Can be shared by multiple threads , In general, there is no need to dynamically create .
client Set up
(1)brpc:ChannelOptions For initialization Channel
(2)brpc::Controller For a time RPC Medium coverage ChannelOptions Options in , It can be different each time according to the context
(3) overall situation gflags Used to adjust the behavior of some underlying code
Controller Characteristics :
One Controller Corresponding once RPC, There can only be one user , The default thread is unsafe .
Cannot be shared , Pointers cannot be shared
Founded in RPC Prior to the start , Deconstruction in RPC After that, there are two modes
a Sync RPC front Controller Put it on the stack , Self destruct after leaving the scope
b asynchronous RPC front new Controller, done Delete in
边栏推荐
- [Mori city] random talk on GIS data (I)
- How to solve the problem of splash screen when the main and sub code streams of easygbs are h.265?
- 学习笔记【gumbel softmax】
- Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
- [6.24-7.1] review of wonderful technical blog posts in the writing community
- Learning records of building thingsboard, an Internet of things platform
- 微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果
- 微信公众号开发相关流程及功能介绍
- 奔赴山海之前,毕业季一定要做的那些事情
- 寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
猜你喜欢

Once the SQL is optimized, the database query speed is increased by 60 times

MySQL common graphics management tools | dark horse programmers

微信公众号开发相关流程及功能介绍
![Reading the paper [learning to discretely compose reasoning module networks for video captioning]](/img/a2/acdaebeb67ec4bcb01c8ff4bbd1d1e.png)
Reading the paper [learning to discretely compose reasoning module networks for video captioning]

Dom4J解析XML、Xpath检索XML

精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
![Extensive reading of the paper [film: visual reasoning with a general condition layer]](/img/69/f4ba37a7eae34a7e698127c31b0161.png)
Extensive reading of the paper [film: visual reasoning with a general condition layer]

原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中

白盒加密技术浅理解

Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
随机推荐
原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
Crunch简介、安装,使用Crunch制作密码字典
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
win10下使用msys+vs2019编译ffmpeg源码
【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法
Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
DTD modeling
CMU AI PhD 第一年总结
【org.slf4j.Logger中info()方法】
Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
[info() method in org.slf4j.logger]
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
为什么一定要从DevOps走向BizDevOps?
【6.24-7.1】写作社区精彩技术博文回顾
ECS summer money saving secret, this time @ old users come and take it away
Cdga | if you are engaged in the communication industry, you should get a data management certificate
IPv4地址、子网掩码、网关
微信公众号开发相关流程及功能介绍
OpenCV视频质量检测--清晰度检测
【英语语法】Unit1 冠词、名词、代词和数词