14-Dubbo测试

2021-05-27 11:27:53 浏览数 (1)

Dubbo

目前是apache托管的开源项目,能够实现RPC

  • 注册中心:zookeeper 默认端口2181
  • 服务提供者:应用程序
  • 服务消费者:使用服务方
  • 服务监控:监控

测试服务器环境

测试服务器IP:192.168.9.3 zookeeper端口20181 服务提供者:

  • membet1:20882
  • membet2:20883

测试dubbo的方法

1.使用Telnet的方式

在mac上运行telnet需要环境

使用Homebrew安装一下

代码语言:javascript复制
$ brew install telnet
代码语言:javascript复制
$ telnet 192.168.9.3 20882

使用ls可以查看提供的服务的名称也就是「接口」

使用ls -l可以查看接口的所有方法

代码语言:javascript复制
dubbo>ls
com.lemon.member.service.MemberService
dubbo>ls -l com.lemon.member.service.MemberService
com.lemon.member.pojo.Member getMember(com.lemon.member.pojo.Member)
void recharge(com.lemon.member.pojo.Recharger)
void withdraw(com.lemon.member.pojo.WithDrawer)
void add(com.lemon.member.pojo.Member)
void update(com.lemon.member.pojo.Member)
java.util.List list()

方法括号中有内容,就是带有参数的方法

Telnet

使用cd进入到服务的名称位置后

代码语言:javascript复制
dubbo>ls -l
com.lemon.member.service.MemberService -> dubbo://192.168.9.3:20882/com.lemon.member.service.MemberService?anyhost=true&application=futureloan-member-service&dubbo=2.5.3&interface=com.lemon.member.service.MemberService&methods=add,recharge,getMember,update,list,withdraw&pid=2333&retries=3&revision=0.0.1-SNAPSHOT&side=provider&timestamp=1619651401859

调用接口的方法:invoke 接口.方法()

代码语言:javascript复制
dubbo>invoke com.lemon.member.service.MemberService.list()

list方法

2.使用jmeter

jmeter-plugins-dubbo-2.7.3-jar-with-dependencies.jar放入libext中后,重启Jmeter

添加「取样器」后可以看到增加了「Dubbo Sample」

取样器

在「Registry Settings」填入服务器信息后点击「Get Provider List」

填写

可以看到我们可以查看相关方法。这些方法与刚才使用Telnet查看的一致

查看方法

我们选择「list」后点击运行

可以在「查看结果树」中查看与Telnet中一致的内容

查看结果

查看add的接口文档

add接口文档

入参

其他性能测试工具

ab和wrk都是快速响应性能测试工具

wrk

安装
代码语言:javascript复制
$ git clone https://gitee.com/mirrors/wrk.git
$ cd wrk/
$ make
代码语言:javascript复制
(base) 192:~ zhongxin$ mkdir wrk
(base) 192:~ zhongxin$ cd wrk/
(base) 192:wrk zhongxin$ ls
(base) 192:wrk zhongxin$ git clone https://gitee.com/mirrors/wrk.git
Cloning into 'wrk'...
remote: Enumerating objects: 1103, done.
remote: Total 1103 (delta 0), reused 0 (delta 0), pack-reused 1103
Receiving objects: 100% (1103/1103), 37.83 MiB | 2.02 MiB/s, done.
Resolving deltas: 100% (345/345), done.
(base) 192:wrk zhongxin$ ls
wrk
(base) 192:wrk zhongxin$ cd wrk/
(base) 192:wrk zhongxin$ make
用法
代码语言:javascript复制
-c 连接数
-d 持续运行失常
-t 线程数
-s Lua脚本
-H 添加请求头
-v 查看版本信息
测试语句
代码语言:javascript复制
./wrk -t4 -c100 -d30s --latency https://www.baidu.com/
代码语言:javascript复制
(base) 192:wrk zhongxin$ ./wrk -t4 -c100 -d30s --latency https://www.baidu.com/
Running 30s test @ https://www.baidu.com/
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max    /- Stdev
    Latency   151.92ms  126.20ms   1.99s    95.29%
    Req/Sec   170.01     43.17   333.00     81.93%
  Latency Distribution
     50%  128.98ms
     75%  137.80ms
     90%  195.57ms
     99%  802.22ms
  19933 requests in 30.10s, 298.16MB read
  Socket errors: connect 0, read 156, write 0, timeout 45
