bigbench 0.0.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.
Files changed (92) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/README.textile +81 -0
  4. data/Rakefile +10 -0
  5. data/bigbench.gemspec +29 -0
  6. data/bin/bigbench +6 -0
  7. data/doc/BigBench.html +631 -0
  8. data/doc/BigBench/Benchmark.html +328 -0
  9. data/doc/BigBench/Benchmark/Benchmark.html +431 -0
  10. data/doc/BigBench/Bot.html +233 -0
  11. data/doc/BigBench/Configuration.html +312 -0
  12. data/doc/BigBench/Configuration/Config.html +375 -0
  13. data/doc/BigBench/Configuration/InvalidOptions.html +217 -0
  14. data/doc/BigBench/Executor.html +252 -0
  15. data/doc/BigBench/Executor/InvalidCommand.html +222 -0
  16. data/doc/BigBench/Fragment.html +404 -0
  17. data/doc/BigBench/Fragment/Fragment.html +384 -0
  18. data/doc/BigBench/Output.html +703 -0
  19. data/doc/BigBench/Runner.html +222 -0
  20. data/doc/BigBench/Runner/NoBenchmarksDefined.html +217 -0
  21. data/doc/BigBench/Store.html +639 -0
  22. data/doc/BigBench/Tracker.html +179 -0
  23. data/doc/BigBench/Tracker/Tracker.html +273 -0
  24. data/doc/Float.html +217 -0
  25. data/doc/Gemfile.html +129 -0
  26. data/doc/Helpers.html +163 -0
  27. data/doc/Object.html +181 -0
  28. data/doc/Rakefile.html +136 -0
  29. data/doc/TestWebServer.html +247 -0
  30. data/doc/created.rid +31 -0
  31. data/doc/images/add.png +0 -0
  32. data/doc/images/brick.png +0 -0
  33. data/doc/images/brick_link.png +0 -0
  34. data/doc/images/bug.png +0 -0
  35. data/doc/images/bullet_black.png +0 -0
  36. data/doc/images/bullet_toggle_minus.png +0 -0
  37. data/doc/images/bullet_toggle_plus.png +0 -0
  38. data/doc/images/date.png +0 -0
  39. data/doc/images/delete.png +0 -0
  40. data/doc/images/find.png +0 -0
  41. data/doc/images/loadingAnimation.gif +0 -0
  42. data/doc/images/macFFBgHack.png +0 -0
  43. data/doc/images/package.png +0 -0
  44. data/doc/images/page_green.png +0 -0
  45. data/doc/images/page_white_text.png +0 -0
  46. data/doc/images/page_white_width.png +0 -0
  47. data/doc/images/plugin.png +0 -0
  48. data/doc/images/ruby.png +0 -0
  49. data/doc/images/tag_blue.png +0 -0
  50. data/doc/images/tag_green.png +0 -0
  51. data/doc/images/transparent.png +0 -0
  52. data/doc/images/wrench.png +0 -0
  53. data/doc/images/wrench_orange.png +0 -0
  54. data/doc/images/zoom.png +0 -0
  55. data/doc/index.html +122 -0
  56. data/doc/js/darkfish.js +153 -0
  57. data/doc/js/jquery.js +18 -0
  58. data/doc/js/navigation.js +142 -0
  59. data/doc/js/search.js +94 -0
  60. data/doc/js/search_index.js +1 -0
  61. data/doc/js/searcher.js +228 -0
  62. data/doc/lib/bigbench/help/executor_txt.html +145 -0
  63. data/doc/rdoc.css +543 -0
  64. data/doc/table_of_contents.html +263 -0
  65. data/lib/bigbench.rb +18 -0
  66. data/lib/bigbench/benchmark.rb +126 -0
  67. data/lib/bigbench/bot.rb +34 -0
  68. data/lib/bigbench/configuration.rb +109 -0
  69. data/lib/bigbench/executor.rb +131 -0
  70. data/lib/bigbench/float_extensions.rb +6 -0
  71. data/lib/bigbench/fragment.rb +119 -0
  72. data/lib/bigbench/help/executor.txt +17 -0
  73. data/lib/bigbench/initializers.rb +2 -0
  74. data/lib/bigbench/output.rb +116 -0
  75. data/lib/bigbench/runner.rb +52 -0
  76. data/lib/bigbench/store.rb +92 -0
  77. data/lib/bigbench/tracker.rb +79 -0
  78. data/lib/bigbench/version.rb +3 -0
  79. data/spec/benchmark_spec.rb +69 -0
  80. data/spec/bot_spec.rb +31 -0
  81. data/spec/configure_spec.rb +39 -0
  82. data/spec/executor_spec.rb +80 -0
  83. data/spec/fragment_spec.rb +110 -0
  84. data/spec/helpers.rb +19 -0
  85. data/spec/lib/test_web_server.rb +18 -0
  86. data/spec/runner_spec.rb +40 -0
  87. data/spec/store_spec.rb +72 -0
  88. data/spec/tests/local.rb +15 -0
  89. data/spec/tests/local_invalid.rb +9 -0
  90. data/spec/tracker_spec.rb +50 -0
  91. data/spec/webserver_spec.rb +35 -0
  92. metadata +220 -0
