celluloid-benchmark 0.1.15 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71cb69d5a66e3aeacbd81a69142f21648673825b
4
- data.tar.gz: 26a007aa1629f007232cbd7636d9190889f60309
3
+ metadata.gz: e9c3d7d1944efb1aaf1bad886c4b908e85091c60
4
+ data.tar.gz: e279f4774b8790d66c6acde77963cb8e7865e53b
5
5
  SHA512:
6
- metadata.gz: 6b02c99bcecb85c1e75d1fd2bcc7eff510810ad2fa68ad669667dba0c7aeabb47df21a0fe46dbb1390401789093295896ed93e5e94a80f096d60cc496c720d9b
7
- data.tar.gz: dbb9384a8381484855ba11e47af41b917aef8d4ba8374507454b11495695d200c686afa3f012f25ca5713e90e35a6c015bd697fd082501ee1a72b664c64ce63b
6
+ metadata.gz: 80245cd323174a52cdeb6f6cd71ade1fd02491793086b76fb0eb4608781ea5c415bf74fa8171b7ac9fcf8b0e34bbc6fc19779d0288dff493b51dac5d1c93d266
7
+ data.tar.gz: 35c665225dc623b5eecc11d19b7f8fecba92d3b23cb1849da98e89cfbbce884d83cf0f7e13c71affc048565a4d1ff86891c7ede5a59f5ebb980f3203b7ee1d05
@@ -16,13 +16,15 @@ require_relative "../lib/celluloid_benchmark/visitor"
16
16
 
17
17
  benchmark_run = CelluloidBenchmark::Runner.run opts.to_hash
18
18
 
19
- p benchmark_run
20
- puts
21
- p "#{benchmark_run.requests / benchmark_run.elapsed_time} requests per second. #{benchmark_run.requests} requests in #{benchmark_run.elapsed_time} seconds by #{benchmark_run.visitors} visitors."
22
-
23
19
  puts
24
20
  benchmark_run.benchmarks.each do |trans|
25
21
  puts "#{trans.ok? ? '[ OK ]' : '[FAIL]'} #{trans.label}"
26
22
  end
27
23
 
28
- exit benchmark_run.ok?
24
+ puts
25
+ p "#{benchmark_run.requests / benchmark_run.elapsed_time} requests per second. #{benchmark_run.requests} requests in #{benchmark_run.elapsed_time} seconds by #{benchmark_run.visitors} visitors. Network time: #{benchmark_run.network_time}"
26
+
27
+ puts
28
+ p benchmark_run
29
+
30
+ exit benchmark_run.ok?
@@ -40,9 +40,6 @@ module CelluloidBenchmark
40
40
  response_codes.all? { |code| code == 200 || code == 201 || code == 302 || code == 304 || code == 401 }
41
41
  end
42
42
 
43
-
44
- private
45
-
46
43
  def average_response_time
47
44
  response_times.reduce(:+) / response_times.size
48
45
  end
@@ -24,20 +24,24 @@ module CelluloidBenchmark
24
24
  @thresholds = Hash.new
25
25
  end
26
26
 
27
- def log(http_status_code, start_time, end_time, label, threshold)
28
- time = 0
29
- if start_time && end_time
30
- time = end_time - start_time
31
- end
32
-
33
- response_times[label] << time
27
+ def log(http_status_code, start_time, end_time, server_response_time, label, threshold)
34
28
  response_codes[label] << http_status_code.to_i
35
29
 
30
+ network_and_server_time = network_and_server_time(start_time, end_time)
31
+
32
+ if server_response_time
33
+ response_times[label] << server_response_time
34
+ network_times[label] << network_and_server_time - server_response_time
35
+ else
36
+ response_times[label] << network_and_server_time
37
+ network_times[label] << network_and_server_time
38
+ end
39
+
36
40
  if threshold
37
41
  thresholds[label] = threshold
38
42
  end
39
43
 
40
- logger.info "#{http_status_code} #{time} #{label}"
44
+ logger.info "#{http_status_code} #{network_and_server_time} #{label}"
41
45
  end
42
46
 
43
47
  def response_times
@@ -52,6 +56,15 @@ module CelluloidBenchmark
52
56
  response_times.values.compact.map(&:size).reduce(0, &:+)
53
57
  end
54
58
 
59
+ def network_times
60
+ @network_times ||= Hash.new { |hash, value| hash[value] = [] }
61
+ end
62
+
63
+ def network_time
64
+ requests = network_times.values.flatten
65
+ requests.reduce(:+) / requests.size
66
+ end
67
+
55
68
  def benchmarks
56
69
  response_times.map do |label, response_times|
57
70
  CelluloidBenchmark::Benchmark.new label, thresholds[label], response_times, response_codes[label]
@@ -83,5 +96,16 @@ module CelluloidBenchmark
83
96
  "#{label} #{response_times.reduce(:+) / response_times.size} #{response_times.min} #{response_times.max} #{response_times.size}"
84
97
  end
85
98
  end