Requests/sec:    662.23
Transfer/sec:      9.91MB

wrk

  • Avg 平均响应
  • Stdev 标准方差
  • Max 最大值
  • /- Stdev 偏差比
  • Latency 响应时间分布
  • Req/sec 每秒请求数

ab

代码语言:javascript复制
(base) 192:wrk zhongxin$ ab -V
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
代码语言:javascript复制
(base) 192:wrk zhongxin$ ab -help
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (TLS1, TLS1.1, TLS1.2 or ALL)
    -E certfile     Specify optional client certificate chain and private key
用法
代码语言:javascript复制
-c 并发用户数
-n 总共请求数
-t 持续运行时长
-T 请求头Content-Type 默认text/plan
-p post请求
-m 请求方法名称
-e 请求结果输出到csv文件
-v 查看版本信息
测试语句
代码语言:javascript复制
ab -c 10 -n 10000 https://www.baidu.com/
代码语言:javascript复制
(base) 192:wrk zhongxin$ ab -c 10 -n 10000 https://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.baidu.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        BWS/1.1
Server Hostname:        www.baidu.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        ECDH P-256 256 bits
TLS Server Name:        www.baidu.com

Document Path:          /
Document Length:        227 bytes

Concurrency Level:      10
Time taken for tests:   107.936 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      10818825 bytes
HTML transferred:       2270000 bytes
Requests per second:    92.65 [#/sec] (mean)
Time per request:       107.936 [ms] (mean)
Time per request:       10.794 [ms] (mean, across all concurrent requests)
Transfer rate:          97.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[ /-sd] median   max
Connect:       31   80  23.8     77    1375
Processing:     9   28  14.1     24     172
Waiting:        9   24  10.8     21     158
Total:         47  108  29.4    103    1404

Percentage of the requests served within a certain time (ms)
  50%    103
  66%    112
  75%    119
  80%    123
  90%    139
  95%    153
  98%    177
  99%    197
 100%   1404 (longest request)
(base) 192:wrk zhongxin$

ngrinder

nGrinder 是基于 Grinder 开源项目,由 NHN 公司的开发团队进行了重新设计和完善。nGrinder 是一款非常易用,有简洁友好的用户界面和 controller-agent 分布式结构的强大的压力测试工具。 它的脚本,支持 Jython、Groovy 两种语言。 官方网站:http://naver.github.io/ngrinder/ GitHub 地址:https://github.com/naver/ngrinder

运行

  • 下载 war 包 https://github.com/naver/ngrinder/releases
代码语言:javascript复制
$ Java -jar ngrinder-controller-xx.war
  1. 登录 Web 管理界面,点击顶部导航用户信息,在下拉信息中,选择‘下载代理’,将会自动下载 Agent,选择‘下载监控’,将自动下载 monitor 监控
  2. 解压、启动 Agent:双击 run_agent.bat(windows) ‘./run_agent.sh’(linux mac)
  3. 代理服务启动后,在页面 admin > 代理管理,就能看到代理服务器

制作脚本

在首页,Quick Start 文本框中输入 要录制脚本的地址,第二个文本框,选择生成脚本的语言类型,点击 开始测试 按钮,就可生成脚本。或者点击,菜单栏中的‘脚本

点击‘新建脚本’按钮,弹窗中,选择脚本类型,填写脚本名称,被测 URL(可选),点击‘创建’即可创建出一个对应脚本语言的脚本

点击脚本列表 ‘脚本名称’列中的脚本名称,即可打开对应的脚本详情

性能测试

  1. 点击顶部菜单栏中的‘性能测试’菜单
  2. 再点击 ‘创建测试
  3. 在这个页面中,填写‘测试名称’,填写‘代理’数量(根据后面的提示), 选择‘脚本’,如果脚本中有服务器地址,则可以不选择目标主机,如果没有,则需要添加‘目标主机’,然后点击右上角的‘保存 并运行’,这样就可以按照你的设计,进行性能测试了。
  4. 性能测试执行过程成功,状态为绿色(红色为执行过程中出错),执行成功,会展示一份测试报告概要。

0 人点赞