benchy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/benchy.rb +54 -40
- data/lib/benchy/version.rb +1 -1
- metadata +5 -5
data/lib/benchy.rb
CHANGED
@@ -23,7 +23,7 @@ module Benchy
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def workers
|
26
|
-
@workers ||= (0
|
26
|
+
@workers ||= (0..concurrency).map{|n| Worker.new(request, "worker.#{n}") }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -44,7 +44,7 @@ module Benchy
|
|
44
44
|
run
|
45
45
|
}
|
46
46
|
http.errback {
|
47
|
-
Benchy.logger.
|
47
|
+
Benchy.logger.error "#{name}\t| Connection error!"
|
48
48
|
halt # TODO - Make this fail the ping and try again, not halt
|
49
49
|
}
|
50
50
|
end
|
@@ -69,57 +69,71 @@ module Benchy
|
|
69
69
|
# Grab an instance of an Em::Http request so we can run it somewhere.
|
70
70
|
def em
|
71
71
|
EventMachine::HttpRequest.new(url).send(method.downcase,
|
72
|
-
:head =>
|
72
|
+
:head => headers,
|
73
73
|
:body => body,
|
74
74
|
:connect_timeout => 9000, # Disable
|
75
75
|
:inactivity_timeout => 9000 # Disable
|
76
76
|
)
|
77
77
|
end
|
78
|
-
|
79
|
-
# Setup smart default headers to minimize the chances that a request gets rejected.
|
80
|
-
def default_headers
|
81
|
-
default_headers = {}
|
82
|
-
default_headers['Content-Type'] = 'application/binary-octet' if body
|
83
|
-
default_headers['Accepts'] = '*/*'
|
84
|
-
default_headers
|
85
|
-
end
|
86
78
|
end
|
87
79
|
|
88
80
|
# Parse out some command line goodness
|
89
81
|
class CLI < Thor
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
82
|
+
%w[post put].each do |meth|
|
83
|
+
desc "#{meth} URL", "#{meth.upcase} to a URL"
|
84
|
+
method_option :body,
|
85
|
+
:type => :string,
|
86
|
+
:aliases => '-b',
|
87
|
+
:desc => "Request body"
|
88
|
+
method_option :headers,
|
89
|
+
:type => :hash,
|
90
|
+
:aliases => '-h',
|
91
|
+
:desc => 'Request headers',
|
92
|
+
:default => {
|
93
|
+
'Content-Type' => 'application/binary-octet',
|
94
|
+
'Accepts' => '*/*'
|
95
|
+
}
|
96
|
+
method_option :concurrency,
|
97
|
+
:type => :numeric,
|
98
|
+
:desc => "Concurrent requests",
|
99
|
+
:aliases => '-c',
|
100
|
+
:default => 1
|
101
|
+
define_method meth do |url|
|
102
|
+
request(url, meth, self.class.body(options))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
%w[get head delete].each do |meth|
|
107
|
+
desc "#{meth} URL", "#{meth.upcase} to a URL"
|
108
|
+
method_option :headers,
|
109
|
+
:type => :hash,
|
110
|
+
:aliases => '-h',
|
111
|
+
:desc => 'Request headers',
|
112
|
+
:default => {
|
113
|
+
'Content-Type' => 'application/binary-octet',
|
114
|
+
'Accepts' => '*/*'
|
115
|
+
}
|
116
|
+
method_option :concurrency,
|
117
|
+
:type => :numeric,
|
118
|
+
:desc => "Concurrent requests",
|
119
|
+
:aliases => '-c',
|
120
|
+
:default => 1
|
121
|
+
define_method meth do |url|
|
122
|
+
request(url, meth)
|
123
|
+
end
|
117
124
|
end
|
118
125
|
|
119
126
|
private
|
120
|
-
|
127
|
+
def request(url, method=:get, body=nil)
|
128
|
+
req = Request.new(url, method, options[:headers], body)
|
129
|
+
EM.run {
|
130
|
+
Dispatcher.new(req, options[:concurrency]).run
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
# Normalize the request body if its specified from the CLI or if its piped in from terminal
|
121
135
|
def self.body(options)
|
122
|
-
options[:
|
136
|
+
options[:body] || (STDIN.read unless STDIN.tty?)
|
123
137
|
end
|
124
138
|
end
|
125
139
|
end
|
data/lib/benchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: em-http-request
|
16
|
-
requirement: &
|
16
|
+
requirement: &70157971397720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70157971397720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thor
|
27
|
-
requirement: &
|
27
|
+
requirement: &70157971397300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70157971397300
|
36
36
|
description: A dirty-simple HTTP benchmarking application
|
37
37
|
email:
|
38
38
|
- brad@bradgessler.com
|