Skip to content

Commit

Permalink
replaced baidu::rpc:: with brpc::
Browse files Browse the repository at this point in the history
  • Loading branch information
gejun committed Sep 5, 2017
1 parent c9627fc commit 888a763
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 260 deletions.
2 changes: 1 addition & 1 deletion docs/cn/bvar_c++.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Variable {
$ cat bvar.echo_server.data
rpc_server_8002_builtin_service_count : 20
rpc_server_8002_connection_count : 1
rpc_server_8002_nshead_service_adaptor : baidu::rpc::policy::NovaServiceAdaptor
rpc_server_8002_nshead_service_adaptor : brpc::policy::NovaServiceAdaptor
rpc_server_8002_service_count : 1
rpc_server_8002_start_time : 2015/07/24-21:08:03
rpc_server_8002_uptime_ms : 14740954
Expand Down
102 changes: 51 additions & 51 deletions docs/cn/client.md

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions docs/cn/combo_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ParallelChannel (“pchan”)同时访问其包含的sub channel,并合并它

示例代码见[example/parallel_echo_c++](http://icode.baidu.com/repo/baidu/opensource/baidu-rpc/files/master/blob/example/parallel_echo_c++/)

任何baidu::rpc::ChannelBase的子类都可以加入ParallelChannel,包括ParallelChannel和其他组合Channel。用户可以设置ParallelChannelOptions.fail_limit来控制访问的最大失败次数(r31803前是ParallelChannel::set_fail_limit),当失败的访问达到这个数目时,RPC call会立刻结束而不等待超时。
任何brpc::ChannelBase的子类都可以加入ParallelChannel,包括ParallelChannel和其他组合Channel。用户可以设置ParallelChannelOptions.fail_limit来控制访问的最大失败次数(r31803前是ParallelChannel::set_fail_limit),当失败的访问达到这个数目时,RPC call会立刻结束而不等待超时。

当baidu-rpc >= 1.0.155.31351时,一个sub channel可多次加入同一个ParallelChannel。当你需要对同一个服务发起多次异步访问并等待它们完成的话,这很有用。

Expand All @@ -30,13 +30,13 @@ ParallelChannel的内部结构大致如下:
可通过如下接口把sub channel插入ParallelChannel:

```c++
int AddChannel(baidu::rpc::ChannelBase* sub_channel,
int AddChannel(brpc::ChannelBase* sub_channel,
ChannelOwnership ownership,
CallMapper* call_mapper,
ResponseMerger* response_merger);
```
当ownership为baidu::rpc::OWNS_CHANNEL时,sub_channel会在ParallelChannel析构时被删除。当baidu-rpc >= 1.0.155.31351时,由于一个sub channel可能会多次加入一个ParallelChannel,只要其中一个指明了ownership为baidu::rpc::OWNS_CHANNEL,那个sub channel就会在ParallelChannel析构时被删除(一次)。
当ownership为brpc::OWNS_CHANNEL时,sub_channel会在ParallelChannel析构时被删除。当baidu-rpc >= 1.0.155.31351时,由于一个sub channel可能会多次加入一个ParallelChannel,只要其中一个指明了ownership为brpc::OWNS_CHANNEL,那个sub channel就会在ParallelChannel析构时被删除(一次)。
访问ParallelChannel时调用AddChannel是线程**不安全**的。
Expand Down Expand Up @@ -88,7 +88,7 @@ method/request/response:ParallelChannel.CallMethod()的参数。
const google::protobuf::MethodDescriptor* method,
const google::protobuf::Message* request,
google::protobuf::Message* response) {
FooRequest* copied_req = baidu::rpc::Clone<FooRequest>(request);
FooRequest* copied_req = brpc::Clone<FooRequest>(request);
copied_req->set_xxx(...);
// 拷贝并修改request,最后的flag告诉pchan在RPC结束后删除Request和Response。
return SubCall(method, copied_req, response->New(), DELETE_REQUEST | DELETE_RESPONSE);
Expand Down Expand Up @@ -157,7 +157,7 @@ const Controller* sub(int index) const;

示例代码见[example/selective_echo_c++](http://icode.baidu.com/repo/baidu/opensource/baidu-rpc/files/master/blob/example/selective_echo_c++/)。

任何baidu::rpc::ChannelBase的子类都可加入SelectiveChannel,包括SelectiveChannel和其他组合Channel。
任何brpc::ChannelBase的子类都可加入SelectiveChannel,包括SelectiveChannel和其他组合Channel。

SelectiveChannel的重试独立于其中的sub channel,当SelectiveChannel访问某个sub channel失败时(可能本身包含了重试),它会重试另外一个sub channel。

Expand All @@ -168,10 +168,10 @@ SelectiveChannel的重试独立于其中的sub channel,当SelectiveChannel访
SelectiveChannel的初始化和普通Channel基本一样,但Init不需要指定名字服务,因为SelectiveChannel面向sub channel并通过AddChannel动态添加,而普通Channel面向的server才记录在名字服务中。

```c++
#include <baidu/rpc/selective_channel.h>
#include brpc/selective_channel.h>
...
baidu::rpc::SelectiveChannel schan;
baidu::rpc::ChannelOptions schan_options;
brpc::SelectiveChannel schan;
brpc::ChannelOptions schan_options;
schan_options.timeout_ms = ...;
schan_options.backup_request_ms = ...;
schan_options.max_retry = ...;
Expand All @@ -194,7 +194,7 @@ if (schan.AddChannel(sub_channel, NULL/*ChannelHandle*/) != 0) { // 第二个

- 和ParallelChannel不同,SelectiveChannel的AddChannel可在任意时刻调用,即使该SelectiveChannel正在被访问(下一次访问时生效)
- SelectiveChannel总是own sub channel,这和ParallelChannel可选择ownership是不同的。
- 如果AddChannel第二个参数不为空,会填入一个类型为baidu::rpc::SelectiveChannel::ChannelHandle的值,这个handle可作为RemoveAndDestroyChannel的参数来动态删除一个channel。
- 如果AddChannel第二个参数不为空,会填入一个类型为brpc::SelectiveChannel::ChannelHandle的值,这个handle可作为RemoveAndDestroyChannel的参数来动态删除一个channel。
- SelectiveChannel会用自身的超时覆盖sub channel初始化时指定的超时。比如某个sub channel的超时为100ms,SelectiveChannel的超时为500ms,实际访问时的超时是500ms,而不是100ms。

访问SelectiveChannel的方式和普通Channel是一样的。
Expand All @@ -211,8 +211,8 @@ if (schan.AddChannel(sub_channel, NULL/*ChannelHandle*/) != 0) { // 第二个
SelectiveChannel的创建和普通Channel类似,但不需要名字服务,而是通过AddChannel方法插入sub channel。下面的代码创建了一个SelectiveChannel,并插入三个访问不同bns的普通Channel。

```c++
baidu::rpc::SelectiveChannel channel;
baidu::rpc::ChannelOptions schan_options;
brpc::SelectiveChannel channel;
brpc::ChannelOptions schan_options;
schan_options.timeout_ms = FLAGS_timeout_ms;
schan_options.backup_request_ms = FLAGS_backup_ms;
schan_options.max_retry = FLAGS_max_retry;
Expand All @@ -222,7 +222,7 @@ if (channel.Init("c_murmurhash", &schan_options) != 0) {
}

for (int i = 0; i < 3; ++i) {
baidu::rpc::Channel* sub_channel = new baidu::rpc::Channel;
brpc::Channel* sub_channel = new brpc::Channel;
if (sub_channel->Init(bns_node_name[i], "rr", NULL) != 0) {
LOG(ERROR) << "Fail to init sub channel " << i;
return -1;
Expand Down Expand Up @@ -251,11 +251,11 @@ ParititonChannel只能处理一种分库方法,当用户需要多种分库方
首先定制PartitionParser。这个例子中tag的形式是N/M,N代表分库的index,M是分库的个数。比如0/3代表一共3个分库,这是第一个。
```c++
#include <baidu/rpc/partition_channel.h>
#include brpc/partition_channel.h>
...
class MyPartitionParser : public baidu::rpc::PartitionParser {
class MyPartitionParser : public brpc::PartitionParser {
public:
bool ParseFromTag(const std::string& tag, baidu::rpc::Partition* out) {
bool ParseFromTag(const std::string& tag, brpc::Partition* out) {
// "N/M" : #N partition of M partitions.
size_t pos = tag.find_first_of('/');
if (pos == std::string::npos) {
Expand All @@ -281,11 +281,11 @@ public:
然后初始化PartitionChannel。

```c++
#include <baidu/rpc/partition_channel.h>
#include brpc/partition_channel.h>
...
baidu::rpc::PartitionChannel channel;
brpc::PartitionChannel channel;

baidu::rpc::PartitionChannelOptions options;
brpc::PartitionChannelOptions options;
options.protocol = ...; // PartitionChannelOptions继承了ChannelOptions,后者有的前者也有
options.timeout_ms = ...; // 同上
options.fail_limit = 1; // PartitionChannel自己的选项,意思同ParalellChannel中的fail_limit。这里为1的意思是只要有1个分库访问失败,这次RPC就失败了。
Expand Down Expand Up @@ -320,8 +320,8 @@ TRACE: 09-06 10:40:42: * 0 server.cpp:192] S[0]=0 S[1]=0 S[2]=0 [total=0]

```c++
...
baidu::rpc::DynamicPartitionChannel channel;
baidu::rpc::PartitionChannelOptions options;
brpc::DynamicPartitionChannel channel;
brpc::PartitionChannelOptions options;
options.succeed_without_server = true; // 表示允许server_list在DynamicPartitionChannel.Init启动时为空,否则Init会失败。
options.fail_limit = 1; // 任何访问分库失败都认为RPC失败。调大这个数值可以使访问更宽松,比如等于2的话表示至少两个分库失败才算失败。
if (channel.Init(new MyPartitionParser(), "file://server_list", "rr", &options) != 0) {
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ channel_short_socket_count: 0
上述信息分为三段:

- 第一段是server接受(accept)的连接。
- 第二段是server与下游的单连接(使用baidu::rpc::Channel建立),fd为-1的是虚拟连接,对应第三段中所有相同RemoteSide的连接。
- 第二段是server与下游的单连接(使用brpc::Channel建立),fd为-1的是虚拟连接,对应第三段中所有相同RemoteSide的连接。
- 第三段是server与下游的短连接或连接池(pooled connections),这些连接从属于第二段中的相同RemoteSide的虚拟连接。

表格标题的含义:
Expand Down
20 changes: 10 additions & 10 deletions docs/cn/cpu_profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ Wrote profile to /home/gejun/pprof/echo_server.1419501210.0.0.0.0
Removing funlockfile from all stack traces.
Total: 2946 samples
1161 39.4% 39.4% 1161 39.4% syscall
248 8.4% 47.8% 248 8.4% baidu::bthread::TaskControl::steal_task
248 8.4% 47.8% 248 8.4% bthread::TaskControl::steal_task
227 7.7% 55.5% 227 7.7% writev
87 3.0% 58.5% 88 3.0% ::cpp_alloc
74 2.5% 61.0% 74 2.5% __read_nocancel
46 1.6% 62.6% 48 1.6% tc_delete
42 1.4% 64.0% 42 1.4% baidu::rpc::Socket::Address
42 1.4% 64.0% 42 1.4% brpc::Socket::Address
41 1.4% 65.4% 41 1.4% epoll_wait
35 1.2% 66.6% 35 1.2% memcpy
33 1.1% 67.7% 33 1.1% __pthread_getspecific
33 1.1% 68.8% 33 1.1% baidu::rpc::Socket::Write
33 1.1% 68.8% 33 1.1% brpc::Socket::Write
33 1.1% 69.9% 33 1.1% epoll_ctl
28 1.0% 70.9% 42 1.4% baidu::rpc::policy::ProcessRpcRequest
27 0.9% 71.8% 27 0.9% baidu::IOBuf::_push_back_ref
27 0.9% 72.7% 27 0.9% baidu::bthread::TaskGroup::ending_sched
28 1.0% 70.9% 42 1.4% brpc::policy::ProcessRpcRequest
27 0.9% 71.8% 27 0.9% base::IOBuf::_push_back_ref
27 0.9% 72.7% 27 0.9% bthread::TaskGroup::ending_sched
```

省略–text进入交互模式,如下图所示:
Expand All @@ -80,14 +80,14 @@ Welcome to pprof! For help, type 'help'.
(pprof) top
Total: 2954 samples
1099 37.2% 37.2% 1099 37.2% syscall
253 8.6% 45.8% 253 8.6% baidu::bthread::TaskControl::steal_task
253 8.6% 45.8% 253 8.6% bthread::TaskControl::steal_task
240 8.1% 53.9% 240 8.1% writev
90 3.0% 56.9% 90 3.0% ::cpp_alloc
67 2.3% 59.2% 67 2.3% __read_nocancel
47 1.6% 60.8% 47 1.6% baidu::IOBuf::_push_back_ref
42 1.4% 62.2% 56 1.9% baidu::rpc::policy::ProcessRpcRequest
47 1.6% 60.8% 47 1.6% base::IOBuf::_push_back_ref
42 1.4% 62.2% 56 1.9% brpc::policy::ProcessRpcRequest
41 1.4% 63.6% 41 1.4% epoll_wait
38 1.3% 64.9% 38 1.3% epoll_ctl
37 1.3% 66.1% 37 1.3% memcpy
35 1.2% 67.3% 35 1.2% baidu::rpc::Socket::Address
35 1.2% 67.3% 35 1.2% brpc::Socket::Address
```
10 changes: 5 additions & 5 deletions docs/cn/dummy_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
你必须手动加入dummy server。你得先查看[Getting Started](getting_started.md)如何下载和编译baidu-rpc,然后在程序入口处加入如下代码片段:

```c++
#include <baidu/rpc/server.h>
#include brpc/server.h>

...

int main() {
...
baidu::rpc::Server dummy_server;
baidu::rpc::ServerOptions dummy_server_options;
brpc::Server dummy_server;
brpc::ServerOptions dummy_server_options;
dummy_server_options.num_threads = 0; // 不要改变寄主程序的线程数。
if (dummy_server.Start(8888/*port*/, &dummy_server_options) != 0) {
LOG(FATAL) << "Fail to start dummy server";
Expand All @@ -32,13 +32,13 @@ int main() {
r31803之后加入dummy server更容易了,只要一行:

```c++
#include <baidu/rpc/server.h>
#include brpc/server.h>

...

int main() {
...
baidu::rpc::StartDummyServerAt(8888/*port*/);
brpc::StartDummyServerAt(8888/*port*/);
...
}
```
2 changes: 1 addition & 1 deletion docs/cn/error_code.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baidu-rpc使用[baidu::rpc::Controller](http://icode.baidu.com/repo/baidu/opensource/baidu-rpc/files/master/blob/src/brpc/controller.h)设置一次RPC的参数和获取一次RPC的结果,ErrorCode()和ErrorText()是Controller的两个方法,分别是该次RPC的错误码和错误描述,只在RPC结束后才能访问,否则结果未定义。ErrorText()由Controller的基类google::protobuf::RpcController定义,ErrorCode()则是baidu::rpc::Controller定义的。Controller还有个Failed()方法告知该次RPC是否失败,这三者的关系是:
baidu-rpc使用[brpc::Controller](http://icode.baidu.com/repo/baidu/opensource/baidu-rpc/files/master/blob/src/brpc/controller.h)设置一次RPC的参数和获取一次RPC的结果,ErrorCode()和ErrorText()是Controller的两个方法,分别是该次RPC的错误码和错误描述,只在RPC结束后才能访问,否则结果未定义。ErrorText()由Controller的基类google::protobuf::RpcController定义,ErrorCode()则是brpc::Controller定义的。Controller还有个Failed()方法告知该次RPC是否失败,这三者的关系是:

- 当Failed()为true时,ErrorCode()一定不为0,ErrorText()是非空的错误描述
- 当Failed()为false时,ErrorCode()一定为0,ErrorText()是未定义的(目前在baidu-rpc中会为空,但你最好不要依赖这个事实)
Expand Down
4 changes: 2 additions & 2 deletions docs/cn/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ r31658之后支持可视化地修改,在浏览器上访问时将看到(R)下
```c++
DEFINE_bool(hex_log_id, false, "Show log_id in hexadecimal");
BAIDU_RPC_VALIDATE_GFLAG(hex_log_id, baidu::rpc::PassValidate/*always true*/);
BAIDU_RPC_VALIDATE_GFLAG(hex_log_id, brpc::PassValidate/*always true*/);
```

这个flag是单纯的开关,修改后不需要更新其他数据(没有处理逻辑),代码中前面看到true后面看到false也不会产生什么后果(不需要线程同步),所以我们让其默认可重载。
Expand All @@ -126,7 +126,7 @@ BAIDU_RPC_VALIDATE_GFLAG(hex_log_id, baidu::rpc::PassValidate/*always true*/);

```c++
DEFINE_int32(health_check_interval, 3, "seconds between consecutive health-checkings");
BAIDU_RPC_VALIDATE_GFLAG(health_check_interval, baidu::rpc::PositiveInteger);
BAIDU_RPC_VALIDATE_GFLAG(health_check_interval, brpc::PositiveInteger);
```
以上操作都可以在命令行中进行:
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ baidu-rpc detects valgrind automatically (and registers stacks of bthread). Olde

# Track instances

We provide a program to help you to track and monitor all baidu-rpc instances. Just run [trackme_server](tools/trackme_server/trackme_server.cpp) somewhere and launch need-to-be-tracked instances with -trackme_server=<SERVER>. The trackme_server will receive pings from instance periodically and print logs when it does. You can aggregate instance addresses from the log and call builtin services of the instances for further information.
We provide a program to help you to track and monitor all baidu-rpc instances. Just run [trackme_server](tools/trackme_server/trackme_server.cpp) somewhere and launch need-to-be-tracked instances with -trackme_server=<SERVER>. The trackme_server will receive pings from instance periodically and print logs when it does. You can aggregate instance addresses from the log and call builtin services of the instances for further information.
14 changes: 7 additions & 7 deletions docs/cn/heap_profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ Total: 38.9 MB
0.0 0.0% 100.0% 0.5 1.3% __do_global_ctors_aux
0.0 0.0% 100.0% 1.6 4.2% _end
0.0 0.0% 100.0% 0.5 1.3% _init
0.0 0.0% 100.0% 0.6 1.5% baidu::rpc::CloseIdleConnections
0.0 0.0% 100.0% 1.1 2.9% baidu::rpc::GlobalUpdate
0.0 0.0% 100.0% 0.6 1.5% baidu::rpc::PProfService::heap
0.0 0.0% 100.0% 1.9 4.9% baidu::rpc::Socket::Create
0.0 0.0% 100.0% 2.9 7.4% baidu::rpc::Socket::Write
0.0 0.0% 100.0% 3.8 9.7% baidu::rpc::Span::CreateServerSpan
0.0 0.0% 100.0% 1.4 3.5% baidu::rpc::SpanQueue::Push
0.0 0.0% 100.0% 0.6 1.5% brpc::CloseIdleConnections
0.0 0.0% 100.0% 1.1 2.9% brpc::GlobalUpdate
0.0 0.0% 100.0% 0.6 1.5% brpc::PProfService::heap
0.0 0.0% 100.0% 1.9 4.9% brpc::Socket::Create
0.0 0.0% 100.0% 2.9 7.4% brpc::Socket::Write
0.0 0.0% 100.0% 3.8 9.7% brpc::Span::CreateServerSpan
0.0 0.0% 100.0% 1.4 3.5% brpc::SpanQueue::Push
0.0 0.0% 100.0% 1.9 4.8% base::ObjectPool
0.0 0.0% 100.0% 0.8 2.0% base::ResourcePool
0.0 0.0% 100.0% 1.0 2.6% base::iobuf::tls_block
Expand Down
Loading

0 comments on commit 888a763

Please sign in to comment.