当前位置:网站首页>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
边栏推荐
- MFC中如何重绘CListCtrl的表头
- Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
- 论文泛读【FiLM: Visual Reasoning with a General Conditioning Layer】
- 物联网平台thingsboard搭建学习记录
- Lumiprobe phosphide hexaethylene phosphide specification
- 从零开始学 MySQL —数据库和数据表操作
- 学习笔记-JDBC连接数据库操作的步骤
- 案例分享:QinQ基本组网配置
- Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
- ffmpeg 音频相关命令
猜你喜欢
随机推荐
Summary of SQL query de duplication statistics methods
博途V16 获取系统时间转换成字符串
【pytorch记录】自动混合精度训练 torch.cuda.amp
狼人杀攻略:你当我好骗吗,我们相信谁!
EasyGBS主子码流都为H.265时,切换出现花屏如何解决?
ECS summer money saving secret, this time @ old users come and take it away
ddr4测试-2
DTD建模
Contos 7 搭建sftp之创建用户、用户组以及删除用户
axure不显示元件库
简版拼多多商品数据
新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?
GetMessage底层机制分析
Task: denial of service DOS
wireshark报文分析tcp,ftp
云服务器ECS夏日省钱秘籍,这次@老用户快来领走
线程的并行、并发、生命周期
sql查询去重统计的方法总结
Team up to learn! 14 days of Hongmeng equipment development "learning, practicing and testing" practical camp, free of charge!
Introduction and installation of crunch, and making password dictionary with crunch