99
+
100
+
101
+ private
102
+
103
+ def network_and_server_time(start_time, end_time)
104
+ if start_time && end_time
105
+ end_time - start_time
106
+ else
107
+ 0
108
+ end
109
+ end
86
110
  end
87
111
  end
@@ -1,3 +1,3 @@
1
1
  module CelluloidBenchmark
2
- VERSION = "0.1.15"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,6 +2,7 @@ require "mechanize"
2
2
  require "multi_json"
3
3
  require "logger"
4
4
  require_relative "data_sources"
5
+ require_relative "visitors/http_methods"
5
6
 
6
7
  module CelluloidBenchmark
7
8
  # Actor that models a person using a web browser. Runs a test scenario. Delegates web browsing to
@@ -9,10 +10,11 @@ module CelluloidBenchmark
9
10
  class Visitor
10
11
  include Celluloid
11
12
  include CelluloidBenchmark::DataSources
13
+ include CelluloidBenchmark::Visitors::HTTPMethods
12
14
 
13
15
  extend Forwardable
14
16
 
15
- def_delegators :@browser, :add_auth, :get, :post, :put, :submit, :transact
17
+ def_delegators :@browser, :add_auth, :submit, :transact
16
18
 
17
19
  attr_reader :benchmark_run
18
20
  attr_accessor :browser
@@ -77,26 +79,6 @@ module CelluloidBenchmark
77
79
  end
78
80
  end
79
81
 
80
- def get_json(uri, headers = {})
81
- get uri, [], nil, headers.merge("Accept" => "application/json, text/javascript, */*; q=0.01")
82
- end
83
-
84
- def post_json(uri, query, headers = {})
85
- post(
86
- uri,
87
- MultiJson.dump(query),
88
- { "Content-Type" => "application/json", "Accept" => "application/json, text/javascript, */*; q=0.01" }.merge(headers)
89
- )
90
- end
91
-
92
- def put_json(uri, query, headers = {})
93
- put(
94
- uri,
95
- MultiJson.dump(query),
96
- { "Content-Type" => "application/json", "Accept" => "application/json, text/javascript, */*; q=0.01" }.merge(headers)
97
- )
98
- end
99
-
100
82
 
101
83
  private
102
84
 
@@ -107,7 +89,25 @@ module CelluloidBenchmark
107
89
 
108
90
  browser.post_connect_hooks << proc do |agent, uri, response, body|
109
91
  self.request_end_time = Time.now
110
- benchmark_run.async.log response.code, request_start_time, request_end_time, current_request_label, current_request_threshold
92
+ end
93
+ end
94
+
95
+ def server_response_time(page)
96
+ if page && page["x-runtime"]
97
+ page["x-runtime"].to_f
98
+ end
99
+ end
100
+
101
+ def log_response(page)
102
+ if benchmark_run
103
+ benchmark_run.async.log(
104
+ page.code,
105
+ request_start_time,
106
+ request_end_time,
107
+ server_response_time(page),
108
+ current_request_label,
109
+ current_request_threshold
110
+ )
111
111
  end
112
112
  end
113
113
 
@@ -0,0 +1,43 @@
1
+ module CelluloidBenchmark
2
+ module Visitors
3
+ module HTTPMethods
4
+ def get(uri, parameters = [], referer = nil, headers = {})
5
+ page = browser.get(uri, parameters, referer, headers)
6
+ log_response page
7
+ page
8
+ end
9
+
10
+ def post(uri, query = {}, headers = {})
11
+ page = browser.post(uri, query, headers)
12
+ log_response page
13
+ page
14
+ end
15
+
16
+ def put(uri, entity, headers = {})
17
+ page = browser.put(uri, entity, headers)
18
+ log_response page
19
+ page
20
+ end
21
+
22
+ def get_json(uri, headers = {})
23
+ get uri, [], nil, headers.merge("Accept" => "application/json, text/javascript, */*; q=0.01")
24
+ end
25
+
26
+ def post_json(uri, query, headers = {})
27
+ post(
28
+ uri,
29
+ MultiJson.dump(query),
30
+ { "Content-Type" => "application/json", "Accept" => "application/json, text/javascript, */*; q=0.01" }.merge(headers)
31
+ )
32
+ end
33
+
34
+ def put_json(uri, query, headers = {})
35
+ put(
36
+ uri,
37
+ MultiJson.dump(query),
38
+ { "Content-Type" => "application/json", "Accept" => "application/json, text/javascript, */*; q=0.01" }.merge(headers)
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid-benchmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Willson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-28 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -116,6 +116,7 @@ files:
116
116
  - lib/celluloid_benchmark/version.rb
117
117
  - lib/celluloid_benchmark/visitor.rb
118
118
  - lib/celluloid_benchmark/visitor_group.rb
119
+ - lib/celluloid_benchmark/visitors/http_methods.rb
119
120
  homepage: https://github.com/scottwillson/celluloid-benchmark
120
121
  licenses:
121
122
  - MIT
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements: []
138
139
  rubyforge_project:
139
- rubygems_version: 2.4.5
140
+ rubygems_version: 2.4.6
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Pure Ruby, realistic, website load test tool