[開源性能測試項目]RoadRunner4.0.0[大版本升級]

代碼在這裏:
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個併發用戶:

[img]http://dl.iteye.com/upload/attachment/214260/6fa059ab-2dee-3998-99bb-5ddd36ae1bbf.png[/img]

控制檯輸出如下:

[quote]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"[/quote]

如果你覺得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']


執行完畢後,我們看一下得到的監控數據:

[img]http://dl.iteye.com/upload/attachment/214264/f2cede99-2fe6-38b8-91f4-e0337024df42.png[/img]


這個版本的RoadRunner其實是在我另外一個性能測試解決方案中抽取出來了,
之前在對公司的分佈式存儲做性能測試,寫了一套針對分佈式存儲的測試方案,
有用例,有調度,還有監控,
後來覺得太專一了,不如把有用的東西合併到RoadRunner中,並對RR做一次大升級,於是就產生了4.0版本的RR.

大家可以看到在源碼的bin和controller目錄中,還放着對分佈式系統做性能測試的解決方案:

[img]http://dl.iteye.com/upload/attachment/214266/b487ea48-24ed-39fc-b725-90308d744ad8.png[/img]

用例分別爲:
大文件的dd操作
小文件的copy操作(svn)
mysql的訪問操作
三種.

如果你正好也要對分佈式存儲做性能測試,那麼直接拿RoadRunner就可以用了,用例和代碼都不需要寫了,細節改一改就行了.

這個版本的RR我還要整理一下,功能全都可用了,但邊邊角角修飾一下.

用Ruby做性能測試絕對不是夢,有人以爲不行,我偏要證明!

大家有問題儘管看測試代碼,很多的,而且我還會多寫測試代碼,一看就知道怎麼用.
更深入的瞭解就看源碼吧.開源的好處.

之前有過介紹RR的文章,
我貼個鏈接:http://charlescui.iteye.com/blog/520197

有問題和建議都寫出來,我就是喜歡這個,所以我會盡力做好的.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章