Skip to content

Commit 5f6ed20

Browse files
chhy2009lioncfliu
authored andcommitted
Docs: add performace data of proxy server to benchmark.md
1 parent 572a388 commit 5f6ed20

4 files changed

Lines changed: 84 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ English | [中文](README.zh_CN.md)
22

33
# tRPC-Cpp
44

5-
[![API](https://img.shields.io/badge/api-latest-green)]()
6-
[![Docs](https://img.shields.io/badge/docs-latest-green)]()
5+
[![API](https://img.shields.io/badge/api-latest-green)](https://trpc-group.github.io/trpc-cpp.github.io)
6+
[![Docs](https://img.shields.io/badge/docs-latest-green)](https://trpc.group/docs/languages/cpp/)
77
[![LICENSE](https://img.shields.io/badge/license-Apache--2.0-green.svg)](https://github.com/trpc-group/trpc-cpp/blob/main/LICENSE)
88
[![Releases](https://img.shields.io/github/release/trpc-group/trpc-cpp.svg?style=flat-square)](https://github.com/trpc-group/trpc-cpp/releases)
99
[![Build Status](https://github.com/trpc-group/trpc-cpp/actions/workflows/ci.yml/badge.svg)](https://github.com/trpc-group/trpc-cpp/actions/workflows/ci.yml)

README.zh_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# tRPC-Cpp
44

5-
[![API](https://img.shields.io/badge/api-latest-green)]()
6-
[![Docs](https://img.shields.io/badge/docs-latest-green)]()
5+
[![API](https://img.shields.io/badge/api-latest-green)](https://trpc-group.github.io/trpc-cpp.github.io)
6+
[![Docs](https://img.shields.io/badge/docs-latest-green)](https://trpc.group/zh/docs/languages/cpp/)
77
[![LICENSE](https://img.shields.io/badge/license-Apache--2.0-green.svg)](https://github.com/trpc-group/trpc-cpp/blob/main/LICENSE)
88
[![Releases](https://img.shields.io/github/release/trpc-group/trpc-cpp.svg?style=flat-square)](https://github.com/trpc-group/trpc-cpp/releases)
99
[![Build Status](https://github.com/trpc-group/trpc-cpp/actions/workflows/ci.yml/badge.svg)](https://github.com/trpc-group/trpc-cpp/actions/workflows/ci.yml)

docs/en/benchmark.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Compilation and linking options for the executable file: Compiled using gcc8, wi
1212

1313
## Test scenario
1414

15-
Throughput test: Test the QPS (Queries Per Second) of the service when the P999 latency of the caller is around 10ms.
15+
Throughput test: Test the QPS (Queries Per Second) of the service when the P999 latency of the caller is around 10ms. Based on whether the called service continues to call downstream, it can be divided into pure server mode and proxy server mode. In the pure server mode, the call chain is: Client --> Server (target service), while in the proxy server mode, the call chain is: Client --> ProxyServer (target service) --> Server.
1616

17-
Long-tail request test: With a fixed QPS of 10,000 requests per second, simulate a scenario where 1% of the requests experience a 5ms long-tail latency (during the test, an additional stress testing tool is launched to send 1% of the long-tail request traffic), and examine the latency of ordinary requests (the latency of long-tail requests is not included in the results).
17+
Long-tail request test: In pure server mode, with a fixed QPS of 10,000 requests per second, simulate a scenario where 1% of the requests experience a 5ms long-tail latency (during the test, an additional stress testing tool is launched to send 1% of the long-tail request traffic), and examine the latency of ordinary requests.
1818

1919
### About caller and callee
2020

21-
The callee is an echo service using the trpc protocol, and its RPC interface is:
21+
The callee is an echo service using the trpc protocol. The RPC interface in pure server mode is:
2222

23-
```
23+
```cpp
2424
::trpc::Status GreeterServiceImpl::SayHello(::trpc::ServerContextPtr context,
2525
const ::trpc::test::helloworld::HelloRequest* request,
2626
::trpc::test::helloworld::HelloReply* reply) {
@@ -30,16 +30,49 @@ The callee is an echo service using the trpc protocol, and its RPC interface is:
3030
}
3131
```
3232
33+
The RPC interface for the proxy server mode is (using code example in fiber mode):
34+
35+
```cpp
36+
::trpc::Status ForwardServiceImpl::Route(::trpc::ServerContextPtr context,
37+
const ::trpc::test::helloworld::HelloRequest* request,
38+
::trpc::test::helloworld::HelloReply* reply) {
39+
auto client_context = ::trpc::MakeClientContext(context, greeter_proxy_);
40+
41+
::trpc::test::helloworld::HelloRequest route_request;
42+
route_request.set_msg(request->msg());
43+
44+
::trpc::test::helloworld::HelloReply route_reply;
45+
46+
// block current fiber, not block current fiber worker thread
47+
::trpc::Status status = greeter_proxy_->SayHello(client_context, route_request, &route_reply);
48+
49+
reply->set_msg(route_reply.msg());
50+
51+
return status;
52+
}
53+
```
54+
3355
The main caller is a stress testing tool. During the test, it will establish 100 connections to the server, and the body size of each request is 10Byte.
3456

3557
### Throughput test results
3658

59+
#### Pure server mode
60+
3761
| | QPS/w | AVG latency/ms | P90 latency/ms | P99 latency/ms | P999 latency/ms |
3862
| ---| ----|------------| ------------| ------------| ------------|
3963
|fiber mode(with 8 worker thread)| 50.8 | 3.36 | 4.69 | 8.36 | 13.47 |
4064
|merge mode(with 8 worker thread)| 57.8 | 1.46 | 3.00 | 9.72 | 17.72 |
4165

42-
It can be seen that the average latency of the merge mode is the lowest and the QPS is the highest. This is because the request processing in the merge mode does not cross threads and the cache miss is the smallest. So it can achieve a very low average latency and a high QPS.
66+
It can be seen that in the merge mode, the average latency is lower and the QPS is higher. This is because the request processing in the merge mode does not cross threads and the cache miss is fewer, so it can achieve a very low average latency and a high QPS.
67+
68+
#### Proxy server mode
69+
70+
| | QPS/w | AVG latency/ms | P90 latency/ms | P99 latency/ms | P999 latency/ms |
71+
| ---| ----|------------| ------------| ------------| ------------|
72+
|fiber mode(with 8 worker thread)| 20.7 | 3.57 | 4.95 | 6.33 | 7.67 |
73+
|merge mode(with 8 worker thread)| 20.7 | 2.12 | 5.69 | 9.18 | 11.71 |
74+
75+
At around 10ms of P999 latency, the QPS of fiber mode and merge mode are comparable, but the fiber mode exhibits better performance in terms of tail latency compared to the merge mode. This is because in the fiber model, network IO and business processing logic can be parallelized across multiple cores, effectively utilizing multiple cores and achieving very low tail latency.
4376

4477
### Long-tail request test results
4578

@@ -48,4 +81,6 @@ It can be seen that the average latency of the merge mode is the lowest and the
4881
|fiber mode(with 8 worker thread)| 0.40/0.47 | 1.31/1.82 | 1.97/3.41 | avg latency: 17.5% ↑, P99 latency: 38.9% ↑ |
4982
|merge mode(with 8 worker thread)| 0.39/0.62 | 1.23/5.86 | 1.92/7.80 | avg latency: 59.0% ↑, P99 latency: 376.4% ↑ |
5083

84+
Note: the latency of long-tail requests is not included in the results.
85+
5186
It can be seen that the fiber mode is less affected by long-tail requests and has strong resistance to interference from long-tail requests, while the merge mode is greatly affected by long-tail latency. This is because in the fiber mode, requests can be processed in parallel by all worker threads, while in the merge mode, the processing of requests by worker threads cannot be parallelized across multiple cores. Once a certain request is processed for a long time, it will affect the processing time of the overall request.

docs/zh/benchmark.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
## 测试场景
1414

15-
吞吐测试:调用方的P999延时在10ms左右时,测量服务的QPS。
15+
吞吐测试:调用方的P999延时在10ms左右时,测量服务的QPS。根据被调服务是否继续调用下游,又分为纯服务端模式和中转调用模式。其中纯服务端模式调用链为: Client --> Server(被测服务),中转调用模式调用链为: Client --> ProxyServer(被测服务) --> Server。
1616

17-
长尾请求测试:固定QPS为1w/s时,在有1%的请求处理存在5ms长尾延时情况下(测试时额外启动一个压测工具发1%的长尾请求流量),考察普通请求的处理延时情况(长尾请求的延时不计入结果)
17+
长尾请求测试:在纯服务端模式下,固定QPS为1w/s时,在有1%的请求处理存在5ms长尾延时情况下(测试时额外启动一个压测工具发1%的长尾请求流量),考察普通请求的处理延时情况。
1818

1919
### 关于主调与被调
2020

21-
被调方为采用trpc协议的echo服务,其rpc接口为
21+
被调方为采用trpc协议的echo服务,纯服务端模式的rpc接口为
2222

2323
```cpp
2424
::trpc::Status GreeterServiceImpl::SayHello(::trpc::ServerContextPtr context,
@@ -30,22 +30,57 @@
3030
}
3131
```
3232
33+
中转调用模式的rpc接口为(以fiber模式下的代码为例):
34+
35+
```cpp
36+
::trpc::Status ForwardServiceImpl::Route(::trpc::ServerContextPtr context,
37+
const ::trpc::test::helloworld::HelloRequest* request,
38+
::trpc::test::helloworld::HelloReply* reply) {
39+
auto client_context = ::trpc::MakeClientContext(context, greeter_proxy_);
40+
41+
::trpc::test::helloworld::HelloRequest route_request;
42+
route_request.set_msg(request->msg());
43+
44+
::trpc::test::helloworld::HelloReply route_reply;
45+
46+
// block current fiber, not block current fiber worker thread
47+
::trpc::Status status = greeter_proxy_->SayHello(client_context, route_request, &route_reply);
48+
49+
reply->set_msg(route_reply.msg());
50+
51+
return status;
52+
}
53+
```
54+
3355
主调方为压测工具,测试时其会向服务端建立100个连接,每次请求的body大小为10Byte。
3456

3557
### 吞吐测试结果
3658

59+
#### 纯服务端模式
60+
3761
| | QPS/w | AVG latency/ms | P90 latency/ms | P99 latency/ms | P999 latency/ms |
3862
| ---| ----|------------| ------------| ------------| ------------|
3963
|fiber模式(8个worker线程)| 50.8 | 3.36 | 4.69 | 8.36 | 13.47 |
4064
|合并模式(8个worker线程)| 57.8 | 1.46 | 3.00 | 9.72 | 17.72 |
4165

42-
可见合并模式的平均延时最低、QPS最高,这是由于合并模式下请求处理不跨线程,cache miss最小,可以做到很低的平均延时和高的QPS。
66+
可见合并模式的平均延时更低、QPS更高,这是由于合并模式下请求处理不跨线程,cache miss更少,可以做到很低的平均延时和高的QPS。
67+
68+
#### 中转调用模式
69+
70+
| | QPS/w | AVG latency/ms | P90 latency/ms | P99 latency/ms | P999 latency/ms |
71+
| ---| ----|------------| ------------| ------------| ------------|
72+
|fiber模式(8个worker线程)| 20.7 | 3.57 | 4.95 | 6.33 | 7.67 |
73+
|合并模式(8个worker线程)| 20.7 | 2.12 | 5.69 | 9.18 | 11.71 |
74+
75+
P999延时在10ms左右时,fiber模式和合并模式的QPS相当,但fiber模式的长尾延时表现要好于合并模式。这是由于fiber模型下网络IO和业务处理逻辑可多核并行化,能充分利用多核,可做到很低的长尾延时。
4376

4477
### 长尾请求测试结果
4578

46-
| 不带长尾请求场景下耗时/带长尾请求场景下耗时| AVG latency/ms | P99 latency/ms | P999 latency/ms | Rise rate |
79+
| 不带长尾请求场景耗时/带长尾请求场景耗时| AVG latency/ms | P99 latency/ms | P999 latency/ms | Rise rate |
4780
| ----| ------------| ------------| ------------| ------------|
4881
|fiber模式(8个worker线程)| 0.40/0.47 | 1.31/1.82 | 1.97/3.41| avg latency: 17.5% ↑, P99 latency: 38.9% ↑ |
4982
|IO/Handle合并模式(8个worker线程)| 0.39/0.62 | 1.23/5.86 | 1.92/7.80 | avg latency: 59.0% ↑,P99 latency: 376.4% ↑ |
5083

84+
Note: 长尾请求的延时不计入上述统计结果。
85+
5186
可见fiber模式受长尾请求的影响相对小,长尾请求抗干扰能力强,而合并模式受长尾延时的影响大。这个是因为fiber模式下请求可被所有worker线程并行处理的,而合并模式下由于worker线程对请求的处理不能多核并行化,一旦有某个请求处理较长,会影响整体请求的处理时长。

0 commit comments

Comments
 (0)