[duboo] 基于JMeter + Dubbo插件进行dubbo接口压力测试

背景信息

对dubbo接口简单调用可通过telnet实现,但无法简单的通过bash或Python脚本实现并发,故采用JMeter + Dubbo插件进行压力测试

环境准备

需首先安装jdk。
jmeter:https://jmeter.apache.org/download_jmeter.cgi
dubbo插件:https://github.com/thubbo/jmeter-plugins-for-apache-dubbo
将dubbo插件移动到jmeter的 lib/ext目录,然后启动jmeter

配置

GUI调试

1. 配置线程组 (Thread Group)

  • Action: 添加 -> 线程(用户) -> 线程组。
  • 参数预设:用于调试时,线程数设为 1,循环次数设为 1。

2. 配置 Dubbo Sampler

  • Action: 在线程组下添加 -> 取样器 -> Dubbo Sample。
  • Registry Settings (注册中心配置):
    • Address 处填写 1.2.3.4:16677(dubbo服务主机ip端口),Registry Protocol 选 none
  • RPC Protocol Settings:
    • Protocol: dubbo
    • Timeout: 1000
    • Versions:1.0.0
  • Interface Settings (接口与方法):
    • Interface: cn.techwolf.victoria.api.def.MessageFilterApi
    • Method: send
  • Method Configuration:
    • ParamType: 填入该 send 方法入参的完整 Java 类名(JMeter Dubbo 插件需要严格的类型匹配,需查阅服务源码或 API 文档获取准确的包装类名)。如果接口定义直接接受 JSON 字符串,则填 java.lang.String
      查看 victoria/api/def/MessageFilterApi.java文件,可知send入参类名为cn.techwolf.international.model.request.NotifyRequest
      image

    • ParamValue: 填入你的 JSON 报文。

      {"receiveId":"42133","receiveType":"OTD_USER_ID","identity":"GEEK","source":"1","message":{"class":"cn.techwolf.international.model.request.template.channel.AppPushTemplateMessage","templateCode":"15","paramMap":{"userName":"爬虫职位-蒬鈥杭枭","body":"app推送消息体","shortLink":"otd://offertoday.app/openwith?type=openGeekRecentViewerPage"}}}
      

image

3. 配置监听器 (Listener)

  • 添加 View Results Tree (察看结果树)、 Summary ReportAggregate Report
  • 执行单次请求,检查响应数据(Response Data)是否返回成功状态码,确认序列化与反序列化链路畅通。

CLI执行压力测试

1. 修改线程组

  • 参数预设
    • Number of Threads (users): 500 (根据你的客户端机器性能和目标 QPS 设定,逐步上调)。
    • Ramp-up period: 10 (10 秒内启动 500 个线程,避免瞬间启动导致客户端自身假死)。
    • Loop Count: 勾选 Infinite (永远循环)。
    • Duration (seconds): 300 (持续压测 5 分钟以观察 GC 表现和系统稳定性)。

2. 调优JMeter JVM 参数

编辑 jmeter 启动脚本,修改 JVM 堆内存设置,防止客户端 OOM 成为瓶颈。

# 将默认的 1G 调整为 4G 或 8G,视施压机物理内存而定
HEAP="-Xms4g -Xmx4g -XX:MaxMetaspaceSize=512m"

3. 执行无头模式压测命令

将当前测试计划保存为 dubbo_stress.jmx,然后执行

jmeter -n -t /Users/boss/Lab/dubbo_stress.jmx -l /Users/boss/Lab/result/result.jtl -e -o /Users/boss/Lab/result/html_report
  • -n: 非 GUI 模式。
  • -t: JMX 脚本路径。
  • -l: 原始结果文件 (JTL) 路径。
  • -e -o: 压测结束后自动生成 HTML 可视化报告。
posted @ 2026-04-09 15:06  夜歌乘年少  阅读(62)  评论(0)    收藏  举报