Skip to content

Conversation

@liupengs
Copy link
Contributor

What problem does this PR solve?

Issue Number: #3072

Problem Summary:

当前,brpc 的用户函数里(CallMethod )无法获取 RPC 在 socket 被读取的时间点,所以存在几个问题:

  1. 无法在用户代码里统计出 RPC 正确的处理总耗时:因为在用户代码里只能从 RPC 开始被处理时开始统计时间, 而实际耗时还应该包含 RPC 在 bthread 队列里的等待时间
  2. 无法直接抛弃超时的RPC: 如果 RPC 在 bthread 调度队列等待的时间过长(也就是从 socket 读取到被 bthread 开始处理这个 RPC 的排队时间,我们线上偶发), 且超过了超时时间, 这个请求应该直接被抛弃, 但是用户无法获取 RPC 到达时间, 导致无法实现这功能

所以,应该把 RPC 从 socket 读取到的时间点暴露给用户代码。

说明:

  1. brpc 中 RPC 的 received_us 并不是 RPC 达到机器网卡的时间, 也不代表用户的发送时间, 但是相对于从 CallMethod 调用后用户自己统计 RPC 耗时, received_us 相对更精确
  2. 当前代码仅修改了 baidu_rpc, 其他的协议没支持, get_rpc_received_us 返回 0, 表示这个协议不支持

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

@wwbmmm
Copy link
Contributor

wwbmmm commented Aug 25, 2025

LGTM

@TousakaRin
Copy link
Contributor

Is it necessary to fill in this field for all protocols?

@liupengs
Copy link
Contributor Author

liupengs commented Aug 26, 2025

Is it necessary to fill in this field for all protocols?

Due to time constraints, I’ve only added the received_us to the widely used Baidu RPC protocol. If necessary, we can add received_us to other protocols in the future.

@TousakaRin TousakaRin merged commit 547ce27 into apache:master Aug 26, 2025
15 checks passed
@liupengs liupengs deleted the expt-expose-message-received-time branch September 21, 2025 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants