brpc icon indicating copy to clipboard operation
brpc copied to clipboard

性能问题

Open shenxuebing opened this issue 6 months ago • 3 comments

brpc-1.13.0 protoc 3.21.12

使用echo_server进行测试

./echo_server -minloglevel=4

使用rpc_press进行压测

1. 单连接模式测试:

./rpc_press -proto="./echo.proto" -method=example.EchoService.Echo -server=192.168.100.4:8000 -input=.'{"message":"hello"} {"message":"world"}' -qps=0 -timeout_ms=3000 -thread_num=512

Image

QPS 45W+

2. 连接池模式测试: ./rpc_press -proto="./echo.proto" -method=example.EchoService.Echo -server=192.168.100.4:8000 -input=.'{"message":"hello"} {"message":"world"}' -qps=0 -timeout_ms=3000 -thread_num=512 -connection_type=pooled

Image

QPS 7W+

这是为什么呢?正常业务场景都是连接池模式,为什们连接池模式反而性能低这么多呢?该如何调优使连接池的性能和单链接接近呢。

shenxuebing avatar Jun 18 '25 11:06 shenxuebing

In pooled mode, at most one RPC request can exist on each pooled connection, while in single connection mode + baidu_rpc_protocol, one TCP connection request can carry multiple RPC requests. if you are using baidu_std_protocol, just use single connection.

TousakaRin avatar Jun 19 '25 03:06 TousakaRin

In pooled mode, at most one RPC request can exist on each pooled connection, while in single connection mode + baidu_rpc_protocol, one TCP connection request can carry multiple RPC requests. if you are using baidu_std_protocol, just use single connection.

但是大多数的业务场景都是连接池模式的吧,很少有单连接的场景。而且就算是使用连接池模式,性能不能这么低吧,我觉得怎么也能到单连接的70-80%,是不是我需要配置什么参数呢?请指导

shenxuebing avatar Jun 19 '25 03:06 shenxuebing

但是大多数的业务场景都是连接池模式的吧, 很少有单连接的场景

No, it depends on your communication protocol. For protocols like http1.x where the server side must process requests on the same TCP connection in sequence,using connection pool is a good way to improve concurrency. For protocols such as http2.0 and baidu_std, a single connection is usually sufficient.

For distributed systems, you should consider name services and load balancing.

If you must use brpc protocol with connection pool, you can use connection_group to create multiple connections to same node and manage them manually.

By the way, if you set -protocol=http, the result may be what you expect

TousakaRin avatar Jun 19 '25 05:06 TousakaRin

单连接比连接池性能好的原因,@shenxuebing 可以参考一下 #506 描述的内容,单连接模式可以同时处理多个请求,连接池只能一个连接处理一个请求 @TousakaRin 已经提到,这就决定了单连接模式小包场景下通过粘包功能可以提升系统吞吐量,但是面对糟糕的广域网环境容错性较差,而连接池模式小包无法实现粘包sys-read/write的占比会非常高,但面对广域网网络抖动具有很好容错。

zchuango avatar Oct 16 '25 07:10 zchuango