RoadRunner 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ # Rrhelper will include many helpful methods for RoadRunner
2
+
3
+ module RoadRunnerModule
4
+
5
+ def iterationId
6
+ if(@mode=='thread')then
7
+ @thread_pool[Thread.current][:iterationId]
8
+ else
9
+ @iterationId
10
+ end
11
+ end
12
+
13
+ def userId
14
+ if(@mode=='thread')then
15
+ @thread_pool[Thread.current][:userId]
16
+ else
17
+ @userId
18
+ end
19
+ end
20
+
21
+ module Rrhelper
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,55 @@
1
+ #After roadRunner.run() executed,
2
+ #execute roadRunner.report() show the Performance report
3
+
4
+ module RoadRunnerModule
5
+ def run
6
+ @strat_time = Time.now
7
+ @initBlk.call
8
+ @thread_pool = {}
9
+ @counter = 0
10
+
11
+ iterationBlk = if(@mode!='thread') then
12
+ proc {
13
+ @iterations.times do |iterationId|
14
+ @iterationId=iterationId
15
+ @users.times do |userId|
16
+ @userId=userId
17
+ rcost = self.transaction('Action',&@actBlk)
18
+ # => the below sentence cost a lot of system resource
19
+ # => if you run for production result,keep it annotated!!!
20
+ # self.log.debug "IterationID is #{self.iterationId};UserID is #{self.userId};This Action Cost #{rcost} seconds"
21
+ @longest = (@longest<rcost)?rcost:@longest
22
+ end
23
+ end}
24
+ elsif(@mode=='thread')
25
+ proc {
26
+ @users.times do |userId|
27
+ @thread_pool[Thread.start(){
28
+ @iterations.times do |iterationId|
29
+ rcost = self.transaction('Action',&@actBlk)
30
+ self.log.debug "IterationID is #{self.iterationId};UserID is #{self.userId};This Action Cost #{rcost} seconds"
31
+ @longest = (@longest<rcost)?rcost:@longest
32
+ @thread_pool[Thread.current][:iterationId] = iterationId
33
+ end
34
+ @counter += 1
35
+ }]={:userId=>userId}
36
+ end
37
+ # @thread_pool.keys.each{|t|t.join}
38
+ while @counter != @users do
39
+ Thread.pass
40
+ end
41
+ }
42
+ end
43
+
44
+ p ' '+"RoadRunner".center(50, '*')
45
+ p ' *'+"---Run , on your way.".rjust(72, ' ')+'*'
46
+ p ' *'*12
47
+ p
48
+ p " Running......"
49
+ @rep = Benchmark::measure(&iterationBlk)
50
+ p " Ending......"
51
+ @endBlk.call
52
+
53
+ @tps = @iterations*@users/@rep.real
54
+ end
55
+ end
@@ -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__)
@@ -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__)
@@ -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
@@ -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")
@@ -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")
@@ -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__)