@@ -0,0 +1,263 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Table of Contents - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body class="indexpage">
24
+ <h1>Table of Contents - RDoc Documentation</h1>
25
+
26
+ <h2>Pages</h2>
27
+ <ul>
28
+ <li class="file">
29
+ <a href="Gemfile.html">Gemfile</a>
30
+ </li>
31
+ <li class="file">
32
+ <a href="Rakefile.html">Rakefile</a>
33
+ </li>
34
+ <li class="file">
35
+ <a href="lib/bigbench/help/executor_txt.html">executor</a>
36
+ </li>
37
+
38
+ </ul>
39
+
40
+ <h2 id="classes">Classes/Modules</h2>
41
+ <ul>
42
+ <li class="module">
43
+ <a href="BigBench.html">BigBench</a>
44
+ </li>
45
+ <li class="module">
46
+ <a href="BigBench/Benchmark.html">BigBench::Benchmark</a>
47
+ </li>
48
+ <li class="class">
49
+ <a href="BigBench/Benchmark/Benchmark.html">BigBench::Benchmark::Benchmark</a>
50
+ </li>
51
+ <li class="module">
52
+ <a href="BigBench/Bot.html">BigBench::Bot</a>
53
+ </li>
54
+ <li class="module">
55
+ <a href="BigBench/Configuration.html">BigBench::Configuration</a>
56
+ </li>
57
+ <li class="class">
58
+ <a href="BigBench/Configuration/Config.html">BigBench::Configuration::Config</a>
59
+ </li>
60
+ <li class="class">
61
+ <a href="BigBench/Configuration/InvalidOptions.html">BigBench::Configuration::InvalidOptions</a>
62
+ </li>
63
+ <li class="module">
64
+ <a href="BigBench/Executor.html">BigBench::Executor</a>
65
+ </li>
66
+ <li class="class">
67
+ <a href="BigBench/Executor/InvalidCommand.html">BigBench::Executor::InvalidCommand</a>
68
+ </li>
69
+ <li class="module">
70
+ <a href="BigBench/Fragment.html">BigBench::Fragment</a>
71
+ </li>
72
+ <li class="class">
73
+ <a href="BigBench/Fragment/Fragment.html">BigBench::Fragment::Fragment</a>
74
+ </li>
75
+ <li class="module">
76
+ <a href="BigBench/Output.html">BigBench::Output</a>
77
+ </li>
78
+ <li class="module">
79
+ <a href="BigBench/Runner.html">BigBench::Runner</a>
80
+ </li>
81
+ <li class="class">
82
+ <a href="BigBench/Runner/NoBenchmarksDefined.html">BigBench::Runner::NoBenchmarksDefined</a>
83
+ </li>
84
+ <li class="module">
85
+ <a href="BigBench/Store.html">BigBench::Store</a>
86
+ </li>
87
+ <li class="module">
88
+ <a href="BigBench/Tracker.html">BigBench::Tracker</a>
89
+ </li>
90
+ <li class="class">
91
+ <a href="BigBench/Tracker/Tracker.html">BigBench::Tracker::Tracker</a>
92
+ </li>
93
+ <li class="class">
94
+ <a href="Float.html">Float</a>
95
+ </li>
96
+ <li class="module">
97
+ <a href="Helpers.html">Helpers</a>
98
+ </li>
99
+ <li class="class">
100
+ <a href="Object.html">Object</a>
101
+ </li>
102
+ <li class="module">
103
+ <a href="TestWebServer.html">TestWebServer</a>
104
+ </li>
105
+
106
+ </ul>
107
+
108
+ <h2 id="methods">Methods</h2>
109
+ <ul>
110
+
111
+ <li class="method"><a href="BigBench/Benchmark.html#method-c-add">::add &mdash; BigBench::Benchmark</a>
112
+
113
+ <li class="method"><a href="BigBench/Configuration/Config.html#method-c-add_option">::add_option &mdash; BigBench::Configuration::Config</a>
114
+
115
+ <li class="method"><a href="BigBench/Store.html#method-c-add_tracking">::add_tracking &mdash; BigBench::Store</a>
116
+
117
+ <li class="method"><a href="BigBench/Benchmark.html#method-c-all">::all &mdash; BigBench::Benchmark</a>
118
+
119
+ <li class="method"><a href="BigBench.html#method-c-benchmark">::benchmark &mdash; BigBench</a>
120
+
121
+ <li class="method"><a href="BigBench.html#method-c-benchmarks">::benchmarks &mdash; BigBench</a>
122
+
123
+ <li class="method"><a href="BigBench/Output.html#method-c-bot_is_checking">::bot_is_checking &mdash; BigBench::Output</a>
124
+
125
+ <li class="method"><a href="BigBench/Store.html#method-c-bot_is_working">::bot_is_working &mdash; BigBench::Store</a>
126
+
127
+ <li class="method"><a href="BigBench/Output.html#method-c-bot_received_test_instructions">::bot_received_test_instructions &mdash; BigBench::Output</a>
128
+
129
+ <li class="method"><a href="BigBench/Store.html#method-c-bot_stopped_working">::bot_stopped_working &mdash; BigBench::Store</a>
130
+
131
+ <li class="method"><a href="BigBench/Store.html#method-c-bots">::bots &mdash; BigBench::Store</a>
132
+
133
+ <li class="method"><a href="BigBench.html#method-c-check_config-21">::check_config! &mdash; BigBench</a>
134
+
135
+ <li class="method"><a href="BigBench/Bot.html#method-c-check_test-21">::check_test! &mdash; BigBench::Bot</a>
136
+
137
+ <li class="method"><a href="BigBench/Configuration.html#method-c-config">::config &mdash; BigBench::Configuration</a>
138
+
139
+ <li class="method"><a href="BigBench.html#method-c-config">::config &mdash; BigBench</a>
140
+
141
+ <li class="method"><a href="BigBench/Configuration.html#method-c-configure-3D">::configure= &mdash; BigBench::Configuration</a>
142
+
143
+ <li class="method"><a href="BigBench.html#method-c-configure-3D">::configure= &mdash; BigBench</a>
144
+
145
+ <li class="method"><a href="BigBench/Store.html#method-c-count_trackings">::count_trackings &mdash; BigBench::Store</a>
146
+
147
+ <li class="method"><a href="BigBench/Fragment.html#method-c-delete">::delete &mdash; BigBench::Fragment</a>
148
+
149
+ <li class="method"><a href="BigBench/Output.html#method-c-deployed_test">::deployed_test &mdash; BigBench::Output</a>
150
+
151
+ <li class="method"><a href="BigBench/Output.html#method-c-done">::done &mdash; BigBench::Output</a>
152
+
153
+ <li class="method"><a href="BigBench.html#method-c-duration">::duration &mdash; BigBench</a>
154
+
155
+ <li class="method"><a href="BigBench/Output.html#method-c-finished_bots_loop">::finished_bots_loop &mdash; BigBench::Output</a>
156
+
157
+ <li class="method"><a href="BigBench/Output.html#method-c-finished_running_benchmarks">::finished_running_benchmarks &mdash; BigBench::Output</a>
158
+
159
+ <li class="method"><a href="BigBench/Output.html#method-c-finished_writing_trackings">::finished_writing_trackings &mdash; BigBench::Output</a>
160
+
161
+ <li class="method"><a href="BigBench/Fragment.html#method-c-get">::get &mdash; BigBench::Fragment</a>
162
+
163
+ <li class="method"><a href="BigBench.html#method-c-load_test-21">::load_test! &mdash; BigBench</a>
164
+
165
+ <li class="method"><a href="BigBench/Output.html#method-c-loaded_tests">::loaded_tests &mdash; BigBench::Output</a>
166
+
167
+ <li class="method"><a href="BigBench/Benchmark.html#method-c-max_duration">::max_duration &mdash; BigBench::Benchmark</a>
168
+
169
+ <li class="method"><a href="BigBench/Benchmark/Benchmark.html#method-c-new">::new &mdash; BigBench::Benchmark::Benchmark</a>
170
+
171
+ <li class="method"><a href="BigBench/Fragment/Fragment.html#method-c-new">::new &mdash; BigBench::Fragment::Fragment</a>
172
+
173
+ <li class="method"><a href="BigBench/Tracker/Tracker.html#method-c-new">::new &mdash; BigBench::Tracker::Tracker</a>
174
+
175
+ <li class="method"><a href="BigBench/Configuration/Config.html#method-c-new">::new &mdash; BigBench::Configuration::Config</a>
176
+
177
+ <li class="method"><a href="BigBench/Fragment.html#method-c-parse">::parse &mdash; BigBench::Fragment</a>
178
+
179
+ <li class="method"><a href="BigBench/Store.html#method-c-pop_tracking">::pop_tracking &mdash; BigBench::Store</a>
180
+
181
+ <li class="method"><a href="BigBench/Fragment.html#method-c-post">::post &mdash; BigBench::Fragment</a>
182
+
183
+ <li class="method"><a href="BigBench/Fragment.html#method-c-put">::put &mdash; BigBench::Fragment</a>
184
+
185
+ <li class="method"><a href="BigBench/Output.html#method-c-reset">::reset &mdash; BigBench::Output</a>
186
+
187
+ <li class="method"><a href="BigBench/Configuration.html#method-c-reset-21">::reset! &mdash; BigBench::Configuration</a>
188
+
189
+ <li class="method"><a href="BigBench/Store.html#method-c-reset-21">::reset! &mdash; BigBench::Store</a>
190
+
191
+ <li class="method"><a href="BigBench/Fragment.html#method-c-reset-21">::reset! &mdash; BigBench::Fragment</a>
192
+
193
+ <li class="method"><a href="BigBench/Benchmark.html#method-c-reset-21">::reset! &mdash; BigBench::Benchmark</a>
194
+
195
+ <li class="method"><a href="BigBench/Executor.html#method-c-run-21">::run! &mdash; BigBench::Executor</a>
196
+
197
+ <li class="method"><a href="BigBench/Runner.html#method-c-run-21">::run! &mdash; BigBench::Runner</a>
198
+
199
+ <li class="method"><a href="BigBench.html#method-c-run-21">::run! &mdash; BigBench</a>
200
+
201
+ <li class="method"><a href="BigBench/Store.html#method-c-running-3F">::running? &mdash; BigBench::Store</a>
202
+
203
+ <li class="method"><a href="BigBench/Output.html#method-c-running_benchmarks">::running_benchmarks &mdash; BigBench::Output</a>
204
+
205
+ <li class="method"><a href="BigBench/Output.html#method-c-running_bots_loop">::running_bots_loop &mdash; BigBench::Output</a>
206
+
207
+ <li class="method"><a href="BigBench/Store.html#method-c-setup-21">::setup! &mdash; BigBench::Store</a>
208
+
209
+ <li class="method"><a href="TestWebServer.html#method-c-start">::start &mdash; TestWebServer</a>
210
+
211
+ <li class="method"><a href="BigBench/Store.html#method-c-start">::start &mdash; BigBench::Store</a>
212
+
213
+ <li class="method"><a href="BigBench/Output.html#method-c-start">::start &mdash; BigBench::Output</a>
214
+
215
+ <li class="method"><a href="BigBench/Output.html#method-c-starting_bots_loop">::starting_bots_loop &mdash; BigBench::Output</a>
216
+
217
+ <li class="method"><a href="BigBench/Store.html#method-c-stop">::stop &mdash; BigBench::Store</a>
218
+
219
+ <li class="method"><a href="TestWebServer.html#method-c-stop">::stop &mdash; TestWebServer</a>
220
+
221
+ <li class="method"><a href="BigBench/Store.html#method-c-test">::test &mdash; BigBench::Store</a>
222
+
223
+ <li class="method"><a href="BigBench/Store.html#method-c-test-3D">::test= &mdash; BigBench::Store</a>
224
+
225
+ <li class="method"><a href="BigBench.html#method-c-write_local_trackings_to_file-21">::write_local_trackings_to_file! &mdash; BigBench</a>
226
+
227
+ <li class="method"><a href="BigBench.html#method-c-write_store_trackings_to_file-21">::write_store_trackings_to_file! &mdash; BigBench</a>
228
+
229
+ <li class="method"><a href="BigBench.html#method-c-write_trackings_to_store-21">::write_trackings_to_store! &mdash; BigBench</a>
230
+
231
+ <li class="method"><a href="BigBench/Output.html#method-c-writing_trackings">::writing_trackings &mdash; BigBench::Output</a>
232
+
233
+ <li class="method"><a href="BigBench/Output.html#method-c-wrote_trackings">::wrote_trackings &mdash; BigBench::Output</a>
234
+
235
+ <li class="method"><a href="BigBench/Benchmark/Benchmark.html#method-i-is_running-3F">#is_running? &mdash; BigBench::Benchmark::Benchmark</a>
236
+
237
+ <li class="method"><a href="BigBench/Runner/NoBenchmarksDefined.html#method-i-message">#message &mdash; BigBench::Runner::NoBenchmarksDefined</a>
238
+
239
+ <li class="method"><a href="BigBench/Configuration/InvalidOptions.html#method-i-message">#message &mdash; BigBench::Configuration::InvalidOptions</a>
240
+
241
+ <li class="method"><a href="BigBench/Executor/InvalidCommand.html#method-i-message">#message &mdash; BigBench::Executor::InvalidCommand</a>
242
+
243
+ <li class="method"><a href="BigBench/Fragment/Fragment.html#method-i-run-21">#run! &mdash; BigBench::Fragment::Fragment</a>
244
+
245
+ <li class="method"><a href="BigBench/Benchmark/Benchmark.html#method-i-run-21">#run! &mdash; BigBench::Benchmark::Benchmark</a>
246
+
247
+ <li class="method"><a href="Float.html#method-i-to_milliseconds">#to_milliseconds &mdash; Float</a>
248
+
249
+ <li class="method"><a href="BigBench/Tracker/Tracker.html#method-i-track">#track &mdash; BigBench::Tracker::Tracker</a>
250
+
251
+ <li class="method"><a href="BigBench/Fragment/Fragment.html#method-i-track-21">#track! &mdash; BigBench::Fragment::Fragment</a>
252
+
253
+ <li class="method"><a href="BigBench/Configuration/Config.html#method-i-valid-3F">#valid? &mdash; BigBench::Configuration::Config</a>
254
+
255
+ </ul>
256
+
257
+
258
+ <footer id="validator-badges">
259
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
260
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
261
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
262
+ </footer>
263
+
@@ -0,0 +1,18 @@
1
+ require 'redis'
2
+ require 'net/http'
3
+ require 'active_support/secure_random'
4
+ require 'active_support/all'
5
+
6
+ require "bigbench/float_extensions"
7
+ require "bigbench/version"
8
+ require "bigbench/configuration"
9
+ require "bigbench/benchmark"
10
+ require "bigbench/fragment"
11
+ require "bigbench/tracker"
12
+ require "bigbench/runner"
13
+ require "bigbench/executor"
14
+ require "bigbench/store"
15
+ require "bigbench/bot"
16
+ require "bigbench/output"
17
+
18
+ load "bigbench/initializers.rb"
@@ -0,0 +1,126 @@
1
+ module BigBench
2
+
3
+ # Holds the actual benchmark methods. A benchmark is a sequence of requests to the same server, but to different paths.
4
+ # A testrun can consist of multiple benchmarks like this:
5
+ #
6
+ # benchmark "default website pages" => "http://localhost:3000" do
7
+ # get "/"
8
+ # get "/blog"
9
+ # get "/imprint"
10
+ # end
11
+ #
12
+ # benchmark "login and logout" => "http://localhost:3000" do
13
+ # post "/login", { :name => "test@user.com", :password => "secret" }
14
+ # post "/logout"
15
+ # end
16
+ #
17
+ # Those benchmarks automatically get added to the modules benchmark array and can be retrieved with the BigBench#benchmarks method.
18
+ module Benchmark
19
+
20
+ @benchmarks = []
21
+
22
+ class Benchmark
23
+
24
+ attr_accessor :name
25
+ attr_accessor :uri
26
+ attr_accessor :threads
27
+ attr_accessor :duration
28
+ attr_accessor :fragments
29
+ attr_accessor :tracker
30
+ attr_accessor :start
31
+ attr_accessor :is_running
32
+ attr_accessor :runs
33
+
34
+ # Initizalizes a new benchmark
35
+ def initialize(name, url, options, &block)
36
+ @name, @uri, @tracker, @is_running, @runs = name, URI(url), Tracker::Tracker.new, false, 0
37
+ @threads = options[:threads] || BigBench.config.threads
38
+ @duration = options[:duration] || BigBench.config.duration
39
+ @fragments = BigBench::Fragment.parse(self, &block)
40
+ end
41
+
42
+ # Execute this benchmark
43
+ def run!
44
+
45
+ # Setup timer
46
+ timer = Thread.new{ sleep(@duration); @is_running = false }
47
+ @start, @is_running = Time.now, true
48
+
49
+ # Benchmark loop
50
+ @running_threads = []
51
+ @threads.times do
52
+ @running_threads << Thread.new do
53
+ while is_running? do
54
+ Net::HTTP.start(uri.host, uri.port) do |http|
55
+ @fragments.each{ |fragment| fragment.run!(http) }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ # Stop execution
62
+ @running_threads.each { |thread| thread.join }
63
+ @runs += 1
64
+ end
65
+
66
+ # Returns if this benchmark is currently running
67
+ def is_running?
68
+ @is_running
69
+ end
70
+
71
+ end
72
+
73
+ # Adds a benchmark to the <tt>BigBench</tt> module. It can later be retrieved with the <tt>all</tt> method.
74
+ def self.add(options, &block)
75
+ name, url = options.select{ |key, value| true unless key.is_a?(Symbol) }.first
76
+ benchmark = Benchmark.new(name, url, options, &block)
77
+ @benchmarks << benchmark
78
+ benchmark
79
+ end
80
+
81
+ # Returns all benchmarks that are registered
82
+ def self.all
83
+ @benchmarks
84
+ end
85
+
86
+ # Resets all benchmarks
87
+ def self.reset!
88
+ @benchmarks = []
89
+ end
90
+
91
+ # Returns the longest duration of all benchmarks
92
+ def self.max_duration
93
+ all.map{ |benchmark| benchmark.duration }.max
94
+ end
95
+
96
+ end
97
+
98
+ # Add a benchmark like this:
99
+ #
100
+ # benchmark "default website pages" => "http://localhost:3000" do
101
+ # get "/"
102
+ # get "/blog"
103
+ # get "/imprint"
104
+ # end
105
+ #
106
+ # benchmark "login and logout" => "http://localhost:3000" do
107
+ # post "/login", { :name => "test@user.com", :password => "secret" }
108
+ # post "http://localhost:3000/logout"
109
+ # end
110
+ #
111
+ def self.benchmark(options)
112
+ return unless block_given?
113
+ Benchmark.add(options, &Proc.new)
114
+ end
115
+
116
+ # List all available benchmarks
117
+ def self.benchmarks
118
+ Benchmark.all
119
+ end
120
+
121
+ # Returns the duration of all benchmarks - ergo the duration of the longest one
122
+ def self.duration
123
+ Benchmark.max_duration
124
+ end
125
+
126
+ end
@@ -0,0 +1,34 @@
1
+ module BigBench
2
+
3
+ # A bot is used for remote testing. It is running in the background of a machine and waits for tests to run. If you want to
4
+ # run a test with a cluster of 20 machines, simply set them all up and start the bot with:
5
+ #
6
+ # bigbench start bot [REDIS_RUL_WITH_PORT REDIS_PASSWORD]
7
+ #
8
+ # A bot will automatically check for a new test every minute. If a new test is available it runs the test and reports its results
9
+ # back to the redis. After that it goes into listening mode again.
10
+ module Bot
11
+
12
+ mattr_accessor :id
13
+
14
+ # Checks if there is a new test waiting on the store.
15
+ #
16
+ # If yes, it loads this test and executes it. After it has finished
17
+ # it writes its trackings to the stores tracking array.
18
+ def self.check_test!
19
+ return unless BigBench::Store.running?
20
+
21
+ BigBench::Output.bot_received_test_instructions
22
+ @id = SecureRandom.hex(16) if @id.nil?
23
+
24
+ BigBench.config.mode = :bot
25
+ BigBench.load_test!(BigBench::Store.test)
26
+
27
+ BigBench::Store.bot_is_working(@id)
28
+ BigBench.run!
29
+ BigBench.write_trackings_to_store!
30
+ BigBench::Store.bot_stopped_working(@id)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,109 @@
1
+ module BigBench
2
+
3
+ # The configuration is configured in the test reciepts and looks like this:
4
+ #
5
+ # BigBench.configure = {
6
+ # :duration => 10.seconds,
7
+ # :output => "test.ljson",
8
+ # :threads => 20
9
+ # }
10
+ #
11
+ # Single values can be set and retrieved like this:
12
+ #
13
+ # BigBench.config.duration = 20.minutes
14
+ # BigBench.config.duration # => 1200 (seconds)
15
+ #
16
+ # The following configuration values are possible - stared configurations need to be present:
17
+ #
18
+ # [duration*] How long will the benchmark take by default. This value can be overridden by every benchmark.
19
+ # [output*] The file where the results should be written to. Usually one takes the <tt>*.ljson</tt> format which is simply a file
20
+ # that contains a fully valid JSON object on every line. This makes it easy to process the results later on, because there's
21
+ # no need to parse the whole results JSON, which can get huge, at once.
22
+ # [threads] How many threads execute the benchmarks. This can be overridden by every benchmark and defaults to <tt>1</tt>.
23
+ module Configuration
24
+
25
+ # The main config object for BigBench. It allows config options to
26
+ # be added and forces some default values before it is <tt>valid?</tt>
27
+ class Config
28
+ attr_accessor :duration
29
+ attr_accessor :output
30
+ attr_accessor :threads
31
+ attr_accessor :mode
32
+ attr_accessor :bot_checks_every
33
+
34
+ VALIDATE_OPTIONS = [:duration, :output, :threads]
35
+
36
+ def initialize
37
+ @threads, @duration, @mode, @bot_checks_every = 1, 1.second, :local, 1.minute
38
+ end
39
+
40
+ def self.add_option(name)
41
+ attr_accessor name unless self.respond_to?(name)
42
+ end
43
+
44
+ def valid?
45
+ VALIDATE_OPTIONS.each{ |option| return false if send(option).nil? }
46
+ true
47
+ end
48
+ end
49
+
50
+ # Is returned if the configuration is not filled sufficiently
51
+ class InvalidOptions < StandardError
52
+ def message
53
+ "At least: #{Config::VALIDATE_OPTIONS.join(', ')} are required"
54
+ end
55
+ end
56
+
57
+ @config = Config.new
58
+
59
+ # Configures the benchmarks with a hash. If the config methods are not present yet,
60
+ # they are added to the config object
61
+ def self.configure=(config)
62
+ raise "Config must be a Hash" unless config.is_a?(Hash)
63
+ config.each { |option, value|
64
+ @config.class.add_option(option)
65
+ @config.send "#{option}=", value
66
+ }
67
+ end
68
+
69
+ # Returns the current config object
70
+ def self.config
71
+ @config
72
+ end
73
+
74
+ # Resets the config object
75
+ def self.reset!
76
+ @config = Config.new
77
+ end
78
+
79
+ end
80
+
81
+ # Configure the benchmark by supplying a hash of options like this:
82
+ #
83
+ # BigBench.configure = {
84
+ # :duration => 10.seconds,
85
+ # :output => "test.ljson",
86
+ # :threads => 20
87
+ # }
88
+ #
89
+ # Those values can then be set and retreived with <tt>BigBench.config.duration</tt>, ...
90
+ def self.configure=(config)
91
+ Configuration.configure=(config)
92
+ end
93
+
94
+ # Set and retreive the config values like this:
95
+ #
96
+ # BigBench.config.duration # => 10.seconds
97
+ # BigBench.config.duration = 20.minutes
98
+ #
99
+ def self.config
100
+ Configuration.config
101
+ end
102
+
103
+ # Checks if all necessary config options are set and raises an <tt>InvalidOptions</tt> exception if not
104
+ def self.check_config!
105
+ raise Configuration::InvalidOptions.new unless config.valid?
106
+ true
107
+ end
108
+
109
+ end