当前位置:网站首页>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
边栏推荐
- The use of subplot function in MATLAB
- ddr4测试-2
- OpenCV视频质量诊断----视频遮挡诊断
- Transform + ASM data
- MySQl的基本使用
- Go Language Advanced
- 物联网平台thingsboard搭建学习记录
- web开发常用的开源框架的开源协议整理
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- 赋能「新型中国企业」,SAP Process Automation 落地中国
猜你喜欢

XML语法、约束

uni-app商品分类

Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference

Dom4J解析XML、Xpath检索XML
![[pytorch record] automatic hybrid accuracy training torch cuda. amp](/img/a5/cf1eb2801380cf2887dfd532d3eb1e.jpg)
[pytorch record] automatic hybrid accuracy training torch cuda. amp

Shell高级进阶

optaplanner学习笔记(一)案例Cloud balance

Nacos configuration file publishing failed, please check whether the parameters are correct solution

Dlib+opencv library for fatigue detection
![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]
随机推荐
ddr4测试-2
宝,运维100+服务器很头疼怎么办?用行云管家!
Les canaux de culture intensive s'efforcent de développer Fu Xin et Wei Shi jiajie pour organiser une conférence de formation sur les nouveaux produits
H264编码profile & level控制
如何正确使用Vertx操作Redis(3.9.4带源码分析)
微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果
MySQL common graphics management tools | dark horse programmers
赋能「新型中国企业」,SAP Process Automation 落地中国
XML语法、约束
微信公众号开发相关流程及功能介绍
What must be done in graduation season before going to Shanhai
GB28181之SIP协议
241. Different Ways to Add Parentheses
Learning notes - steps of JDBC connection database operation
云服务器ECS夏日省钱秘籍,这次@老用户快来领走
[6.24-7.1] review of wonderful technical blog posts in the writing community
Write it down once Net travel management background CPU Explosion Analysis
web开发常用的开源框架的开源协议整理
【森城市】GIS数据漫谈(一)
brpc理解