roadrunner 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/test/baidu.rb ADDED
@@ -0,0 +1,100 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'roadrunner'
4
+ # => I'll use the Httparty lib to make http request
5
+ # => as the LR method LoadRunner#web_url() and
6
+ # => LoadRunner#web_submit_data() and LoadRunner#web_custom_request()
7
+ require 'httparty'
8
+
9
+ # => if one of RoadRunner.new's argument is block
10
+ # => then the database connection will be established
11
+ # => and the below method could be used:
12
+ # => RoadRunner#save_report()
13
+
14
+ # => IMPORTANT:
15
+ # => if a block is given to RoadRunner#new
16
+ # => make sure there is exist the below three tables in the target DATABASE:
17
+ # => scenarios transactions records
18
+ # => and the three tables is defined in db.rb,
19
+ # => otherwise if the three tables does not exist in the target DATABASE,
20
+ # => Roadrunner will auto create the three tables.
21
+
22
+ baidu=RoadRunner.new do |session|
23
+ {:adapter=>"mysql",
24
+ :encoding=>"utf8",
25
+ :database=>"dpmp",
26
+ :username=>"root",
27
+ :password=>"alisoft",
28
+ :host=>"10.2.226.133"}
29
+ end
30
+
31
+
32
+ # => RoadRunner#mode could be set as such value:
33
+ # => 'thread'
34
+ # => 'sequence' or other string is same.
35
+ # => when thread mode is set,
36
+ # => the RoadRunner#action will run as thread,
37
+ # => and main thread will fork RoadRunner#users threads to run every action block
38
+ #baidu.mode = 'thread'
39
+
40
+ baidu.init do
41
+ # RoadRunner#users : the concurrency user do the action.
42
+ # RoadRunner#iterations : every user execute the action such times
43
+ baidu.users,baidu.iterations=4,25
44
+ end
45
+
46
+ # => RoadRunner#any_other_method()
47
+ # => if any_other_method() is not exsit in RoadRunner#methods
48
+ # => the RoadRunner#any_other_method(){} will be dealed as RoadRunner#transaction('any_other_method'){}
49
+ # => and the important is:
50
+ # => the block of RoadRunner#transaction('any_other_method'){}
51
+ # => the value of the last expression in the block
52
+ # => will determin this transaction's current action is pass or not!!!
53
+ # =>
54
+ # => status's value is:
55
+ # => 0=>success
56
+ # => -1=>faile
57
+ # => ruby code as below:
58
+ # => case status
59
+ # => when false,'false','-1',-1 then status = -1
60
+ # => else status = 0
61
+ # => end
62
+ baidu.action do
63
+ baidu.query do
64
+ resp = HTTParty.get('http://www.baidu.com/s?wd=charlescui')
65
+ # => check request header if contain the certain key words
66
+ # => same as the LR method LoadRunner#web_reg_find("Search=Headers")
67
+ #resp.headers.inspect.include? 'Apache'
68
+ end
69
+ # => Log4r is integrade in the RoadRunner and you could use it as below.
70
+ # => RoadRunner#log.debug
71
+ # => RoadRunner#log.info
72
+ # => RoadRunner#log.warn
73
+ # => RoadRunner#log.error
74
+ # => RoadRunner#log.fatal
75
+ baidu.image do
76
+ resp = HTTParty.get('http://image.baidu.com/i?tn=baiduimage&ct=201326592&cl=2&lm=-1&pv=&word=girl&z=0')
77
+ # => check request body
78
+ # => same as the LR method LoadRunner#web_reg_find()
79
+ #resp.body.include? 'CalendarPopup'
80
+ end
81
+ baidu.mp3 do
82
+ resp = HTTParty.get('http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word=anny&lm=-1')
83
+ # => check request body
84
+ # => same as the LR method LoadRunner#web_reg_find()
85
+ #resp.body.include? 'CalendarPopup'
86
+ end
87
+ end
88
+
89
+ # => RoadRunner#run
90
+ # => this method will execute the RoadRunner script
91
+ # => the performance will start.
92
+ baidu.run
93
+ # => RoadRunner#report
94
+ # => this method will output the report to the STDOUT
95
+ baidu.report
96
+ # => RoadRunner#save_report
97
+ # => this method will save the report to database if the database connection is established
98
+ # => :script is one of the arguments
99
+ # => if the :script is set and the value of :script is a path,the file's content of the path will be saved in database.
100
+ baidu.save_report(:name=>"baiduQueryImageMP3",:script=>__FILE__)
data/test/blog.rb ADDED
@@ -0,0 +1,100 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'roadrunner'
4
+ # => I'll use the Httparty lib to make http request
5
+ # => as the LR method LoadRunner#web_url() and
6
+ # => LoadRunner#web_submit_data() and LoadRunner#web_custom_request()
7
+ require 'httparty'
8
+
9
+ # => if one of RoadRunner.new's argument is block
10
+ # => then the database connection will be established
11
+ # => and the below method could be used:
12
+ # => RoadRunner#save_report()
13
+
14
+ # => IMPORTANT:
15
+ # => if a block is given to RoadRunner#new
16
+ # => make sure there is exist the below three tables in the target DATABASE:
17
+ # => scenarios transactions records
18
+ # => and the three tables is defined in db.rb,
19
+ # => otherwise if the three tables does not exist in the target DATABASE,
20
+ # => Roadrunner will auto create the three tables.
21
+
22
+ blog=RoadRunner.new do |session|
23
+ {:adapter=>"mysql",
24
+ :encoding=>"utf8",
25
+ :database=>"dpmp",
26
+ :username=>"root",
27
+ :password=>"alisoft",
28
+ :host=>"10.2.226.133"}
29
+ end
30
+
31
+
32
+ # => RoadRunner#mode could be set as such value:
33
+ # => 'thread'
34
+ # => 'sequence' or other string is same.
35
+ # => when thread mode is set,
36
+ # => the RoadRunner#action will run as thread,
37
+ # => and main thread will fork RoadRunner#users threads to run every action block
38
+ #blog.mode = 'thread'
39
+
40
+ blog.init do
41
+ # RoadRunner#users : the concurrency user do the action.
42
+ # RoadRunner#iterations : every user execute the action such times
43
+ blog.users,blog.iterations=2,25
44
+ end
45
+
46
+ # => RoadRunner#any_other_method()
47
+ # => if any_other_method() is not exsit in RoadRunner#methods
48
+ # => the RoadRunner#any_other_method(){} will be dealed as RoadRunner#transaction('any_other_method'){}
49
+ # => and the important is:
50
+ # => the block of RoadRunner#transaction('any_other_method'){}
51
+ # => the value of the last expression in the block
52
+ # => will determin this transaction's current action is pass or not!!!
53
+ # =>
54
+ # => status's value is:
55
+ # => 0=>success
56
+ # => -1=>faile
57
+ # => ruby code as below:
58
+ # => case status
59
+ # => when false,'false','-1',-1 then status = -1
60
+ # => else status = 0
61
+ # => end
62
+ blog.action do
63
+ blog.homepage do
64
+ resp = HTTParty.get('http://charlescui.javaeye.com')
65
+ # => check request header if contain the certain key words
66
+ # => same as the LR method LoadRunner#web_reg_find("Search=Headers")
67
+ #resp.headers.inspect.include? 'Apache'
68
+ end
69
+ # => Log4r is integrade in the RoadRunner and you could use it as below.
70
+ # => RoadRunner#log.debug
71
+ # => RoadRunner#log.info
72
+ # => RoadRunner#log.warn
73
+ # => RoadRunner#log.error
74
+ # => RoadRunner#log.fatal
75
+ blog.guest_book do
76
+ resp = HTTParty.get('http://charlescui.javaeye.com/blog/guest_book')
77
+ # => check request body
78
+ # => same as the LR method LoadRunner#web_reg_find()
79
+ #resp.body.include? 'CalendarPopup'
80
+ end
81
+ blog.album do
82
+ resp = HTTParty.get('http://charlescui.javaeye.com/blog/album')
83
+ # => check request body
84
+ # => same as the LR method LoadRunner#web_reg_find()
85
+ #resp.body.include? 'CalendarPopup'
86
+ end
87
+ end
88
+
89
+ # => RoadRunner#run
90
+ # => this method will execute the RoadRunner script
91
+ # => the performance will start.
92
+ blog.run
93
+ # => RoadRunner#report
94
+ # => this method will output the report to the STDOUT
95
+ blog.report
96
+ # => RoadRunner#save_report
97
+ # => this method will save the report to database if the database connection is established
98
+ # => :script is one of the arguments
99
+ # => if the :script is set and the value of :script is a path,the file's content of the path will be saved in database.
100
+ blog.save_report(:name=>"blogHomeGuestBookAlbum",:script=>__FILE__)
Binary file
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
4
+
5
+ require 'roadrunner'
6
+
7
+ dl=RoadRunner.new
8
+
9
+ =begin
10
+ RoadRunner::mode =>
11
+ /thread/,/t/
12
+ /process/,/p/
13
+ else.
14
+ Defined in run.rb
15
+ 当mode为进程的时候,RoadRunner将产生最真实的压力
16
+ =end
17
+
18
+ dl.mode='p'
19
+
20
+ dl.init do
21
+ # users决定同时有多少并发用户一起执行action
22
+ # iterations决定每个用户执行多少次
23
+ dl.users,dl.iterations=5,10
24
+ end
25
+
26
+
27
+ dl.action do
28
+ sleep 10
29
+ %x{wget "http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_B1_606.dmg" 1>/dev/null 2>&1}
30
+ end
31
+
32
+ dl.ended do
33
+ end
34
+
35
+ dl.run
36
+ dl.report
37
+
38
+ p "Tps could get : RoadRunner::tps => #{dl.tps}"
data/test/fibonacci.rb ADDED
@@ -0,0 +1,27 @@
1
+ # 计算斐波那契数列
2
+ # Array.new(200)数组长度决定数列长度
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
5
+
6
+ require 'roadrunner'
7
+
8
+ rrfib=RoadRunner.new
9
+
10
+ rrfib.init do
11
+ rrfib.global[:x],rrfib.global[:y]=0,1
12
+
13
+ # users决定同时有多少并发用户一起执行action
14
+ # iterations决定每个用户执行多少次
15
+ rrfib.users,rrfib.iterations=10,100
16
+ end
17
+
18
+ rrfib.action do
19
+ rrfib.global[:fib]=Array.new(200) {|i| [0,1].include?(i) ? 1 : (rrfib.global[:x],rrfib.global[:y] = rrfib.global[:y],rrfib.global[:x]+rrfib.global[:y])&&(rrfib.global[:x]+rrfib.global[:y]) }
20
+ end
21
+
22
+ rrfib.ended do
23
+ #rrfib.global={}
24
+ end
25
+
26
+ rrfib.run
27
+ rrfib.report
data/test/get163.rb ADDED
@@ -0,0 +1,38 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'roadrunner'
4
+ require 'httparty'
5
+
6
+ get163=RoadRunner.new do |session|
7
+ session=
8
+ {:adapter=>"mysql",
9
+ :encoding=>"utf8",
10
+ :database=>"dpmp",
11
+ :username=>"root",
12
+ :password=>"alisoft",
13
+ :host=>"10.2.226.133"}
14
+ end
15
+ get163.mode = 'thread'
16
+
17
+ get163.init do
18
+ # users决定同时有多少并发用户一起执行action
19
+ # iterations决定每个用户执行多少次
20
+ get163.users,get163.iterations=10,100
21
+ end
22
+
23
+ get163.action do
24
+ get163.homepage do
25
+ resp = HTTParty.get('http://www.163.com')
26
+ # p resp.headers.inspect
27
+ true
28
+ end
29
+ get163.sports do
30
+ resp = HTTParty.get('http://sports.163.com/')
31
+ true
32
+ end
33
+ true
34
+ end
35
+
36
+ get163.run
37
+ get163.report
38
+ #get163.save_report(:name=>"Get163HomeAndSports")
data/test/get19Lou.rb ADDED
@@ -0,0 +1,39 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'roadrunner'
4
+ require 'httparty'
5
+
6
+ get19Lou=RoadRunner.new do |session|
7
+ session=
8
+ {:adapter=>"mysql",
9
+ :encoding=>"utf8",
10
+ :database=>"dpmp",
11
+ :username=>"root",
12
+ :password=>"alisoft",
13
+ :host=>"10.2.226.133"}
14
+ end
15
+ #get19Lou.mode = 'thread'
16
+
17
+ get19Lou.init do
18
+ # users决定同时有多少并发用户一起执行action
19
+ # iterations决定每个用户执行多少次
20
+ get19Lou.users,get19Lou.iterations=10,10
21
+ end
22
+
23
+ get19Lou.action do
24
+ get19Lou.homepage do
25
+ resp = HTTParty.get('http://19lou.com')
26
+ # => check request header if contain the certain key words
27
+ # (resp.headers.inspect.include? 'Apache')
28
+ end
29
+ get19Lou.auto do
30
+ resp = HTTParty.get('http://auto.19lou.com/')
31
+ # => check request body
32
+ # resp.body.include? '19lou'
33
+ end
34
+ true
35
+ end
36
+
37
+ get19Lou.run
38
+ get19Lou.report
39
+ get19Lou.save_report(:name=>"get19LouHomeAndSports2")
data/test/getHawaii.rb ADDED
@@ -0,0 +1,95 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'roadrunner'
4
+ # => I'll use the Httparty lib to make http request
5
+ # => as the LR method LoadRunner#web_url() and
6
+ # => LoadRunner#web_submit_data() and LoadRunner#web_custom_request()
7
+ require 'httparty'
8
+
9
+ # => if one of RoadRunner.new's argument is block
10
+ # => then the database connection will be established
11
+ # => and the below method could be used:
12
+ # => RoadRunner#save_report()
13
+
14
+ # => IMPORTANT:
15
+ # => if a block is given to RoadRunner#new
16
+ # => make sure there is exist the below three tables in the target DATABASE:
17
+ # => scenarios transactions records
18
+ # => and the three tables is defined in db.rb,
19
+ # => otherwise if the three tables does not exist in the target DATABASE,
20
+ # => Roadrunner will auto create the three tables.
21
+
22
+ getHawaii=RoadRunner.new
23
+ #do |session|
24
+ # {:adapter=>"mysql",
25
+ # :encoding=>"utf8",
26
+ # :database=>"dpmp",
27
+ # :username=>"root",
28
+ # :password=>"alisoft",
29
+ # :host=>"10.2.226.133"}
30
+ #end
31
+
32
+ # => RoadRunner#mode could be set as such value:
33
+ # => 'thread'
34
+ # => 'sequence' or other string is same.
35
+ # => when thread mode is set,
36
+ # => the RoadRunner#action will run as thread,
37
+ # => and main thread will fork RoadRunner#users threads to run every action block
38
+ #getHawaii.mode = 'thread'
39
+
40
+ getHawaii.init do
41
+ # users决定同时有多少并发用户一起执行action
42
+ # iterations决定每个用户执行多少次
43
+ getHawaii.users,getHawaii.iterations=2,1
44
+ end
45
+
46
+ # => RoadRunner#any_other_method()
47
+ # => if any_other_method() is not exsit in RoadRunner#methods
48
+ # => the RoadRunner#any_other_method(){} will be dealed as RoadRunner#transaction('any_other_method'){}
49
+ # => and the important is:
50
+ # => the block of RoadRunner#transaction('any_other_method'){}
51
+ # => the value of the last expression in the block
52
+ # => will determin this transaction's current action is pass or not!!!
53
+ # =>
54
+ # => status's value is:
55
+ # => 0=>success
56
+ # => -1=>faile
57
+ # => ruby code as below:
58
+ # => case status
59
+ # => when false,'false','-1',-1 then status = -1
60
+ # => else status = 0
61
+ # => end
62
+ getHawaii.action do
63
+ getHawaii.homepage do
64
+ resp = HTTParty.get('http://www.hawaii.com/')
65
+ # => check request header if contain the certain key words
66
+ # => same as the LR method LoadRunner#web_reg_find("Search=Headers")
67
+ resp.headers.inspect.include? 'Apache'
68
+ end
69
+ # => Log4r is integrade in the RoadRunner and you could use it as below.
70
+ # => RoadRunner#log.debug
71
+ # => RoadRunner#log.info
72
+ # => RoadRunner#log.warn
73
+ # => RoadRunner#log.error
74
+ # => RoadRunner#log.fatal
75
+ getHawaii.homepage2 do
76
+ resp = HTTParty.get('http://www.hawaii.com/')
77
+ # => check request body
78
+ # => same as the LR method LoadRunner#web_reg_find()
79
+ resp.body.include? 'CalendarPopup'
80
+ end
81
+ true
82
+ end
83
+
84
+ # => RoadRunner#run
85
+ # => this method will execute the RoadRunner script
86
+ # => the performance will start.
87
+ getHawaii.run
88
+ # => RoadRunner#report
89
+ # => this method will output the report to the STDOUT
90
+ getHawaii.report
91
+ # => RoadRunner#save_report
92
+ # => this method will save the report to database if the database connection is established
93
+ # => :script is one of the arguments
94
+ # => if the :script is set and the value of :script is a path,the file's content of the path will be saved in database.
95
+ getHawaii.save_report(:name=>"getHawaiiHomepage",:script=>__FILE__)
@@ -0,0 +1,31 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'rubygems'
4
+ require 'roadrunner'
5
+ require 'rfuzz/client'
6
+ require 'httparty'
7
+
8
+ rclient=RoadRunner.new
9
+ #client.mode = 'thread'
10
+
11
+ rclient.init do
12
+ # users决定同时有多少并发用户一起执行action
13
+ # iterations决定每个用户执行多少次
14
+ @rc = RFuzz::HttpClient.new('10.2.226.132', 6080)
15
+ rclient.users,rclient.iterations=10,100
16
+ end
17
+
18
+ rclient.action do
19
+ @rc.get('/').http_body
20
+ true
21
+ end
22
+
23
+ rclient.run
24
+ rclient.report
25
+ client.save_report(:name=>"clientHomeAndSports")
26
+
27
+ hclient=RoadRunner.new
28
+ hclient.users,hclient.iterations=10,100
29
+ hclient.action{resp = HTTParty.get('http://10.2.226.132:6080')}
30
+ hclient.run
31
+ hclient.report
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
4
+
5
+ require 'roadrunner'
6
+
7
+ require 'rubygems'
8
+ require 'activerecord'
9
+ require 'benchmark'
10
+ require 'logger'
11
+ require 'pp'
12
+
13
+ mysql=RoadRunner.new
14
+
15
+ =begin
16
+ RoadRunner::mode =>
17
+ /thread/,/t/
18
+ /process/,/p/
19
+ else.
20
+ Defined in run.rb
21
+ 当mode为进程的时候,RoadRunner将产生最真实的压力
22
+ =end
23
+
24
+ mysql.mode='p'
25
+
26
+ begin
27
+ ActiveRecord::Base.establish_connection(
28
+ :adapter =>"mysql",
29
+ :username => "houyi",
30
+ :password =>"111111",
31
+ :database => "SNS",
32
+ :host =>"10.250.6.30"
33
+ )
34
+ $log.info "mysql Connect Success."
35
+ rescue => e
36
+ $log.error "mysql Connect Failed!"
37
+ $log.error e.to_s
38
+ end
39
+
40
+ class RRData < ActiveRecord::Base
41
+ set_table_name "qa_posts"
42
+ # set_primary_key "ID"
43
+ end
44
+
45
+ mysql.init do
46
+ # users决定同时有多少并发用户一起执行action
47
+ # iterations决定每个用户执行多少次
48
+ mysql.users,mysql.iterations=100,10000
49
+ end
50
+
51
+ SQL=""
52
+
53
+ mysql.action do
54
+ # ts = Benchmark.measure{
55
+ RRData.find_by_sql(SQL)
56
+ # }
57
+ # mysql.log.error "RRData.find_by_sql #{SQL} ts => #{ts}"
58
+ end
59
+
60
+ mysql.ended do
61
+ end
62
+
63
+ mysql.run
64
+ mysql.report
65
+
66
+ p "Tps could get : RoadRunner::tps => #{mysql.tps}"
data/test/pi.rb ADDED
@@ -0,0 +1,37 @@
1
+ # 莱布尼兹公式计算圆周率
2
+ #rrpi.global[:deep]代表计算的深度
3
+ #深度越深,计算越精确,当然也越耗时
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
6
+
7
+ require 'roadrunner'
8
+
9
+ rrpi=RoadRunner.new
10
+
11
+ rrpi.init do
12
+ rrpi.global[:pi],rrpi.global[:deep]=0,100
13
+
14
+ # users决定同时有多少并发用户一起执行action
15
+ # iterations决定每个用户执行多少次
16
+ rrpi.users,rrpi.iterations=10,1000
17
+ end
18
+
19
+ rrpi.action do
20
+
21
+ # 新增加了iterationId和userId两个接口方法,
22
+ # 可以通过iterationId获得当前action执行到第一次
23
+ # 可以通过userId获得当前action执行用户的id
24
+ # puts rrpi.iterationId
25
+ # puts rrpi.userId
26
+ 1.upto(rrpi.global[:deep]){|x|rrpi.global[:pi]+=((-1)**(x+1)*1.0/(x*2-1))}
27
+ end
28
+
29
+ rrpi.ended do
30
+ rrpi.global[:pi]*=4
31
+ #rrpi.global={}
32
+ end
33
+
34
+ rrpi.run
35
+ rrpi.report
36
+
37
+ p "Tps could get : RoadRunner::tps => #{rrpi.tps}"
data/test/pi_db.rb ADDED
@@ -0,0 +1,41 @@
1
+ # 莱布尼兹公式计算圆周率
2
+ #rrpi.global[:deep]代表计算的深度
3
+ #深度越深,计算越精确,当然也越耗时
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
6
+
7
+ require 'roadrunner'
8
+
9
+ #rrpi=RoadRunner.new(:out=>"#{File.join(File.dirname(__FILE__),'roadrunner_stdout.log')}")
10
+
11
+ rrpi=RoadRunner.new(:out=>"#{File.join(File.dirname(__FILE__),'roadrunner_stdout.log')}") do |session|
12
+ session[:adapter] = 'sqlite3'
13
+ session[:database] = File.join(File.dirname(__FILE__),'db','development.sqlite3')
14
+ end
15
+
16
+ rrpi.init do
17
+ rrpi.global[:pi],rrpi.global[:deep]=0,1000
18
+
19
+ # users决定同时有多少并发用户一起执行action
20
+ # iterations决定每个用户执行多少次
21
+ rrpi.users,rrpi.iterations=10,10
22
+ end
23
+
24
+ rrpi.action do
25
+
26
+ # 新增加了iterationId和userId两个接口方法,
27
+ # 可以通过iterationId获得当前action执行到第一次
28
+ # 可以通过userId获得当前action执行用户的id
29
+ # puts rrpi.iterationId
30
+ # puts rrpi.userId
31
+ 1.upto(rrpi.global[:deep]){|x|rrpi.global[:pi]+=((-1)**(x+1)*1.0/(x*2-1))}
32
+ end
33
+
34
+ rrpi.ended do
35
+ rrpi.global[:pi]*=4
36
+ #rrpi.global={}
37
+ end
38
+
39
+ rrpi.run
40
+ rrpi.report
41
+ rrpi.save_report("pi_conputiong_perf_01")
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # 莱布尼兹公式计算圆周率
4
+ #rrpi.global[:deep]代表计算的深度
5
+ #深度越深,计算越精确,当然也越耗时
6
+
7
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
8
+
9
+ require 'roadrunner'
10
+
11
+ rrpi=RoadRunner.new
12
+
13
+ rrpi.init do
14
+ rrpi.global[:pi],rrpi.global[:deep]=0,100
15
+
16
+ # users决定同时有多少并发用户一起执行action
17
+ # iterations决定每个用户执行多少次
18
+ rrpi.users,rrpi.iterations=10,1000
19
+ end
20
+
21
+
22
+ rrpi.action do
23
+
24
+ # 新增加了iterationId和userId两个接口方法,
25
+ # 可以通过iterationId获得当前action执行到第一次
26
+ # 可以通过userId获得当前action执行用户的id
27
+ # puts rrpi.iterationId
28
+ # puts rrpi.userId
29
+ 1.upto(rrpi.global[:deep]){|x|rrpi.global[:pi]+=((-1)**(x+1)*1.0/(x*2-1))}
30
+ end
31
+
32
+ rrpi.ended do
33
+ rrpi.global[:pi]*=4
34
+ #rrpi.global={}
35
+ end
36
+
37
+ 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']
38
+
39
+ RoadRunnerModule::RRMonitor.monit(File.join(File.dirname(__FILE__),'..','conf','servers.yaml'),rrpi.log,cmd,"Pi-Monitor-Performance"){
40
+ rrpi.run
41
+ }
42
+
43
+ rrpi.report
44
+
45
+ p "Tps could get : RoadRunner::tps => #{rrpi.tps}"