railsbench 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/BUGS CHANGED
@@ -1,3 +1,2 @@
1
- - POST isn't supported (yet)
2
1
  - documentation could be improved
3
2
  - hoe's rake install doesn't work (which is actually hoe's problem)
data/CHANGELOG CHANGED
@@ -1,3 +1,141 @@
1
+ 2007-04-01 07:29 stkaes
2
+
3
+ * latest_changes.txt, script/perf_html: -colorize option for
4
+ perf_html
5
+
6
+ 2007-04-01 07:29 stkaes
7
+
8
+ * script/perf_plot: added -theme option
9
+
10
+ 2007-03-31 07:49 stkaes
11
+
12
+ * script/perf_diff: options -narrow and -skip_urls are no longer
13
+ necessary
14
+
15
+ 2007-03-31 07:48 stkaes
16
+
17
+ * script/perf_html: allow _ in benchmark names
18
+
19
+ 2007-03-31 07:26 stkaes
20
+
21
+ * CHANGELOG: updated CHANGELOG
22
+
23
+ 2007-03-31 07:26 stkaes
24
+
25
+ * Manifest.txt: include new scripts
26
+
27
+ 2007-03-31 07:25 stkaes
28
+
29
+ * bin/railsbench: make new scripts callabe from railsbench
30
+
31
+ 2007-03-31 07:25 stkaes
32
+
33
+ * latest_changes.txt: still more changes
34
+
35
+ 2007-03-31 07:24 stkaes
36
+
37
+ * README: adapted README to latest changes
38
+
39
+ 2007-03-31 06:56 stkaes
40
+
41
+ * install.rb: copy all entries from the development database config
42
+
43
+ 2007-03-31 06:43 stkaes
44
+
45
+ * latest_changes.txt: lates changes description
46
+
47
+ 2007-03-30 10:49 stkaes
48
+
49
+ * lib/railsbench/railsbenchmark.rb: merge benchmark session data
50
+ with session data from session store
51
+
52
+ 2007-03-30 09:43 stkaes
53
+
54
+ * lib/railsbench/benchmark_specs.rb: load benchmark file using ERB
55
+
56
+ 2007-03-30 09:13 stkaes
57
+
58
+ * lib/railsbench/benchmark_specs.rb,
59
+ lib/railsbench/railsbenchmark.rb: make it possible to specify
60
+ session data in benchmarks.yml
61
+
62
+ 2007-03-30 05:45 stkaes
63
+
64
+ * script/perf_table: script for generating a tabular overview
65
+
66
+ 2007-03-25 14:34 stkaes
67
+
68
+ * script/perf_plot: allow specification of colors
69
+
70
+ 2007-03-25 11:37 stkaes
71
+
72
+ * script/perf_plot: allow specification of output file
73
+
74
+ 2007-03-25 07:15 stkaes
75
+
76
+ * script/perf_plot: automatically remove date and benchmark names
77
+ from config names
78
+
79
+ 2007-03-20 06:23 stkaes
80
+
81
+ * lib/railsbench/benchmark_specs.rb: don't fuck with array
82
+ extensions during running rails
83
+
84
+ 2007-03-18 19:02 stkaes
85
+
86
+ * Manifest.txt, lib/railsbench/benchmark_specs.rb,
87
+ lib/railsbench/railsbenchmark.rb, script/convert_raw_data_files,
88
+ script/perf_bench, script/perf_plot, script/run_urls: refactored
89
+ benchmark loading; added script for converting benchmark data
90
+ files to new format
91
+
92
+ 2007-03-16 10:22 stkaes
93
+
94
+ * lib/railsbench/railsbenchmark.rb: added post support; use
95
+ benchmark names instead of urls for display
96
+
97
+ 2007-03-09 07:57 stkaes
98
+
99
+ * README: it's query_string, not query_params
100
+
101
+ 2007-03-09 07:54 stkaes
102
+
103
+ * PROBLEMS: doc change
104
+
105
+ 2007-03-09 06:57 stkaes
106
+
107
+ * latest_changes.txt, script/perf_plot, script/perf_plot_gc: use
108
+ -geometry=1600x1200 to specify dimensions foer generated .png
109
+ files
110
+ use -font_size=12 to set font size for labels, markers etc
111
+
112
+ 2007-02-13 08:30 stkaes
113
+
114
+ * script/perf_comp: use time instad of number of collections for gc
115
+ change factor calculation
116
+
117
+ 2007-01-26 17:46 stkaes
118
+
119
+ * PROBLEMS: dos2unix
120
+
121
+ 2007-01-26 17:24 stkaes
122
+
123
+ * Manifest.txt, PROBLEMS: aded file PROBLEMS for things which are
124
+ not really railsbench bugs
125
+
126
+ 2007-01-26 17:23 stkaes
127
+
128
+ * script/generate_benchmarks: added better version checking
129
+
130
+ 2007-01-26 15:26 stkaes
131
+
132
+ * lib/railsbench/version.rb: prepare for 0.9.2 release
133
+
134
+ 2007-01-26 15:25 stkaes
135
+
136
+ * config/benchmarks.yml: changed default benchmarks.yml to contain
137
+ only default benchmark
138
+
1
139
  2007-01-14 09:07 stkaes
2
140
 
3
141
  * CHANGELOG: updated CHANGELOG
@@ -5,6 +5,7 @@ install.rb
5
5
  postinstall.rb
6
6
  LICENSE
7
7
  Manifest.txt
8
+ PROBLEMS
8
9
  README
9
10
  Rakefile
10
11
  setup.rb
@@ -17,8 +18,10 @@ lib/railsbench/perf_info.rb
17
18
  lib/railsbench/perf_utils.rb
18
19
  lib/railsbench/write_headers_only.rb
19
20
  lib/railsbench/railsbenchmark.rb
21
+ lib/railsbench/benchmark_specs.rb
20
22
  lib/benchmark.rb
21
23
  script/generate_benchmarks
24
+ script/convert_raw_data_files
22
25
  script/perf_bench
23
26
  script/perf_comp
24
27
  script/perf_comp_gc
@@ -30,6 +33,7 @@ script/perf_plot_gc
30
33
  script/perf_prof
31
34
  script/perf_run
32
35
  script/perf_run_gc
36
+ script/perf_table
33
37
  script/perf_tex
34
38
  script/perf_times
35
39
  script/perf_times_gc
@@ -0,0 +1,56 @@
1
+ You might experience the problem described below, if your
2
+ benchmarking.rb environment file contains the line
3
+
4
+ config.action_controller.view_controller_internals = false
5
+
6
+
7
+ This is the preferred setting for a production mode config file, but
8
+ can cause problems when a view template tries to access a method only
9
+ available when view_controller_internals is true.
10
+
11
+ If you experierence backtraces like the one below, try the setting
12
+
13
+ config.action_controller.view_controller_internals = true
14
+
15
+ Typical backtrace:
16
+
17
+ ActionView::TemplateError (undefined method `each' for nil:NilClass) on line #1 of app/views/test/param_access_t
18
+ est.rhtml:
19
+ 1: <% for k,v in params %>
20
+ 2: <%= h k %> = <%= h v %>
21
+ 3: <% end %>
22
+ 4:
23
+
24
+ #{RAILS_ROOT}/app/views/test/param_access_test.rhtml:1:in `_run_rhtml_47app47views47test47param_access_test46rhtml'
25
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_view/base.rb:326:in `compile_and_render_template'
26
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_view/base.rb:301:in `render_template'
27
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_view/base.rb:260:in `render_file'
28
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/base.rb:806:in `render_file'
29
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/base.rb:711:in `render_with_no_layout'
30
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/layout.rb:256:in `render_without_benchmark'
31
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
32
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/lib/benchmark.rb:300:in `measure'
33
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
34
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/base.rb:1096:in `perform_action_without_filters'
35
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:632:in `call_filter'
36
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:638:in `call_filter'
37
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:438:in `call'
38
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:637:in `call_filter'
39
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:634:in `call_filter'
40
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'
41
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
42
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/lib/benchmark.rb:300:in `measure'
43
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
44
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/rescue.rb:83:in `perform_action'
45
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/base.rb:430:in `process_without_filters'
46
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/filters.rb:624:in `process_without_session_management_support'
47
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/session_management.rb:114:in `process'
48
+ c:/home/skaes/svn/trunk12pre/actionpack/lib/action_controller/base.rb:330:in `process'
49
+ c:/home/skaes/svn/trunk12pre/railties/lib/dispatcher.rb:41:in `dispatch'
50
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/lib/railsbench/railsbenchmark.rb:262:in `run_urls_without_benchmark_and_without_gc_control'
51
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/lib/railsbench/railsbenchmark.rb:261:in `run_urls_without_benchmark_and_without_gc_control'
52
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/lib/railsbench/railsbenchmark.rb:259:in `run_urls_without_benchmark_and_without_gc_control'
53
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/lib/railsbench/railsbenchmark.rb:194:in `run_urls_without_benchmark'
54
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/script/run_urls:35
55
+ c:/ruby184/lib/ruby/gems/1.8/gems/railsbench-0.9.2/bin/railsbench:71
56
+ /ruby184/bin/railsbench:18
data/README CHANGED
@@ -104,10 +104,15 @@ FILES
104
104
  file name is computed from date and benchmark name as described above
105
105
  but has a .html extension instead of .txt
106
106
 
107
- perf_plot n [ options ] file1 file2 ...
107
+ perf_plot [ options ] file1 file2 ...
108
108
  - plot performance data from raw performance files using gruff
109
109
  see source for options
110
110
 
111
+ perf_table [ options ] file1 file2 ...
112
+ - produces a tabular overview of perf data from given raw data files
113
+ see source for options
114
+
115
+
111
116
  ENVIRONMENT
112
117
 
113
118
  RAILS_ROOT
@@ -131,7 +136,9 @@ INVOCATION
131
136
  Ruby's bin directory. Individual commands can be called by prefixing
132
137
  with railsbench. If you tire of typing railsbench all the time, you
133
138
  can either define an alias (alias rb="railsbench"), or you can
134
- include railsbench's script directory into your seach path.
139
+ include railsbench's script directory into your seach path. In this
140
+ case you need to run 'sudo railsbench postinstall' to make the
141
+ scripts executable.
135
142
 
136
143
 
137
144
  USAGE
@@ -217,12 +224,12 @@ USAGE
217
224
  freed : 207085.69 0.2 206803.00 208213.00
218
225
  freelist : 0.00 0.0 0.00 0.00
219
226
 
220
- Note that these numbers, especially requests per collection, are only
221
- an approximation. This is due to the fact that run_urls will add one
222
- final garbage collection call at the end of the run. Of course, higher
223
- number of iterations will produce more accurate data. Also, if the
224
- benchmark lists several uris, garbage per request will not give you
225
- meaningful information.
227
+ Note that these numbers, especially requests per collection, are
228
+ only an approximation. This is due to the fact that perf_run_gc will
229
+ add one final garbage collection call at the end of the run. Of
230
+ course, higher number of iterations will produce more accurate
231
+ data. Also, if the benchmark lists several uris, garbage per request
232
+ will not give you meaningful information.
226
233
 
227
234
 
228
235
  CONFIGURATION
@@ -230,39 +237,64 @@ CONFIGURATION
230
237
  Benchmarks are configured through file benchmarks.yml. Example:
231
238
 
232
239
  default:
233
- index, other
240
+ index, query, alpha
234
241
 
235
242
  index:
236
243
  uri: /test/index
237
244
  new_session: true
238
245
 
239
- other:
240
- -
246
+ query:
241
247
  uri: /test/list
242
- -
248
+ method: post
249
+ post_data: search_string=tomatoes
250
+
251
+ alpha:
243
252
  uri: /test/alphabetic
244
- query_params: page=7
253
+ query_string: page=7&letter=A
245
254
 
246
- defines 3 benchmarks:
255
+ defines 4 benchmarks:
247
256
 
248
- "other" consists of 2 urls (/test/list and /test/alphabetic)
249
- "index" will run (/test/index)
250
- "default" will run all urls in "index" and "other"
257
+ "index" will run (/test/index) using method GET
258
+ "query" will run (/test/list) using method POST
259
+ "alpha" will run (/test/alphabetic) using method GET
260
+ "default" will run benchmarks "index", "query" and "alpha"
251
261
 
252
262
  uri: is mandatory, query_params: and new_session: are optional.
253
263
 
254
264
  Instead of
255
265
 
256
266
  uri: /test/alphabetic
257
- query_params: page=7
267
+ query_string: page=7
258
268
 
259
269
  one could have written
260
270
 
261
- uri: /test/alphabetic?page=7
262
-
263
- new_session: specifies whether a session cookie is sent with the
264
- request (default). To make this work correctly, you need to set
265
- session_data on the benchmarker instance. See benchmarks.rb for details.
271
+ uri: /test/alphabetic?page=7&letter=A
272
+
273
+ A single test session is created before running the benchmarks and
274
+ stored in the sesion container of your choice. The corresponding
275
+ _session_id value is sent with each request. If you specifiy
276
+ new_session: true, railsbench will not send the session_id value, so
277
+ Rails will create a new session per request for the given benchmark.
278
+
279
+ Session data can either be set on the benchmarker instance, or
280
+ specified in the benchmark config file like so:
281
+
282
+ list_user_5:
283
+ uri: /test/list
284
+ method: post
285
+ post_data: search_string=tomatoes
286
+ session_data:
287
+ user_id: 5
288
+
289
+ benchmarks.yml is loaded using ERB. This makes it possible to avoid
290
+ using primary keys in the config file:
291
+
292
+ list_user_stefan:
293
+ uri: /test/list
294
+ method: post
295
+ post_data: search_string=tomatoes
296
+ session_data:
297
+ user_id: <%= User.find_by_login('stefan').id %>
266
298
 
267
299
  An inital benchmark configuration file can be generated using command
268
300
  generate_benchmarks.
@@ -3,6 +3,7 @@
3
3
  RAILSBENCH_CMDS = %w(
4
4
  base
5
5
  generate_benchmarks
6
+ convert_raw_data_files
6
7
  help
7
8
  install
8
9
  path
@@ -16,6 +17,7 @@ perf_plot_gc
16
17
  perf_prof
17
18
  perf_run
18
19
  perf_run_gc
20
+ perf_table
19
21
  perf_tex
20
22
  perf_times
21
23
  perf_times_gc
@@ -1,49 +1,2 @@
1
1
  default:
2
2
  uri: /
3
-
4
- all:
5
- new_sessions, same_session
6
-
7
- new_sessions:
8
- empty, welcome
9
-
10
- same_session:
11
- rezept, myknzlpzl, show, cat, cat5, letter
12
-
13
- empty:
14
- uri: /empty/index
15
- new_session: true
16
-
17
- welcome:
18
- uri: /welcome/index
19
- new_session: true
20
-
21
- rezept:
22
- uri: /rezept/index
23
-
24
- myknzlpzl:
25
- uri: /rezept/myknzlpzl
26
-
27
- show:
28
- uri: /rezept/show/713
29
-
30
- cat:
31
- uri: /rezept/cat/Hauptspeise
32
-
33
- cat5:
34
- uri: /rezept/cat/Hauptspeise?page=5
35
-
36
- letter:
37
- uri: /rezept/letter/G
38
-
39
- links:
40
- -
41
- uri: /test/url_test
42
- -
43
- uri: /test/link_test
44
-
45
- alpha:
46
- uri: /rezept/alphabetic
47
-
48
- test_index:
49
- uri: /test/index
data/install.rb CHANGED
@@ -33,7 +33,7 @@ install("#{RAILSBENCH_BASE}/config/benchmarks.rb", RAILS_CONFIG, :mode => 0644)
33
33
  install("#{RAILSBENCH_BASE}/config/benchmarks.yml", RAILS_CONFIG, :mode => 0644) unless
34
34
  File.exists?(RAILS_CONFIG + "benchmarks.yml")
35
35
 
36
- install("#{RAILSBENCH_BASE}/config/benchmarking.rb", RAILS_ENVS, :mode => 0644) unless
36
+ cp(RAILS_ENVS + "production.rb", RAILS_ENVS + "benchmarking.rb") unless
37
37
  File.exists?(RAILS_ENVS + "benchmarking.rb")
38
38
 
39
39
  database = YAML::load(File.open(RAILS_CONFIG + "database.yml"))
@@ -41,8 +41,8 @@ unless database["benchmarking"]
41
41
  puts "creating database configuration: benchmarking"
42
42
  File.open(RAILS_CONFIG + "database.yml", "ab") do |file|
43
43
  file.puts "\nbenchmarking:\n"
44
- %w(adapter database host username password).each do |k|
45
- file.puts " #{k}: #{database['development'][k]}"
44
+ database['development'].each do |k, v|
45
+ file.puts " #{k}: #{v}"
46
46
  end
47
47
  end
48
48
  end
@@ -53,7 +53,7 @@ __END__
53
53
  ### mode:ruby ***
54
54
  ### End: ***
55
55
 
56
- # Copyright (C) 2005, 2006 Stefan Kaes
56
+ # Copyright (C) 2005, 2006, 2007 Stefan Kaes
57
57
  #
58
58
  # This program is free software; you can redistribute it and/or modify
59
59
  # it under the terms of the GNU General Public License as published by
@@ -0,0 +1,63 @@
1
+ require 'delegate'
2
+ require 'yaml'
3
+ require 'erb'
4
+
5
+ class BenchmarkSpec < DelegateClass(Hash)
6
+ attr_accessor :name
7
+
8
+ READERS = %w(uri method post_data query_string new_session action controller session_data)
9
+ READERS.each do |method|
10
+ define_method(method) { self[method] }
11
+ end
12
+
13
+ def initialize(name, hash)
14
+ super(hash)
15
+ @name = name
16
+ end
17
+
18
+ def inspect
19
+ "BenchmarkSpec(#{name},#{super})"
20
+ end
21
+
22
+ class << self
23
+ def load(name, file_name = nil)
24
+ unless file_name
25
+ file_name = ENV['RAILS_ROOT'] + "/config/benchmarks.yml"
26
+ end
27
+ @@specs = YAML::load(ERB.new(IO.read(file_name)).result)
28
+ raise "There is no benchmark named '#{name}'" unless @@specs[name]
29
+ parse(@@specs, name)
30
+ end
31
+
32
+ def parse(specs, name)
33
+ spec = specs[name]
34
+ if spec.is_a?(String)
35
+ spec.split(/, */).collect!{ |n| parse(specs, n) }.flatten
36
+ elsif spec.is_a?(Hash)
37
+ [ BenchmarkSpec.new(name,spec) ]
38
+ elsif spec.is_a?(Array)
39
+ spec.collect{|n| parse(specs, n)}.flatten
40
+ else
41
+ raise "oops: unknown entry type in benchmark specification"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ __END__
48
+
49
+ # Copyright (C) 2007 Stefan Kaes
50
+ #
51
+ # This program is free software; you can redistribute it and/or modify
52
+ # it under the terms of the GNU General Public License as published by
53
+ # the Free Software Foundation; either version 2 of the License, or
54
+ # (at your option) any later version.
55
+ #
56
+ # This program is distributed in the hope that it will be useful,
57
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
58
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59
+ # GNU General Public License for more details.
60
+ #
61
+ # You should have received a copy of the GNU General Public License
62
+ # along with this program; if not, write to the Free Software
63
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -1,6 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/benchmark_specs')
2
+
1
3
  class RailsBenchmark
2
4
 
3
- attr_accessor :gc_frequency, :iterations, :url_spec
5
+ attr_accessor :gc_frequency, :iterations
4
6
  attr_accessor :http_host, :remote_addr, :server_port
5
7
  attr_accessor :relative_url_root
6
8
  attr_accessor :perform_caching, :cache_template_loading
@@ -34,8 +36,6 @@ class RailsBenchmark
34
36
 
35
37
  @session_data = options[:session_data] || {}
36
38
 
37
- @url_spec = options[:url_spec]
38
-
39
39
  ENV['RAILS_ENV'] = 'benchmarking'
40
40
 
41
41
  require ENV['RAILS_ROOT'] + "/config/environment"
@@ -56,6 +56,13 @@ class RailsBenchmark
56
56
  end
57
57
  end_eval
58
58
 
59
+ # make sure Rails doesn't try to read post data from stdin
60
+ CGI::QueryExtension.module_eval <<-end_eval
61
+ def read_body(content_length)
62
+ ENV['RAW_POST_DATA']
63
+ end
64
+ end_eval
65
+
59
66
  if ARGV.include?('-path')
60
67
  $:.each{|f| STDERR.puts f}
61
68
  exit
@@ -108,6 +115,14 @@ class RailsBenchmark
108
115
  @session_id = @session.session_id
109
116
  end
110
117
 
118
+ def update_test_session_data(session_data)
119
+ dbman = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager]
120
+ old_session_data = dbman.new(@session).restore
121
+ new_session_data = old_session_data.merge(session_data || {})
122
+ new_session_data.each{ |k,v| @session[k] = v }
123
+ @session.update
124
+ end
125
+
111
126
  def delete_test_session
112
127
  @session.delete
113
128
  @session = nil
@@ -118,30 +133,42 @@ class RailsBenchmark
118
133
  end
119
134
 
120
135
  def setup_test_urls(name)
121
- raise "There is no benchmark named '#{name}'" unless @url_spec[name]
122
- @urls = self.class.parse_url_spec(@url_spec, name)
136
+ @urls = BenchmarkSpec.load(name)
123
137
  end
124
138
 
125
139
  def setup_initial_env
126
140
  ENV['REMOTE_ADDR'] = remote_addr
127
141
  ENV['HTTP_HOST'] = http_host
128
142
  ENV['SERVER_PORT'] = server_port.to_s
129
- ENV['REQUEST_METHOD'] = 'GET'
130
143
  end
131
144
 
132
- def setup_request_env(uri, query_string, new_session)
133
- ENV['REQUEST_URI'] = @relative_url_root + uri
134
- ENV['QUERY_STRING'] = query_string || ''
135
- ENV['CONTENT_LENGTH'] = (query_string || '').length.to_s
136
- ENV['HTTP_COOKIE'] = new_session ? '' : "_session_id=#{@session_id}"
145
+ def setup_request_env(entry)
146
+ ENV['REQUEST_URI'] = @relative_url_root + entry.uri
147
+ ENV['RAW_POST_DATA'] = nil
148
+ ENV['QUERY_STRING'] = nil
149
+ case ENV['REQUEST_METHOD'] = (entry.method || 'get').upcase
150
+ when 'GET'
151
+ query_data = escape_data(entry.query_string || '')
152
+ ENV['QUERY_STRING'] = query_data
153
+ when 'POST'
154
+ query_data = escape_data(entry.post_data || '')
155
+ ENV['RAW_POST_DATA'] = query_data
156
+ end
157
+ ENV['CONTENT_LENGTH'] = query_data.length.to_s
158
+ ENV['HTTP_COOKIE'] = entry.new_session ? '' : "_session_id=#{@session_id}"
159
+ update_test_session_data(entry.session_data) unless entry.new_session
160
+ end
161
+
162
+ def escape_data(str)
163
+ str.split('&').map{|e| e.split('=').map{|e| CGI::escape e}.join('=')}.join('&')
137
164
  end
138
165
 
139
166
  def warmup
140
167
  error_exit "No urls given for performance test" unless @urls && @urls.size>0
141
168
  setup_initial_env
142
169
  @urls.each do |entry|
143
- error_exit "No uri given for benchmark entry: #{entry.inspect}" unless entry['uri']
144
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
170
+ error_exit "No uri given for benchmark entry: #{entry.inspect}" unless entry.uri
171
+ setup_request_env(entry)
145
172
  Dispatcher.dispatch
146
173
  end
147
174
  end
@@ -242,7 +269,7 @@ class RailsBenchmark
242
269
 
243
270
  def run_urls_without_benchmark_but_with_gc_control(urls, n, gc_frequency)
244
271
  urls.each do |entry|
245
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
272
+ setup_request_env(entry)
246
273
  GC.enable; GC.start; GC.disable
247
274
  request_count = 0
248
275
  n.times do
@@ -257,7 +284,7 @@ class RailsBenchmark
257
284
 
258
285
  def run_urls_without_benchmark_and_without_gc_control(urls, n)
259
286
  urls.each do |entry|
260
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
287
+ setup_request_env(entry)
261
288
  n.times do
262
289
  Dispatcher.dispatch
263
290
  end
@@ -269,8 +296,8 @@ class RailsBenchmark
269
296
  GC.clear_stats if gc_stats
270
297
  urls.each do |entry|
271
298
  request_count = 0
272
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
273
- test.report(entry['uri']) do
299
+ setup_request_env(entry)
300
+ test.report(entry.name) do
274
301
  GC.disable_stats if gc_stats
275
302
  GC.enable; GC.start; GC.disable
276
303
  GC.enable_stats if gc_stats
@@ -294,11 +321,11 @@ class RailsBenchmark
294
321
  gc_stats = patched_gc?
295
322
  GC.clear_stats if gc_stats
296
323
  urls.each do |entry|
297
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
324
+ setup_request_env(entry)
298
325
  GC.disable_stats if gc_stats
299
326
  GC.start
300
327
  GC.enable_stats if gc_stats
301
- test.report(entry['uri']) do
328
+ test.report(entry.name) do
302
329
  n.times do
303
330
  Dispatcher.dispatch
304
331
  end
@@ -320,7 +347,7 @@ class RailsBenchmark
320
347
  test.report("url_mix (#{urls.length} urls)") do
321
348
  n.times do
322
349
  urls.each do |entry|
323
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
350
+ setup_request_env(entry)
324
351
  Dispatcher.dispatch
325
352
  end
326
353
  end
@@ -342,7 +369,7 @@ class RailsBenchmark
342
369
  request_count = 0
343
370
  n.times do
344
371
  urls.each do |entry|
345
- setup_request_env(entry['uri'], entry['query_string'], entry['new_session'])
372
+ setup_request_env(entry)
346
373
  Dispatcher.dispatch
347
374
  if (request_count += 1) == gc_frequency
348
375
  GC.enable; GC.start; GC.disable
@@ -357,17 +384,6 @@ class RailsBenchmark
357
384
  GC.clear_stats
358
385
  end
359
386
  end
360
-
361
- def self.parse_url_spec(url_spec, name)
362
- res = url_spec[name]
363
- if res.is_a?(String)
364
- res = res.split(/, */).collect!{ |n| parse_url_spec(url_spec, n) }.flatten
365
- elsif res.is_a?(Hash)
366
- res = [ res ]
367
- end
368
- res
369
- end
370
-
371
387
  end
372
388
 
373
389
 
@@ -2,7 +2,7 @@ module Railsbench #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+
5
+ require 'fileutils'
6
+ require 'railsbench/benchmark_specs'
7
+
8
+ ARGV.each do |file_name|
9
+ backup_file_name = file_name + '~'
10
+ FileUtils.mv(file_name, backup_file_name)
11
+ File.open(backup_file_name) do |infile|
12
+ bench_name = Hash.new{ |hash,key| hash[key] = key }
13
+ File.open(file_name, "w") do |outfile|
14
+ infile.each_line do |line|
15
+ case line
16
+ when /-bm=([^\s]+)/
17
+ # $stderr.puts "-bm=#{$1}"
18
+ outfile.puts(line)
19
+ benchmarks = BenchmarkSpec.load($1)
20
+ benchmarks.each{|spec| bench_name[spec.uri] = spec.name}
21
+ when /^(.*)(\s+[\d\.]+\s+[\d\.]+\s+[\d\.]+\s+\(\s*[\d\.]+\s*\))$/
22
+ l = $1.length
23
+ # $stderr.printf "%-#{l}s%s\n", $1.strip, $2
24
+ outfile.printf "%-#{l}s%s\n", bench_name[$1.strip], $2
25
+ else
26
+ outfile.puts(line)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ __END__
34
+
35
+ # Copyright (C) 2007 Stefan Kaes
36
+ #
37
+ # This program is free software; you can redistribute it and/or modify
38
+ # it under the terms of the GNU General Public License as published by
39
+ # the Free Software Foundation; either version 2 of the License, or
40
+ # (at your option) any later version.
41
+ #
42
+ # This program is distributed in the hope that it will be useful,
43
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
44
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45
+ # GNU General Public License for more details.
46
+ #
47
+ # You should have received a copy of the GNU General Public License
48
+ # along with this program; if not, write to the Free Software
49
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -50,8 +50,8 @@ def dump_entry(name, entry, io = $stdout)
50
50
  end
51
51
  end
52
52
 
53
- if defined? ActionController::CodeGeneration
54
- $stderr.puts "this Rails version is not supported. please upgrade to a 1.2 variety."
53
+ unless Rails::VERSION::MAJOR >= 1 && Rails::VERSION::MINOR >= 2
54
+ $stderr.puts "Rails version #{Rails::VERSION::STRING} is not supported. please use a 1.2.x variety."
55
55
  exit 1
56
56
  end
57
57
 
@@ -34,12 +34,10 @@ bm(32) do |test|
34
34
  exit!(-1)
35
35
  end
36
36
 
37
- benchmarks = YAML::load(File.open(ENV['RAILS_ROOT'] + "/config/benchmarks.yml"))
38
37
  benchmark_name = "default"
39
38
  ARGV.each{ |arg| benchmark_name = $1 if arg =~ /-bm=([a-zA-Z_0-9]+)/ }
40
39
 
41
40
  RAILS_BENCHMARKER.iterations = ARGV[0].to_i
42
- RAILS_BENCHMARKER.url_spec = benchmarks
43
41
  RAILS_BENCHMARKER.setup_test_urls(benchmark_name)
44
42
  RAILS_BENCHMARKER.establish_test_session
45
43
  RAILS_BENCHMARKER.warmup
@@ -110,7 +110,7 @@ if pi[0].gc_stats? && pi[1].gc_stats?
110
110
  t1 = pi[0].gc_time_mean
111
111
  c2 = pi[1].gc_calls_mean
112
112
  t2 = pi[1].gc_time_mean
113
- factor = (c1-c2==0) ? 1 : c1/c2
113
+ factor = (t1-t2==0) ? 1 : t1/t2
114
114
 
115
115
  if narrow
116
116
  printf "\n%-4s %9s %9s %7s %7s %8s %8s %6s\n",
@@ -27,7 +27,7 @@ file2 = benchmark_file_name(benchmark, ARGV[5], 2)
27
27
  perf_run("perf_diff", iterations, "#{common} #{options2}", file2)
28
28
  puts;puts
29
29
 
30
- system("ruby #{bindir}/perf_comp -narrow -skip_urls #{file1} #{file2}")
30
+ system("ruby #{bindir}/perf_comp #{file1} #{file2}")
31
31
 
32
32
  __END__
33
33
 
@@ -11,6 +11,12 @@ puts <<'END'
11
11
  .c1 { background:#fff3df; }
12
12
  .c2 { background:#dfedff; }
13
13
  .factor { background:#efe0ef; }
14
+ .factor_red_alert { background:#CC303B; }
15
+ .factor_red { background:#FF6060; }
16
+ .factor_reddish { background:#FFA766; }
17
+ .factor_green_alert { background:#0B8900; }
18
+ .factor_green { background:#6AB788; }
19
+ .factor_greenish { background:#7FFFB0; }
14
20
  .name { background:#dfdfdf; }
15
21
  .perf_name { text-align:left; }
16
22
  .perf_data { text-align:right; }
@@ -19,6 +25,25 @@ puts <<'END'
19
25
  END
20
26
  end
21
27
 
28
+ def factor_class(v)
29
+ return 'factor' unless ARGV.include?('-colorize')
30
+ if v <= 0.85
31
+ 'factor_red_alert'
32
+ elsif v <= 0.90
33
+ 'factor_red'
34
+ elsif v <= 0.95
35
+ 'factor_reddish'
36
+ elsif v >= 1.15
37
+ 'factor_green_alert'
38
+ elsif v >= 1.10
39
+ 'factor_green'
40
+ elsif v >= 1.05
41
+ 'factor_greenish'
42
+ else
43
+ 'factor'
44
+ end
45
+ end
46
+
22
47
  unless ARGV.include?('-notable')
23
48
  puts "<table cellspacing=1px>"
24
49
  $stdin.each_line do |l|
@@ -46,13 +71,13 @@ unless ARGV.include?('-notable')
46
71
  puts "</tr>"
47
72
  end
48
73
  case l
49
- when %r{^([A-Za-z0-9./?= ]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+$}
74
+ when %r{^([A-Za-z0-9./?=_ ]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+$}
50
75
  puts "<tr>"
51
76
  puts "<td class='perf_name name#{" i" if $1.strip == "all requests"}'>#{$1}</td>"
52
77
  puts "<td class='perf_data c1'>#{$2}</td><td class='perf_data c2'>#{$3}</td>"
53
78
  puts "<td class='perf_data c1'>#{$4}</td><td class='perf_data c2'>#{$5}</td>"
54
79
  puts "<td class='perf_data c1'>#{$6}</td><td class='perf_data c2'>#{$7}</td>"
55
- puts "<td class='perf_data factor'>#{$8}</td>"
80
+ puts "<td class='perf_data #{factor_class($8.to_f)}'>#{$8}</td>"
56
81
  puts "</tr>"
57
82
  end
58
83
  end
@@ -15,7 +15,11 @@ names = []
15
15
  labels = []
16
16
  perf_data = []
17
17
  graph_type = Gruff::Line
18
- graph_width = 800
18
+ graph_width = '800x600'
19
+ font_size = 14
20
+ output_file = "graph.png"
21
+ colors = nil
22
+ theme = nil
19
23
 
20
24
  ARGV.each do |arg|
21
25
  case arg
@@ -29,18 +33,29 @@ ARGV.each do |arg|
29
33
  graph_type = Gruff::Bar
30
34
  when /^-width=(\d+)$/
31
35
  graph_width = $1.to_i
36
+ when /^-geometry=(\d+x\d+)$/
37
+ graph_width = $1
38
+ when /^-colors=(.*)$/
39
+ colors = $1.split(/ *,/)
40
+ when /^-theme=(.*)$/
41
+ theme = $1
32
42
  when /^-names=(.+)$/
33
43
  names = $1.split(',')
34
44
  when /^-labels=(.+)$/
35
45
  labels = $1.split(',')
46
+ when /^-font_size=(\d+)$/
47
+ font_size = $1.to_i
48
+ when /^-out=(.+)$/
49
+ output_file = $1
36
50
  else
37
51
  files << File.open_or_die(arg)
38
- names[files.length-1] ||= File.basename(arg)
52
+ names[files.length-1] ||= File.basename(arg).sub(/\.txt$/, '').sub(/^\d\d-\d\d\.[^\.]+./, '')
39
53
  end
40
54
  end
41
55
 
42
56
  files.length > 0 or die "usage: perf_plot [options] file1 file2 ..."
43
57
 
58
+ pi = nil
44
59
  files.each do |file|
45
60
  pi = PerfInfo.new(file)
46
61
  iter = pi.iterations
@@ -51,9 +66,7 @@ end
51
66
 
52
67
  selection = (1..(perf_data.last.length)).to_a if selection.empty?
53
68
  if labels.empty?
54
- labels = selection.map{|i| i.to_s}.index_map
55
- else
56
- labels = labels.index_map
69
+ labels = pi.keys.restrict_to(selection.map{|i| i-1})
57
70
  end
58
71
  perf_data = perf_data.map{|d| d.restrict_to(selection.map{|i| i-1})}
59
72
 
@@ -62,13 +75,18 @@ perf_data = perf_data.map{|d| d.restrict_to(selection.map{|i| i-1})}
62
75
  # puts perf_data.inspect
63
76
 
64
77
  g = graph_type.new(graph_width)
78
+ g.send "theme_#{theme}" if theme
79
+ g.replace_colors(colors) if colors
65
80
  g.title = title
66
81
  g.sort = false
82
+ g.legend_font_size = font_size
83
+ g.legend_box_size = font_size
84
+ g.marker_font_size = font_size
67
85
  g.minimum_value = 0
68
86
  g.maximum_value = perf_data.flatten.max.ceil
69
- g.labels = labels
87
+ g.labels = labels.index_map
70
88
  perf_data.each_with_index{|d,i| g.data(names[i], d)}
71
- g.write
89
+ g.write(output_file)
72
90
 
73
91
 
74
92
  __END__
@@ -15,7 +15,8 @@ names = []
15
15
  labels = %w()
16
16
  perf_data = []
17
17
  graph_type = Gruff::StackedBar
18
- graph_width = 1400
18
+ graph_width = '1400x1050'
19
+ font_size = 14
19
20
  ignored_object_types = %w(NODE STRING)
20
21
 
21
22
  ARGV.each do |arg|
@@ -26,10 +27,14 @@ ARGV.each do |arg|
26
27
  # graph_type = Gruff::Bar
27
28
  when /^-width=(\d+)$/
28
29
  graph_width = $1.to_i
30
+ when /^-geometry=(\d+x\d+)$/
31
+ graph_width = $1
29
32
  # when /^-title=(.*)$/
30
33
  # title = $1 unless $1.strip.empty?
31
34
  # when /^-names=(.+)$/
32
35
  # names = $1.split(',')
36
+ when /^-font_size=(\d+)$/
37
+ font_size = $1.to_i
33
38
  when /^-ignore=(.*)$/
34
39
  ignored_object_types = $1.split(',').map(&:upcase)
35
40
  else
@@ -65,9 +70,9 @@ end
65
70
 
66
71
  g.title = title
67
72
  g.sort = false
68
- g.legend_font_size = 8
69
- g.legend_box_size = 8
70
- g.marker_font_size = 8
73
+ g.legend_font_size = font_size
74
+ g.legend_box_size = font_size
75
+ g.marker_font_size = font_size
71
76
  #g.minimum_value = 0
72
77
  #g.maximum_value = gc_max_processed
73
78
  g.labels = Hash[* (0...gc_count_max).map{|i| [2*i, i.to_s]}.flatten ]
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ require 'railsbench/perf_info'
5
+
6
+ # extract options
7
+
8
+ selection = []
9
+ title = "Performance Graph"
10
+ files = []
11
+ names = []
12
+ labels = []
13
+ perf_data = []
14
+ font_size = 14
15
+ output_file = "graph.png"
16
+ colors = nil
17
+
18
+ ARGV.each do |arg|
19
+ case arg
20
+ when /^-only=(.*)$/
21
+ selection = $1.split(',').map{|s| s.strip.to_i}
22
+ when /^-title=(.*)$/
23
+ title = $1 unless $1.strip.empty?
24
+ when '-line'
25
+ graph_type = Gruff::Line
26
+ when '-bar'
27
+ graph_type = Gruff::Bar
28
+ when /^-width=(\d+)$/
29
+ graph_width = $1.to_i
30
+ when /^-geometry=(\d+x\d+)$/
31
+ graph_width = $1
32
+ when /^-colors=(.*)$/
33
+ colors = $1.split(/ *,/)
34
+ when /^-names=(.+)$/
35
+ names = $1.split(',')
36
+ when /^-labels=(.+)$/
37
+ labels = $1.split(',')
38
+ when /^-font_size=(\d+)$/
39
+ font_size = $1.to_i
40
+ when /^-out=(.+)$/
41
+ output_file = $1
42
+ else
43
+ files << File.open_or_die(arg)
44
+ names << File.basename(arg).sub(/\.txt$/, '').sub(/^\d\d-\d\d\.[^\.]+./, '')
45
+ end
46
+ end
47
+
48
+ files.length > 0 or die "usage: perf_table [options] file1 file2 ..."
49
+
50
+ pi = nil
51
+ files.each do |file|
52
+ pi = PerfInfo.new(file)
53
+ iter = pi.iterations
54
+ urls = pi.requests_per_key
55
+ perf_data << pi.keys.map{ |key| iter*urls/pi.timings_mean(key) }
56
+ file.close
57
+ end
58
+
59
+ selection = (1..(perf_data.last.length)).to_a if selection.empty?
60
+ if labels.empty?
61
+ labels = pi.keys.restrict_to(selection.map{|i| i-1})
62
+ end
63
+ perf_data = perf_data.map{|d| d.restrict_to(selection.map{|i| i-1})}
64
+
65
+ #puts selection.inspect
66
+ #puts labels.length
67
+ #puts labels.inspect
68
+ #puts perf_data.length
69
+ #puts perf_data.inspect
70
+ #puts names.inspect
71
+
72
+ # puts labels.zip(perf_data).inspect
73
+ puts "<table border=1>"
74
+ puts "<tr><td></td>"
75
+ labels.each{|l| puts "<th>#{l}</th>"}
76
+ puts "</tr>"
77
+ names.zip(perf_data).each do |row|
78
+ puts "<tr>"
79
+ puts "<th align='left'>#{row.first}</th>"
80
+ row.last.each do |cell|
81
+ puts "<td align='right'>#{sprintf "%6.2f", cell}</td>"
82
+ end
83
+ puts "</tr>"
84
+ end
85
+ puts "</table>"
86
+
87
+
88
+ __END__
89
+
90
+ # Copyright (C) 2007 Stefan Kaes
91
+ #
92
+ # This program is free software; you can redistribute it and/or modify
93
+ # it under the terms of the GNU General Public License as published by
94
+ # the Free Software Foundation; either version 2 of the License, or
95
+ # (at your option) any later version.
96
+ #
97
+ # This program is distributed in the hope that it will be useful,
98
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
99
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100
+ # GNU General Public License for more details.
101
+ #
102
+ # You should have received a copy of the GNU General Public License
103
+ # along with this program; if not, write to the Free Software
104
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -23,12 +23,10 @@ trap("INT") do
23
23
  exit!(-1)
24
24
  end
25
25
 
26
- benchmarks = YAML::load(File.open(ENV['RAILS_ROOT'] + "/config/benchmarks.yml"))
27
26
  benchmark_name = "default"
28
27
  ARGV.each{ |arg| benchmark_name = $1 if arg =~ /-bm=([^ ]+)/ }
29
28
 
30
29
  RAILS_BENCHMARKER.iterations = ARGV[0].to_i
31
- RAILS_BENCHMARKER.url_spec = benchmarks
32
30
  RAILS_BENCHMARKER.setup_test_urls(benchmark_name)
33
31
  RAILS_BENCHMARKER.establish_test_session
34
32
  RAILS_BENCHMARKER.warmup if ARGV.include?('-warmup')
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: railsbench
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.1
7
- date: 2007-01-14 00:00:00 +01:00
6
+ version: 0.9.2
7
+ date: 2007-04-01 00:00:00 +02:00
8
8
  summary: rails benchmarking tools
9
9
  require_paths:
10
10
  - lib
@@ -36,6 +36,7 @@ files:
36
36
  - postinstall.rb
37
37
  - LICENSE
38
38
  - Manifest.txt
39
+ - PROBLEMS
39
40
  - README
40
41
  - Rakefile
41
42
  - setup.rb
@@ -48,8 +49,10 @@ files:
48
49
  - lib/railsbench/perf_utils.rb
49
50
  - lib/railsbench/write_headers_only.rb
50
51
  - lib/railsbench/railsbenchmark.rb
52
+ - lib/railsbench/benchmark_specs.rb
51
53
  - lib/benchmark.rb
52
54
  - script/generate_benchmarks
55
+ - script/convert_raw_data_files
53
56
  - script/perf_bench
54
57
  - script/perf_comp
55
58
  - script/perf_comp_gc
@@ -61,6 +64,7 @@ files:
61
64
  - script/perf_prof
62
65
  - script/perf_run
63
66
  - script/perf_run_gc
67
+ - script/perf_table
64
68
  - script/perf_tex
65
69
  - script/perf_times
66
70
  - script/perf_times_gc
@@ -88,5 +92,5 @@ dependencies:
88
92
  requirements:
89
93
  - - ">="
90
94
  - !ruby/object:Gem::Version
91
- version: 1.1.6
95
+ version: 1.2.0
92
96
  version: