apache / apache/brpc

server异步response写pb消息耗时较长

Open
#1,512 2 comments 0 reactions 0 assignees View on GitHub
performance
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

**Describe the bug (描述bug)**
brpc server 异步响应模式在往response中写消息字段时,通过前后取时间戳发现,response写pb消息偶现耗时4-5ms,更长时甚至20ms+

response proto格式:
{
optional uint64 id = 1;
optional int32 stat = 2;
optional uint32 cxxdiali = 3;
repeated uint32 acount = 4; //大概40+个
}

在response赋值pb消息前后取时间戳
// send response
**long long tik = GetClock();**
response->set_id (request->id ());
if (succ) {
response->set_stat (STATUS_OK);
} else {
response->set_stat (STATUS_FAILURE);
}
response->set_cxxdiali (carty);
for (int i = 1; i < size; ++i) {
response->add_ acount(xxdialis[i]);
}
**long long tok = GetClock();**

当tok-tik 超时3ms以上记录,占比大概2~3/1000:
cost: 5 1628476500710->1628476500715.
cost: 6 1628476503023->1628476503029.
cost: 8 1628476503323->1628476503331.
cost: 4 1628476505146->1628476505150.
cost: 4 1628476506299->1628476506303.
cost: 5 1628476507680->1628476507685.
cost: 23 1628476508124->1628476508147.
cost: 24 1628476508274->1628476508298.
cost: 23 1628476508455->1628476508478.
cost: 23 1628476508515->1628476508538.
cost: 23 1628476508545->1628476508568.
cost: 23 1628476508755->1628476508778.
cost: 23 1628476508876->1628476508899.
cost: 23 1628476508936->1628476508959.
cost: 23 1628476509056->1628476509079.

**To Reproduce (复现方法)**

**Expected behavior (期望行为)**

**Versions (各种版本)**
OS: linux 3.10.0-514.44.5.10.h254.x86_64
Compiler: gcc 9.x
brpc: 0.9.7
protobuf: 3.6.1

**Additional context/screenshots (更多上下文/截图)**

我的服务占用内存很高,我判断是pb在写消息时申请内存导致的偶现延时增大,请问各位是否有什么优化建议?
我查了pb的资料有arena方式创建message,不知道brpc内是否支持,如何调用?或者各位大佬有其他好的建议?

多谢 !

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the asynchronous brpc server response path described in the issue, using the listed brpc 0.9.7 and protobuf 3.6.1 versions. Measure the timestamped response field assignments and repeated-field additions under the reported workload; done means identifying the source of the latency spikes and validating an optimization or documented explanation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.