Skip to content

feat: add JFR RPC profiling support - #1578

Open
weilhuang wants to merge 1 commit into
sofastack:masterfrom
weilhuang:jfr-profiling-1128
Open

feat: add JFR RPC profiling support#1578
weilhuang wants to merge 1 commit into
sofastack:masterfrom
weilhuang:jfr-profiling-1128

Conversation

@weilhuang

Copy link
Copy Markdown

Motivation:

通过 JFR 记录 SOFA RPC 调用过程中的阶段耗时,并能够关联客户端和服务端数据,帮助定位“RPC 整体耗时较长,但无法确定时间消耗在哪个阶段”的问题。

  • 使用客户端和服务端总 Event 记录一次 RPC 调用;
  • 在总 Event 中记录现有阶段耗时;
  • 使用 profileId 关联 Consumer 和 Provider;
  • 完成 Bolt、Triple 的传播和端到端验证;
  • 提供命令行报告工具解析一个或多个 JFR 文件。

Modification:

  1. 新增通用 Profile 扩展
  • core/api 中增加 Profile SPI、ProfileFactoryProfiles 门面;
  • Profile 默认关闭,未配置时不会生成 profileId 或注册 JFR 订阅者;
  • Profile 采集异常不会影响正常 RPC 调用。
  1. 新增 JFR Profile 模块
  • 新增 sofa-rpc-profile-jfr 模块;
  • 通过 Module SPI 在 default.profile=jfr 时自动安装;
  • 定义客户端和服务端持续时间事件:
    • com.alipay.sofa.rpc.ClientInvocation
    • com.alipay.sofa.rpc.ServerInvocation
  • 事件记录服务、方法、应用、协议、地址、结果、错误类型、请求/响应大小和阶段耗时;
  • 出于安全考虑,不记录方法参数、响应内容和异常消息。
  1. 记录 RPC 阶段耗时
  • 接入客户端路由、过滤器、负载均衡、连接创建、序列化和反序列化耗时;
  • 接入服务端反序列化、线程池等待、过滤器、业务执行、序列化和网络等待耗时;
  • 阶段数据保存在每次调用独立的 RpcInternalContext 中,避免异步调用之间相互覆盖。
  1. 实现跨进程调用关联
  • 客户端自动生成并校验 UUID 格式的 profileId
  • Bolt 通过请求属性传递;
  • Triple 通过 metadata 传递;
  • 报告工具使用 profileId 关联不同进程、不同 JFR 文件中的客户端和服务端事件。
  1. 新增 JFR 报告工具
  • 使用 JDK 自带的 jdk.jfr.consumer API,不引入 JMC SDK;
  • 支持读取一个或多个 .jfr 文件;
  • 支持输出耗时 Top-N RPC 调用及其阶段时间线;
  • 使用两遍扫描,只在内存中保留 Top-N 调用详情,避免内存随录制时间无限增长;
  • 客户端或服务端数据缺失时仍可输出单端报告。
  1. 测试和兼容性
  • 增加 Profile SPI、JFR Event、模块安装/卸载、独立 JVM SPI 自动发现和报告解析测试;
  • 增加真实 Bolt、Triple Provider/Consumer 端到端测试;
  • 端到端测试会生成 JFR 文件、解析事件,并验证客户端和服务端能够按 profileId 关联;
  • JDK 8 下 JFR 会重新转换 Event 子类,因此从 JaCoCo 0.7.9 中排除纯事件载体类,避免重复插桩,其他 JFR 实现代码仍参与覆盖率统计;
  • 补充接入方式、JFR 录制、报告生成、JDK 8 注意事项以及 JFR 阶段报告与 CPU 火焰图的区别。

Result:

Relates to gh-1128

Add the Profile SPI, JFR invocation events, bounded report generation, and Bolt/Triple correlation with invocation-scoped phase data.

Relates to sofastackgh-1128
@sofastack-cla

sofastack-cla Bot commented Aug 21, 2026

Copy link
Copy Markdown

Hi @wl2027, welcome to SOFAStack community, Please sign Contributor License Agreement!

After you signed CLA, we will automatically sync the status of this pull request in 3 minutes.

@sofastack-cla sofastack-cla Bot added cla:no Need sign CLA First-time contributor First-time contributor size/XXL labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:no Need sign CLA First-time contributor First-time contributor size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant