ramaze 2011.01.30 → 2011.07.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
data/benchmark/results.txt
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
====== simple ======
|
2
|
-
<code ruby>
|
3
|
-
require 'ramaze'
|
4
|
-
|
5
|
-
class MainController < Ramaze::Controller
|
6
|
-
def index
|
7
|
-
"Hello, World!"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
</code>
|
11
|
-
|
12
|
-
=== webrick ===
|
13
|
-
Mem usage before: 20.32MB
|
14
|
-
Time taken for tests: 7.747022 seconds
|
15
|
-
Failed requests: 0
|
16
|
-
Requests per second: 129.08 [#/sec] (mean)
|
17
|
-
Time per request: 77.470 [ms] (mean)
|
18
|
-
Time per request: 7.747 [ms] (mean, across all concurrent requests)
|
19
|
-
Mem usage after: 25.43MB
|
20
|
-
|
21
|
-
=== mongrel ===
|
22
|
-
Mem usage before: 20.25MB
|
23
|
-
Time taken for tests: 2.205161 seconds
|
24
|
-
Failed requests: 0
|
25
|
-
Requests per second: 453.48 [#/sec] (mean)
|
26
|
-
Time per request: 22.052 [ms] (mean)
|
27
|
-
Time per request: 2.205 [ms] (mean, across all concurrent requests)
|
28
|
-
Mem usage after: 21.91MB
|
29
|
-
|
30
|
-
=== evented_mongrel ===
|
31
|
-
Mem usage before: 22.64MB
|
32
|
-
Time taken for tests: 1.311583 seconds
|
33
|
-
Failed requests: 0
|
34
|
-
Requests per second: 762.44 [#/sec] (mean)
|
35
|
-
Time per request: 13.116 [ms] (mean)
|
36
|
-
Time per request: 1.312 [ms] (mean, across all concurrent requests)
|
37
|
-
Mem usage after: 27.03MB
|
38
|
-
|
39
|
-
====== no_template ======
|
40
|
-
<code ruby>
|
41
|
-
require 'ramaze'
|
42
|
-
|
43
|
-
class MainController < Ramaze::Controller
|
44
|
-
engine :None
|
45
|
-
|
46
|
-
def index
|
47
|
-
"Hello, World!"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
</code>
|
51
|
-
|
52
|
-
=== evented_mongrel ===
|
53
|
-
Mem usage before: 22.63MB
|
54
|
-
Time taken for tests: 1.151947 seconds
|
55
|
-
Failed requests: 0
|
56
|
-
Requests per second: 868.10 [#/sec] (mean)
|
57
|
-
Time per request: 11.519 [ms] (mean)
|
58
|
-
Time per request: 1.152 [ms] (mean, across all concurrent requests)
|
59
|
-
Mem usage after: 27.11MB
|
60
|
-
|
61
|
-
====== no_informer ======
|
62
|
-
<code ruby>
|
63
|
-
require 'ramaze'
|
64
|
-
|
65
|
-
class MainController < Ramaze::Controller
|
66
|
-
def index
|
67
|
-
"Hello, World!"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
Ramaze::Inform.loggers = []
|
72
|
-
</code>
|
73
|
-
|
74
|
-
=== evented_mongrel ===
|
75
|
-
Mem usage before: 22.63MB
|
76
|
-
Time taken for tests: 1.202878 seconds
|
77
|
-
Failed requests: 0
|
78
|
-
Requests per second: 831.34 [#/sec] (mean)
|
79
|
-
Time per request: 12.029 [ms] (mean)
|
80
|
-
Time per request: 1.203 [ms] (mean, across all concurrent requests)
|
81
|
-
Mem usage after: 27.07MB
|
82
|
-
|
83
|
-
====== no_sessions ======
|
84
|
-
<code ruby>
|
85
|
-
require 'ramaze'
|
86
|
-
|
87
|
-
class MainController < Ramaze::Controller
|
88
|
-
def index
|
89
|
-
"Hello, World!"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
Ramaze::Inform.loggers = []
|
94
|
-
Ramaze::Global.sessions = false
|
95
|
-
</code>
|
96
|
-
|
97
|
-
=== evented_mongrel ===
|
98
|
-
Mem usage before: 22.63MB
|
99
|
-
Time taken for tests: 0.835254 seconds
|
100
|
-
Failed requests: 0
|
101
|
-
Requests per second: 1197.24 [#/sec] (mean)
|
102
|
-
Time per request: 8.353 [ms] (mean)
|
103
|
-
Time per request: 0.835 [ms] (mean, across all concurrent requests)
|
104
|
-
Mem usage after: 26.38MB
|
105
|
-
|
106
|
-
====== minimal ======
|
107
|
-
<code ruby>
|
108
|
-
require 'ramaze'
|
109
|
-
|
110
|
-
class MainController < Ramaze::Controller
|
111
|
-
engine :None
|
112
|
-
|
113
|
-
def index
|
114
|
-
"Hello, World!"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
Ramaze::Global.sourcereload = false
|
119
|
-
Ramaze::Global.sessions = false
|
120
|
-
Ramaze::Inform.loggers = []
|
121
|
-
</code>
|
122
|
-
|
123
|
-
=== evented_mongrel ===
|
124
|
-
Mem usage before: 22.62MB
|
125
|
-
Time taken for tests: 0.647273 seconds
|
126
|
-
Failed requests: 0
|
127
|
-
Requests per second: 1544.94 [#/sec] (mean)
|
128
|
-
Time per request: 6.473 [ms] (mean)
|
129
|
-
Time per request: 0.647 [ms] (mean, across all concurrent requests)
|
130
|
-
Mem usage after: 26.42MB
|
131
|
-
|
data/benchmark/run.rb
DELETED
@@ -1,355 +0,0 @@
|
|
1
|
-
require "optparse"
|
2
|
-
require "timeout"
|
3
|
-
require "net/http"
|
4
|
-
|
5
|
-
class String
|
6
|
-
def /(o) File.join(self, o.to_s) end
|
7
|
-
end
|
8
|
-
|
9
|
-
class RamazeBenchmark
|
10
|
-
|
11
|
-
class BasicWriter
|
12
|
-
def initialize
|
13
|
-
@ljust = 24
|
14
|
-
end
|
15
|
-
|
16
|
-
def write(key, val)
|
17
|
-
if key == "Name"
|
18
|
-
puts "====== #{val} ======"
|
19
|
-
else
|
20
|
-
puts((key.to_s + ":").ljust(@ljust) + val.to_s)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def flush
|
25
|
-
puts
|
26
|
-
$stdout.flush
|
27
|
-
end
|
28
|
-
|
29
|
-
def close; end
|
30
|
-
end
|
31
|
-
|
32
|
-
class CSVWriter
|
33
|
-
def initialize
|
34
|
-
@keys, @vals = [], []
|
35
|
-
end
|
36
|
-
|
37
|
-
def write(key, val)
|
38
|
-
@keys << key
|
39
|
-
@vals << (val =~ /^\d[\d.]+/ ? $& : val)
|
40
|
-
end
|
41
|
-
|
42
|
-
def flush
|
43
|
-
unless @header
|
44
|
-
puts FasterCSV.generate{|csv| csv << @keys }
|
45
|
-
@header = true
|
46
|
-
end
|
47
|
-
|
48
|
-
puts FasterCSV.generate{|csv| csv << @vals }
|
49
|
-
@keys, @vals = [], []
|
50
|
-
end
|
51
|
-
|
52
|
-
def close; end
|
53
|
-
end
|
54
|
-
|
55
|
-
class GruffWriter
|
56
|
-
RPS = "Requests per second"
|
57
|
-
|
58
|
-
def initialize
|
59
|
-
@benchmarks = {}
|
60
|
-
@order = []
|
61
|
-
end
|
62
|
-
|
63
|
-
def write(key, val)
|
64
|
-
@benchmark ||= {}
|
65
|
-
@benchmark[key] = (val =~ /^\d[\d.]+/ ? $&.to_f : val)
|
66
|
-
end
|
67
|
-
|
68
|
-
def flush
|
69
|
-
if @benchmark["Requests per second"]
|
70
|
-
name = @benchmark["Name"]
|
71
|
-
@benchmarks[name] ||= []
|
72
|
-
@benchmarks[name] << @benchmark
|
73
|
-
@order << name unless @order.include?(name)
|
74
|
-
end
|
75
|
-
@benchmark = nil
|
76
|
-
end
|
77
|
-
|
78
|
-
def close
|
79
|
-
g = Gruff::SideBar.new(800)
|
80
|
-
g.title = "Ramaze Benchmark"
|
81
|
-
setup_gruff_data(g)
|
82
|
-
g.labels = gruff_labels
|
83
|
-
g.sort = false
|
84
|
-
g.hide_legend = true if graph_type == :simple
|
85
|
-
g.x_axis_label = "requests/sec"
|
86
|
-
g.minimum_value = 0
|
87
|
-
g.write
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
def gruff_labels
|
93
|
-
table = {}
|
94
|
-
@order.each_with_index do |bname, idx|
|
95
|
-
table[idx] = bname
|
96
|
-
end
|
97
|
-
return table
|
98
|
-
end
|
99
|
-
|
100
|
-
def adapters
|
101
|
-
@benchmarks.to_a[0][1].map{|bm| bm["Adapter"]}.uniq
|
102
|
-
end
|
103
|
-
|
104
|
-
def paths
|
105
|
-
@benchmarks.to_a[0][1].map{|bm| bm["Path"]}.uniq
|
106
|
-
end
|
107
|
-
|
108
|
-
def graph_type
|
109
|
-
case [adapters.size > 1, paths.size > 1]
|
110
|
-
when [true , true ]; :both
|
111
|
-
when [true , false]; :adapter
|
112
|
-
when [false, true ]; :path
|
113
|
-
else :simple; end
|
114
|
-
end
|
115
|
-
|
116
|
-
def setup_gruff_data(g)
|
117
|
-
case graph_type
|
118
|
-
when :simple
|
119
|
-
g.data("", @order.map{|name| @benchmarks[name][0][RPS] }, '#6886B4')
|
120
|
-
when :adapter
|
121
|
-
adapters.each do |adapter|
|
122
|
-
g.data(adapter, @order.map{|name|
|
123
|
-
@benchmarks[name].find{|bm| bm["Adapter"] == adapter}[RPS]
|
124
|
-
})
|
125
|
-
end
|
126
|
-
when :path
|
127
|
-
paths.each do |path|
|
128
|
-
g.data(path, @order.map{|name|
|
129
|
-
@benchmarks[name].find{|bm| bm["Path"] == path}[RPS]
|
130
|
-
})
|
131
|
-
end
|
132
|
-
when :both
|
133
|
-
adapters.each do |adapter|
|
134
|
-
paths.each do |path|
|
135
|
-
g.data("#{adapter}, #{path}", @order.map{|name|
|
136
|
-
@benchmarks[name].find{|bm|
|
137
|
-
bm["Adapter"] == adapter && bm["Path"] == path
|
138
|
-
}[RPS]
|
139
|
-
})
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
attr_accessor :requests, :adapters, :port, :log, :display_code, :target
|
147
|
-
attr_accessor :concurrent, :paths, :benchmarker, :informer
|
148
|
-
attr_accessor :mode, :show_log, :formats
|
149
|
-
|
150
|
-
def initialize()
|
151
|
-
@adapters = [:webrick]
|
152
|
-
@port = rand(32768-1)+32768
|
153
|
-
@requests = 100
|
154
|
-
@concurrent = 10
|
155
|
-
@signal = 'SIGKILL'
|
156
|
-
@host = "127.0.0.1"
|
157
|
-
@paths = ["/"]
|
158
|
-
@target = /.+/
|
159
|
-
@informer = true
|
160
|
-
@formats = ["text"]
|
161
|
-
@writers = []
|
162
|
-
@mode = :live
|
163
|
-
yield self
|
164
|
-
end
|
165
|
-
|
166
|
-
def start
|
167
|
-
# setup writers
|
168
|
-
@formats.each do |format|
|
169
|
-
case format
|
170
|
-
when "csv" ; @writers << CSVWriter.new
|
171
|
-
when "gruff"; @writers << GruffWriter.new
|
172
|
-
when "text" ; @writers << BasicWriter.new
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
# benchmarks
|
177
|
-
glob = File.expand_path('../suite/*.rb', __FILE__)
|
178
|
-
Dir.glob(glob) do |filename|
|
179
|
-
@adapters.each do |adapter|
|
180
|
-
@paths.each do |path|
|
181
|
-
benchmark(filename, adapter, path) if @target.match(filename)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# close writers
|
187
|
-
@writers.each do |writer|
|
188
|
-
writer.close
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
# start to measure
|
193
|
-
def benchmark(filename, adapter, path)
|
194
|
-
# output informations
|
195
|
-
l :Name, filename.scan(/\/([^\/]+)\.rb/).to_s
|
196
|
-
l :Adapter, adapter
|
197
|
-
l :Requests, @requests
|
198
|
-
l :Concurrent, @concurrent
|
199
|
-
l :Path, path
|
200
|
-
l :Informer, @informer
|
201
|
-
if @display_code
|
202
|
-
l :Code, "<code ruby>\n#{File.read(filename)}\n</code>\n\n"
|
203
|
-
end
|
204
|
-
|
205
|
-
# real benchmark
|
206
|
-
ramaze(filename, adapter) do |pid|
|
207
|
-
l "Mem usage before", "#{memsize(pid)}MB"
|
208
|
-
ab(path).each do |line|
|
209
|
-
l *line.split(/:\s*/)
|
210
|
-
end
|
211
|
-
l "Mem usage after", "#{memsize(pid)}MB"
|
212
|
-
end
|
213
|
-
|
214
|
-
# flush writers
|
215
|
-
@writers.each do |writer|
|
216
|
-
writer.flush
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
private
|
221
|
-
|
222
|
-
# memory usage size
|
223
|
-
def memsize(pid)
|
224
|
-
(`ps -p #{pid} -o rss=`.strip.to_f/10.24).round/100.0
|
225
|
-
end
|
226
|
-
|
227
|
-
# output
|
228
|
-
def l(key, val)
|
229
|
-
@writers.each do |writer|
|
230
|
-
writer.write(key.to_s, val)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
# url of ramaze server
|
235
|
-
def url(path)
|
236
|
-
"http://#{@host}:#{@port}#{path}"
|
237
|
-
end
|
238
|
-
|
239
|
-
# apache benchmark
|
240
|
-
def ab(path)
|
241
|
-
re = /^(Fail|Req|Time|Total transferred|Document Length|Transfer rate)/
|
242
|
-
`ab -c #{@concurrent} -n #{@requests} #{url(path)}`.split("\n").grep(re)
|
243
|
-
end
|
244
|
-
|
245
|
-
# startup
|
246
|
-
def ramaze(filename, adapter)
|
247
|
-
pid = fork do
|
248
|
-
begin
|
249
|
-
require 'ramaze'
|
250
|
-
Ramaze.options.mode = @mode
|
251
|
-
if @informer
|
252
|
-
unless @show_log
|
253
|
-
require 'ramaze/log/informer'
|
254
|
-
Ramaze::Log.loggers = [Ramaze::Logger::Informer.new("/dev/null")]
|
255
|
-
end
|
256
|
-
else
|
257
|
-
Ramaze::Log.loggers = []
|
258
|
-
end
|
259
|
-
require filename
|
260
|
-
Ramaze.start :adapter => adapter, :port => @port
|
261
|
-
rescue LoadError => ex; l :Error, ex; end
|
262
|
-
end
|
263
|
-
|
264
|
-
yield pid if wait_to_startup
|
265
|
-
|
266
|
-
Process.kill(@signal, pid)
|
267
|
-
Process.waitpid2(pid)
|
268
|
-
end
|
269
|
-
|
270
|
-
# wait for ramaze to start up
|
271
|
-
def wait_to_startup
|
272
|
-
begin
|
273
|
-
Timeout.timeout(5) do
|
274
|
-
loop do
|
275
|
-
begin
|
276
|
-
sleep 1; Net::HTTP.new(@host, @port).head("/"); return true
|
277
|
-
rescue Errno::ECONNREFUSED; end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
rescue Timeout::Error
|
281
|
-
l "Error", "failed to start benchmark script"; return false
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
Signal.trap(:INT, proc{exit})
|
287
|
-
|
288
|
-
RamazeBenchmark.new do |bm|
|
289
|
-
OptionParser.new(false, 24, " ") do |opt|
|
290
|
-
opt.on('-a', '--adapters NAMES', '[webrick] Specify adapters') do |adapters|
|
291
|
-
bm.adapters = adapters.split(",")
|
292
|
-
end
|
293
|
-
|
294
|
-
opt.on('--formats (text|csv|gruff)', '[text] Specify output formats') do |formats|
|
295
|
-
bm.formats = formats.split(",")
|
296
|
-
bm.formats.each do |format|
|
297
|
-
case format
|
298
|
-
when "csv" ; require "fastercsv"
|
299
|
-
when "gruff"; require "gruff"
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
opt.on('-n', '--requests NUM', '[100] Number of requests') do |n|
|
305
|
-
bm.requests = n
|
306
|
-
end
|
307
|
-
|
308
|
-
opt.on('-c', '--concurrent NUM', '[10] Number of multiple requests') do |n|
|
309
|
-
bm.concurrent = n
|
310
|
-
end
|
311
|
-
|
312
|
-
opt.on('--code', 'Display benchmark code') do |n|
|
313
|
-
bm.display_code = true
|
314
|
-
end
|
315
|
-
|
316
|
-
opt.on('-p', '--port NUM',
|
317
|
-
'[random(32768-65535)] Specify port number') do |n|
|
318
|
-
bm.port = n
|
319
|
-
end
|
320
|
-
|
321
|
-
opt.on('--paths PATHS', '[/] Specify request paths') do |paths|
|
322
|
-
bm.paths = paths.split(",")
|
323
|
-
end
|
324
|
-
|
325
|
-
opt.on('--mode MODE', '[live] Ramaze mode') do |mode|
|
326
|
-
bm.mode = mode.to_sym
|
327
|
-
end
|
328
|
-
|
329
|
-
opt.on('--no-informer', 'Disable informer') do
|
330
|
-
bm.informer = false
|
331
|
-
end
|
332
|
-
|
333
|
-
opt.on('--show-log', 'Show log') do
|
334
|
-
bm.show_log = true
|
335
|
-
end
|
336
|
-
|
337
|
-
opt.on('--target REGEXP',
|
338
|
-
'[/.+/] Specify benchmark scripts to measure') do |name|
|
339
|
-
bm.target = Regexp.compile(name)
|
340
|
-
end
|
341
|
-
|
342
|
-
opt.on('-h', '--help', 'Show this message') do
|
343
|
-
puts opt.help
|
344
|
-
exit
|
345
|
-
end
|
346
|
-
|
347
|
-
begin
|
348
|
-
opt.parse!(ARGV)
|
349
|
-
rescue OptionParser::ParseError => ex
|
350
|
-
puts "[ERROR] " + ex
|
351
|
-
puts opt.help
|
352
|
-
exit
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end.start
|