Skip to content

Commit

Permalink
enable brpc use rdma
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuvie committed Sep 22, 2022
2 parents 7aeae8c + 866a9eb commit 4159b9c
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 8 deletions.
8 changes: 7 additions & 1 deletion community/cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@
* 公司名称: 欢聚时代
* 落地项目: 推荐、直播
* 使用版本: 基于社区版本定制
* 信息提供者:chenBright
* 信息提供者:chenBright

## brpc 在 Apache Doris 中的应用
* 落地项目:Apache Doris
* 使用版本:1.2.0
* 使用情况:Apache Doris 作为一款 MPP 分析型数据库,其内部节点间使用 Apache Brpc 作为主要 RPC 框架。Brpc 为 Doris 提供了稳定易用的高性能通信机制。并且 BRPC 提供的 bthread,bvar 等基础库,以及各种性能调试工具,也极大的方便了 Doris 的开发和调试工作。
* 信息提供者:morningman
1 change: 1 addition & 0 deletions community/oncall.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
| 07/25/2022 - 07/31/2022 | 王伟冰 | https://lists.apache.org/thread/83scwkkfxrp6kkkoltbrn1fthfy3w0qz
| 08/08/2022 - 08/14/2022 | 何磊 | https://lists.apache.org/thread/jj16rzfh34yrt6o0xqfdz9wtdtzxzswq
| 08/15/2022 - 08/21/2022 | 刘帅 | https://lists.apache.org/thread/jp69sm7c8fs3dkdd828qk0fsojqwwz6h
| 09/05/2022 - 09/12/2022 | 王伟冰 | https://lists.apache.org/thread/4jjk2hxw9s2wskccclqb8fvpqxqffnlb
26 changes: 26 additions & 0 deletions docs/cn/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ BNS是百度内常用的命名服务,比如bns://rdev.matrix.all,其中"bns"

如果consul不可访问,服务可自动降级到file naming service获取服务列表。此功能默认关闭,可通过设置-consul\_enable\_degrade\_to\_file\_naming\_service来打开。服务列表文件目录通过-consul \_file\_naming\_service\_dir来设置,使用service-name作为文件名。该文件可通过consul-template生成,里面会保存consul不可用之前最新的下游服务节点。当consul恢复时可自动恢复到consul naming service。


### nacos://\<service-name\>

NacosNamingService使用[Open-Api](https://nacos.io/zh-cn/docs/open-api.html)定时从nacos获取服务列表。
NacosNamingService支持[简单鉴权](https://nacos.io/zh-cn/docs/auth.html)

`<service-name>`是一个http uri query,具体参数参见`/nacos/v1/ns/instance/list`文档。
注意:`<service-name>`需要urlencode。
```
nacos://serviceName=test&groupName=g&namespaceId=n&clusters=c&healthyOnly=true
```

NacosNamingService拉取列表的时间间隔为`/nacos/v1/ns/instance/list`api返回的`cacheMillis`
NacosNamingService只支持整形的权重值。

| GFlags | 描述 | 默认值 |
| ---------------------------------- | -------------------------- | ---------------------------- |
| nacos_address | nacos http url | "" |
| nacos_service_discovery_path | nacos服务发现路径 | "/nacos/v1/ns/instance/list" |
| nacos_service_auth_path | nacos登陆路径 | "/nacos/v1/auth/login" |
| nacos_service_timeout_ms | 连接nacos超时时间(毫秒) | 200 |
| nacos_username | 用户名(urlencode编码) | "" |
| nacos_password | 密码(urlencode编码) | "" |
| nacos_load_balancer | nacos集群的负载均衡 | "rr" |


### 更多命名服务
用户可以通过实现brpc::NamingService来对接更多命名服务,具体见[这里](https://github.com/brpc/brpc/blob/master/docs/cn/load_balancing.md#%E5%91%BD%E5%90%8D%E6%9C%8D%E5%8A%A1)

Expand Down
11 changes: 11 additions & 0 deletions docs/cn/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ $ sh run_tests.sh
### 使用cmake编译brpc
参考[这里](#使用cmake编译brpc)

### 使用vcpkg编译brpc

[vcpkg](https://github.com/microsoft/vcpkg) 是一个全平台支持的包管理器,你可以使用以下步骤vcpkg轻松编译brpc:

```shell
$ git clone https://github.com/microsoft/vcpkg.git
$ ./bootstrap-vcpkg.bat # 使用 powershell
$ ./bootstrap-vcpkg.sh # 使用 bash
$ ./vcpkg install brpc
```

## 自己构建依赖的Linux

### 依赖准备
Expand Down
26 changes: 26 additions & 0 deletions docs/en/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ If the server list returned by the consul does not follow [response format](http

If consul is not accessible, the naming service can be automatically downgraded to file naming service. This feature is turned off by default and can be turned on by setting -consul\_enable\_degrade\_to\_file\_naming\_service. After downgrading, in the directory specified by -consul\_file\_naming\_service\_dir, the file whose name is the service-name will be used. This file can be generated by the consul-template, which holds the latest server list before the consul is unavailable. The consul naming service is automatically restored when consul is restored.


### nacos://\<service-name\>

NacosNamingService gets a list of servers from nacos periodically by [Open-Api](https://nacos.io/en-us/docs/open-api.html).
NacosNamingService supports [simple authentication](https://nacos.io/en-us/docs/auth.html).

`<service-name>` is a http uri query,For more detail, refer to `/nacos/v1/ns/instance/list` api document.
NOTE: `<service-name>` must be url-encoded.
```
nacos://serviceName=test&groupName=g&namespaceId=n&clusters=c&healthyOnly=true
```

The server list is cached for `cacheMillis` milliseconds as specified in the response of `/nacos/v1/ns/instance/list` api.
NOTE: The value of server weight must be an integer.

| GFlags | Description | Default value |
| ---------------------------------- | ------------------------------------ | ---------------------------- |
| nacos_address | nacos http url | "" |
| nacos_service_discovery_path | path for discovery | "/nacos/v1/ns/instance/list" |
| nacos_service_auth_path | path for login | "/nacos/v1/auth/login" |
| nacos_service_timeout_ms | timeout for connecting to nacos(ms) | 200 |
| nacos_username | url-encoded username | "" |
| nacos_password | url-encoded password | "" |
| nacos_load_balancer | load balancer for nacos clusters | "rr" |


### More naming services
User can extend to more naming services by implementing brpc::NamingService, check [this link](https://github.com/brpc/brpc/blob/master/docs/cn/load_balancing.md#%E5%91%BD%E5%90%8D%E6%9C%8D%E5%8A%A1) for details.

Expand Down
12 changes: 12 additions & 0 deletions docs/en/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ Examples link brpc statically, if you need to link the shared version, remove `C
$ mkdir build && cd build && cmake -DBUILD_UNIT_TESTS=ON .. && make && make test
```

### Compile brpc with vcpkg

[vcpkg](https://github.com/microsoft/vcpkg) is a package manager that supports all platforms,
you can use vcpkg to build llvm with the following step:

```shell
$ git clone https://github.com/microsoft/vcpkg.git
$ ./bootstrap-vcpkg.bat # for powershell
$ ./bootstrap-vcpkg.sh # for bash
$ ./vcpkg install brpc
```

## Fedora/CentOS

### Prepare deps
Expand Down
3 changes: 3 additions & 0 deletions src/brpc/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "brpc/policy/remote_file_naming_service.h"
#include "brpc/policy/consul_naming_service.h"
#include "brpc/policy/discovery_naming_service.h"
#include "brpc/policy/nacos_naming_service.h"

// Load Balancers
#include "brpc/policy/round_robin_load_balancer.h"
Expand Down Expand Up @@ -135,6 +136,7 @@ struct GlobalExtensions {
RemoteFileNamingService rfns;
ConsulNamingService cns;
DiscoveryNamingService dcns;
NacosNamingService nns;

RoundRobinLoadBalancer rr_lb;
WeightedRoundRobinLoadBalancer wrr_lb;
Expand Down Expand Up @@ -358,6 +360,7 @@ static void GlobalInitializeOrDieImpl() {
NamingServiceExtension()->RegisterOrDie("remotefile", &g_ext->rfns);
NamingServiceExtension()->RegisterOrDie("consul", &g_ext->cns);
NamingServiceExtension()->RegisterOrDie("discovery", &g_ext->dcns);
NamingServiceExtension()->RegisterOrDie("nacos", &g_ext->nns);

// Load Balancers
LoadBalancerExtension()->RegisterOrDie("rr", &g_ext->rr_lb);
Expand Down
6 changes: 5 additions & 1 deletion src/brpc/periodic_naming_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ DEFINE_int32(ns_access_interval, 5,
"Wait so many seconds before next access to naming service");
BRPC_VALIDATE_GFLAG(ns_access_interval, PositiveInteger);

int PeriodicNamingService::GetNamingServiceAccessIntervalMs() const {
return std::max(FLAGS_ns_access_interval, 1) * 1000;
}

int PeriodicNamingService::RunNamingService(
const char* service_name, NamingServiceActions* actions) {
std::vector<ServerNode> servers;
Expand All @@ -47,7 +51,7 @@ int PeriodicNamingService::RunNamingService(
actions->ResetServers(servers);
}

if (bthread_usleep(std::max(FLAGS_ns_access_interval, 1) * 1000000L) < 0) {
if (bthread_usleep(GetNamingServiceAccessIntervalMs() * 1000UL) < 0) {
if (errno == ESTOP) {
RPC_VLOG << "Quit NamingServiceThread=" << bthread_self();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/brpc/periodic_naming_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PeriodicNamingService : public NamingService {
virtual int GetServers(const char *service_name,
std::vector<ServerNode>* servers) = 0;

virtual int GetNamingServiceAccessIntervalMs() const;

int RunNamingService(const char* service_name,
NamingServiceActions* actions);
};
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/policy/http_rpc_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ void ProcessHttpRequest(InputMessageBase *msg) {
if (is_grpc_ct) {
bool grpc_compressed = false;
if (!RemoveGrpcPrefix(&req_body, &grpc_compressed)) {
cntl->SetFailed(ERESPONSE, "Invalid gRPC response");
cntl->SetFailed(EREQUEST, "Invalid gRPC request");
return;
}
if (grpc_compressed) {
Expand Down
Loading

0 comments on commit 4159b9c

Please sign in to comment.