http://code.google.com/p/roadrunner/
安装:
gem install RoadRunner –source http://rubygems.org
RoadRunner4.0版本加了两个非常重要,也是很多同学很期待的功能:
1.进程模式
2.性能监控(监控Xnix系统)
下面是进程模式的一个例子,
功能是测试下载一个文件
#!/usr/bin/env ruby #下载一个mac版本的QQ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require 'roadrunner' dl=RoadRunner.new =begin RoadRunner::mode => /thread/,/t/ /process/,/p/ else. Defined in run.rb 当mode为进程的时候,RoadRunner将产生最真实的压力 =end dl.mode='p' dl.init do # users决定同时有多少并发用户,就是多少个进程 # iterations决定每个用户执行多少次 dl.users,dl.iterations=5,10 end dl.action do sleep 10 %x{wget "http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_B1_606.dmg" 1>/dev/null 2>&1} end dl.ended do end dl.run dl.report p "Tps could get : RoadRunner::tps => #{dl.tps}"
如果哪位同学觉得RR用起来复杂,那就错了!
上面那个例子这么写纯粹是为了代码工整,
简化后的写法如下:
#!/usr/bin/env ruby #简洁版本 require 'roadrunner' dl=RoadRunner.new dl.mode,dl.users,dl.iterations='p',5,10 dl.action{ %x{wget "http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_B1_606.dmg" 1>/dev/null 2>&1} } dl.run dl.report
在做并发性能测试的时候我们可以监控系统进程,
看看是否真得起了定义中的5个并发用户:
![[开源性能测试项目]RoadRunner4.0.0[大版本升级]_第1张图片](http1://img.it610.com/image/product/f14f8be9ca764933977677e17e6838cd.png)
控制台输出如下:
引用
charlesdemacbook-pro:test Cui$ ruby download_processes.rb
" ********************RoadRunner********************"
" * ---Run , on your way.*"
" **************************************************"
" Running......"
"Processes<[3158, 3159, 3160, 3161, 3162]> working."
.
.
"Main process<3157> going down."
"\n"
" Ending......"
" Wait for moment,the report is collecting......"
***************Performance Reports****************
user system total real
0.010000 0.010000 23.090000 (355.002860)
----------------------------------------------------------------
The Virtual User is 5.
Total Execute 50 Action(s).
Total Cost 355.002859830856 Second(s).
This Scenario's TPS : 0.140843935803286.
The longest action cost 0 seconds.
----------------Transaction Report----------------
----------------------------------------------------------------
User defined params as below:
******************End of Reports******************
"Tps could get : RoadRunner::tps => 0.140843935803286"
" ********************RoadRunner********************"
" * ---Run , on your way.*"
" **************************************************"
" Running......"
"Processes<[3158, 3159, 3160, 3161, 3162]> working."
.
.
"Main process<3157> going down."
"\n"
" Ending......"
" Wait for moment,the report is collecting......"
***************Performance Reports****************
user system total real
0.010000 0.010000 23.090000 (355.002860)
----------------------------------------------------------------
The Virtual User is 5.
Total Execute 50 Action(s).
Total Cost 355.002859830856 Second(s).
This Scenario's TPS : 0.140843935803286.
The longest action cost 0 seconds.
----------------Transaction Report----------------
----------------------------------------------------------------
User defined params as below:
******************End of Reports******************
"Tps could get : RoadRunner::tps => 0.140843935803286"
如果你觉得Ruby语言自身做性能测试有点慢,那你可以在执行性能测试的时候用其它能和ruby互动的语言,
而RoadRunner起到一个调度的作用.
理论上进程模式是性能最好的.
目前跟进程模式有关的,但没有完成的一点需求就是,如何收集每个进程的性能测试信息,我的大概思路是,
把各个进程的数据存到本地文件,或者memcache中,不过这并不重要.最重要的如何让RoadRunner更快的问题已经解决了.
下面是性能监控的一个例子:
性能监控的使用非常简单,只要用这个方法
RoadRunnerModule::RRMonitor.monit(File.join(File.dirname(__FILE__),'..','conf','servers.yaml'),rrpi.log,cmd,"Pi-Monitor-Performance")
再用一个prco把要操作的代码放到块里面,跟在这个方法后面就可以监控了.
被监控主机的ip和帐号等信息放到一个配置文件中=>
File.join(File.dirname(__FILE__),'..','conf','servers.yaml')
该文件如下:
--- 10.250.3.25: :username: admin :ts: Test-Performance :password: "123456" 10.250.3.26: :username: admin :ts: Test-Performance :password: "123456" 10.250.6.30: :username: admin :ts: Test-Performance :password: "123456" 10.250.3.27: :username: admin :ts: Test-Performance :password: "123456" 10.250.3.28: :username: admin :ts: Test-Performance :password: "123456" 10.250.3.29: :username: admin :ts: Test-Performance :password: "123456" 10.250.3.30: :username: admin :ts: Test-Performance :password: "123456"
ts指的是跟存储性能监控数据文件路径相关的东西,全称是"test scenario"的意思,可以不写.
可以看一下这个方法的定义=>
RoadRunnerModule::RRMonitor.new({:server=>ip, :log=>log, :username=>obj[:username], :password=>obj[:password], :ts=>obj[:obj]||ts})
测试代码如下:
#!/usr/bin/env ruby # 莱布尼兹公式计算圆周率 #rrpi.global[:deep]代表计算的深度 #深度越深,计算越精确,当然也越耗时 $:.unshift File.join(File.dirname(__FILE__),'..','lib') require 'roadrunner' rrpi=RoadRunner.new rrpi.init do rrpi.global[:pi],rrpi.global[:deep]=0,100 # users决定同时有多少并发用户一起执行action # iterations决定每个用户执行多少次 rrpi.users,rrpi.iterations=10,1000 end rrpi.action do # 新增加了iterationId和userId两个接口方法, # 可以通过iterationId获得当前action执行到第一次 # 可以通过userId获得当前action执行用户的id # puts rrpi.iterationId # puts rrpi.userId 1.upto(rrpi.global[:deep]){|x|rrpi.global[:pi]+=((-1)**(x+1)*1.0/(x*2-1))} end rrpi.ended do rrpi.global[:pi]*=4 #rrpi.global={} end cmd=['ifstat','iostat 3','while((1>0));do sar -u -d 3 10; done','vmstat 3','while((1>0));do sar -u -n DEV 3 10; done'] RoadRunnerModule::RRMonitor.monit(File.join(File.dirname(__FILE__),'..','conf','servers.yaml'),rrpi.log,cmd,"Pi-Monitor-Performance"){ rrpi.run } rrpi.report p "Tps could get : RoadRunner::tps => #{rrpi.tps}"
需要监控的东西其实可以自己定义,
默认的话,我定义了如下监控内容:
cmd=['ifstat','iostat 3','while((1>0));do sar -u -d 3 10; done','vmstat 3','while((1>0));do sar -u -n DEV 3 10; done']
执行完毕后,我们看一下得到的监控数据:
![[开源性能测试项目]RoadRunner4.0.0[大版本升级]_第2张图片](http1://img.it610.com/image/product/20e7eefdefbd4b7a983666f4debf6939.jpg)
这个版本的RoadRunner其实是在我另外一个性能测试解决方案中抽取出来了,
之前在对公司的分布式存储做性能测试,写了一套针对分布式存储的测试方案,
有用例,有调度,还有监控,
后来觉得太专一了,不如把有用的东西合并到RoadRunner中,并对RR做一次大升级,于是就产生了4.0版本的RR.
大家可以看到在源码的bin和controller目录中,还放着对分布式系统做性能测试的解决方案:
![[开源性能测试项目]RoadRunner4.0.0[大版本升级]_第3张图片](http1://img.it610.com/image/product/e6b4fd6c21ee4efbbeb092dc001fbabf.jpg)
用例分别为:
大文件的dd操作
小文件的copy操作(svn)
mysql的访问操作
三种.
如果你正好也要对分布式存储做性能测试,那么直接拿RoadRunner就可以用了,用例和代码都不需要写了,细节改一改就行了.
这个版本的RR我还要整理一下,功能全都可用了,但边边角角修饰一下.
用Ruby做性能测试绝对不是梦,有人以为不行,我偏要证明!
大家有问题尽管看测试代码,很多的,而且我还会多写测试代码,一看就知道怎么用.
更深入的了解就看源码吧.开源的好处.
之前有过介绍RR的文章,
我贴个链接:http://charlescui.iteye.com/blog/520197
有问题和建议都写出来,我就是喜欢这个,所以我会尽力做好的.