项目作者: youzan

项目描述 :
A gatling plugin for running load tests on Apache Dubbo(https://github.com/apache/incubator-dubbo) and other java ecosystem.
高级语言: Scala
项目地址: git://github.com/youzan/gatling-dubbo.git
创建时间: 2018-12-16T16:20:20Z
项目社区:https://github.com/youzan/gatling-dubbo

开源协议:

下载


Gatling-Dubbo 2.0

【招聘】Java开发、测试开发等岗位,有意者请将简历投递至<canyuns【@】163.com>

Gatling的非官方Dubbo压测插件,基于Gatling 2.3.1,插件已在Dubbo 2.6.5上测试,但理论上所有Dubbo版本都适用,2.0插件采用普通API调用方式执行压测请求,如果你想使用泛化调用方式执行压测请求,请参考1.0插件,推荐使用2.0插件,即采用普通API调用方式,因为 dubbo 官方推荐生产上使用该方式,所以以同样的方式压测得到的结果,更具有参考意义,且2.0插件无需 dubbo 框架做任何改造。

区别于 Gatling-Dubbo 1.0 只支持 dubbo 压测,Gatling-Dubbo 2.0 不仅支持 dubbo 压测,还支持非 dubbo 的其他 java 调用压测,因为脚本中的 f 怎么写控制权在你手里,就像使用 Jmeter 压测 java 一样。

使用方法

打包Jar

按需修改配置:

  • 默认为4核8G内存机器配置了200线程池,与dubbo线程池一致,你也可以根据自己的机器配置使用API调整线程池大小,下述
  • 如果你使用其他Dubbo版本,请修改根目录下build.sbt中的libraryDependencies配置

如果你不需要修改配置,可以略过以下打包步骤,直接下载Jar包(该 Jar 包无应用依赖)

项目依赖sbt,请安装sbt 1.2.1,详见官方文档,执行

  1. $ git clone https://github.com/youzan/gatling-dubbo.git
  2. $ cd gatling-dubbo
  3. $ sbt assembly

将上述jar包拷贝到/your-path-to/gatling-charts-highcharts-bundle-2.3.1/lib目录

  1. $ cp /your-path-to/gatling-dubbo/target/scala-2.12/gatling-dubbo-assembly-1.0.jar /your-path-to/gatling-charts-highcharts-bundle-2.3.1/lib

依赖

由于插件采用普通API调用方式执行压测请求,所以需要引入服务特定的 API 包,为了演示方便,这里直接将依赖写在了项目根目录下的 build.sbt 中:

  1. name := "gatling-dubbo"
  2. version := "1.0"
  3. scalaVersion := "2.12.6"
  4. libraryDependencies ++= Seq(
  5. "io.gatling" % "gatling-core" % "2.3.1" % "provided",
  6. "com.alibaba" % "dubbo" % "2.6.5",
  7. "com.youzan.xxx" % "xxx-api" % "1.xxx-RELEASE" exclude("ch.qos.logback", "logback-classic") //应用 API 包
  8. )
  9. assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)

创建Simulation和相应的json数据文件

参考gatling-dubbo/src/test/scala目录下的DubboTest.scala和data.json

DubboTest.scala具体说明请参考示例

check 说明
目前 check 支持两种,jsonPath 和 custom,如果 dubbo 返回值可以转化为 json(如 PlainResult、Map 等),则推荐使用 jsonPath 校验结果,如果 dubbo 返回值是 String 等类型,则推荐使用 custom 校验结果,即自定义校验逻辑,custom 的示例如下:

  1. .check(custom((response: String) => {
  2. print(response)
  3. response == "expected response"
  4. }, "option error message"))

示例中展示的是单接口的例子,如果你想探测应用单机的真实水位,可以结合使用 gatling 的 randomSwitch 混合多接口且按生产环境真实的接口比例同时进行压测。

data.json

  1. [
  2. {
  3. "kdtId": 160,
  4. "page": 1
  5. },
  6. {
  7. "kdtId": 160,
  8. "page": 2
  9. },
  10. {
  11. "kdtId": 160,
  12. "page": 3
  13. }
  14. ]

数据采用 json 数组保存,其中每一个 json 对象都是一次压测请求需要的完整参数,且为了方便通过 session 设置动态参数,数据结构采用一维结构,风格同 Jmeter。

执行Dubbo压测

  1. $ bin/gatling.sh
  2. GATLING_HOME is set to /your-path-to/gatling-charts-highcharts-bundle-2.3.1
  3. Choose a simulation number:
  4. [0] dubbo.DubboTest
  5. 0
  6. Select simulation id (default is 'dubbotest'). Accepted characters are a-z, A-Z, 0-9, - and _
  7. Select run description (optional)
  8. Simulation dubbo.DubboTest started...
  9. ================================================================================
  10. 2019-04-04 10:12:44 5s elapsed
  11. ---- Requests ------------------------------------------------------------------
  12. > Global (OK=56 KO=0 )
  13. > com.youzan.xxx.XxxService (OK=56 KO=0 )
  14. ---- scenario of xxx -----------------------------------------------------------
  15. [--------------------------------------------------------------------------] 0%
  16. waiting: 0 / active: 10 / done:0
  17. ================================================================================
  18. ...
  19. ================================================================================
  20. 2019-04-04 10:13:11 31s elapsed
  21. ---- Requests ------------------------------------------------------------------
  22. > Global (OK=320 KO=0 )
  23. > com.youzan.xxx.XxxService (OK=320 KO=0 )
  24. ---- scenario of xxx -----------------------------------------------------------
  25. [--------------------------------------------------------------------------] 0%
  26. waiting: 0 / active: 10 / done:0
  27. ================================================================================
  28. Simulation dubbo.DubboTest completed in 31 seconds
  29. Parsing log file(s)...
  30. Parsing log file(s) done
  31. Generating reports...
  32. ================================================================================
  33. ---- Global Information --------------------------------------------------------
  34. > request count 320 (OK=320 KO=0 )
  35. > min response time 44 (OK=44 KO=- )
  36. > max response time 343 (OK=343 KO=- )
  37. > mean response time 62 (OK=62 KO=- )
  38. > std deviation 42 (OK=42 KO=- )
  39. > response time 50th percentile 49 (OK=49 KO=- )
  40. > response time 75th percentile 53 (OK=53 KO=- )
  41. > response time 95th percentile 160 (OK=160 KO=- )
  42. > response time 99th percentile 275 (OK=275 KO=- )
  43. > mean requests/sec 10.323 (OK=10.323 KO=- )
  44. ---- Response Time Distribution ------------------------------------------------
  45. > t < 800 ms 320 (100%)
  46. > 800 ms < t < 1200 ms 0 ( 0%)
  47. > t > 1200 ms 0 ( 0%)
  48. > failed 0 ( 0%)
  49. ================================================================================
  50. Reports generated in 0s.
  51. Please open the following file: /your-path-to/gatling-charts-highcharts-bundle-2.3.1/results/dubbotest-1554343959840/index.html

打开上述报告查看更多压测信息:
Reports

gatling-dubbo 在有赞的应用示例

I 应用基线性能评估与容量规划:
Reports

II 中心化限流效果验证:
Reports

License

Apache License, Version 2.0