benchmark-http 0.8.2 → 0.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a12b67daeeadc34944c967a8f441da017cb3a31f3bb778893b344b3b24115d1
4
- data.tar.gz: efff4138d8be9145ab9df016162bce6bbf2da9e4fcfd36cebda36acc9601a773
3
+ metadata.gz: 8b3803e60e468cb173cbaf5df1556f95fc7dfe89531fb785530050875a5a32e1
4
+ data.tar.gz: a5c54afd2afb70743f6d589eaa784c593a5f78d96e59c87c996ef90a7aa968fb
5
5
  SHA512:
6
- metadata.gz: dd41f22b3e11709045bb9e63ab41a9069f9548c243ef1ab365e045eaf7f548ff0b88d03060404404e68c2484cfbc0dbfa4b2101f11764c5f70f0ad9a5197e110
7
- data.tar.gz: 59cce9e283b1ed06e49d34c7159ff2b883455b474b057c9b1c932427bb31e9b8421224288b1c9d5269da4da10271d922697a645c8df319393fa61c2204ba1bc3
6
+ metadata.gz: aff57e060c1239d34ef229f33c6141beefdea04970adf8608d119824cc512bcb5e994df5df3290023f03e1f3a3563184a8437b377ad01a26d1576718cfa45715
7
+ data.tar.gz: 78d67c5fd5dfdbe15306723711ea4b274278e9c694d287105f3b808d725b10ae500c64007f67497eddd655d4b8a8603c02395b99b1db23422fd725711e649209
@@ -18,6 +18,7 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require_relative 'command/latency'
21
22
  require_relative 'command/concurrency'
22
23
  require_relative 'command/spider'
23
24
 
@@ -41,6 +42,7 @@ module Benchmark
41
42
  end
42
43
 
43
44
  nested :command, {
45
+ 'latency' => Latency,
44
46
  'concurrency' => Concurrency,
45
47
  'spider' => Spider
46
48
  }
@@ -64,7 +64,7 @@ module Benchmark
64
64
  end
65
65
  end.each(&:wait)
66
66
 
67
- puts "I made #{statistics.size} requests in #{Seconds[statistics.sequential_duration]}. The per-request latency was #{Seconds[statistics.latency]}. That's #{statistics.per_second.round(2)} asynchronous requests/second."
67
+ puts "I made #{statistics.count} requests in #{Seconds[statistics.sequential_duration]}. The per-request latency was #{Seconds[statistics.latency]}. That's #{statistics.per_second.round(2)} asynchronous requests/second."
68
68
 
69
69
  puts "\t Variance: #{Seconds[statistics.variance]}"
70
70
  puts "\tStandard Deviation: #{Seconds[statistics.standard_deviation]}"
@@ -0,0 +1,94 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative '../seconds'
22
+ require_relative '../statistics'
23
+
24
+ require 'async'
25
+ require 'async/http/client'
26
+ require 'async/http/endpoint'
27
+
28
+ require 'samovar'
29
+
30
+ module Benchmark
31
+ module HTTP
32
+ module Command
33
+ class Latency < Samovar::Command
34
+ self.description = "Determine the optimal level of concurrency."
35
+
36
+ options do
37
+ option "-k/--concurrency <count>", "The number of simultaneous connections to make.", default: 1, type: Integer
38
+ option '-c/--confidence <factor>', "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
39
+ end
40
+
41
+ many :hosts, "One or more hosts to benchmark"
42
+
43
+ def confidence_factor
44
+ 1.0 - @options[:confidence]
45
+ end
46
+
47
+ def measure_performance(concurrency, endpoint, request_path)
48
+ puts "I am running #{concurrency} asynchronous tasks that will each make sequential requests..."
49
+
50
+ statistics = Statistics.new(concurrency)
51
+ task = Async::Task.current
52
+
53
+ concurrency.times.map do
54
+ task.async do
55
+ client = Async::HTTP::Client.new(endpoint, endpoint.protocol)
56
+
57
+ statistics.sample(confidence_factor) do
58
+ response = client.get(request_path).tap(&:finish)
59
+ end
60
+
61
+ client.close
62
+ end
63
+ end.each(&:wait)
64
+
65
+ puts "I made #{statistics.count} requests in #{Seconds[statistics.sequential_duration]}. The per-request latency was #{Seconds[statistics.latency]}. That's #{statistics.per_second} asynchronous requests/second."
66
+ puts "\t Variance: #{Seconds[statistics.variance]}"
67
+ puts "\tStandard Deviation: #{Seconds[statistics.standard_deviation]}"
68
+ puts "\t Standard Error: #{Seconds[statistics.standard_error]}"
69
+
70
+ return statistics
71
+ end
72
+
73
+ def run(url)
74
+ endpoint = Async::HTTP::Endpoint.parse(url)
75
+ request_path = endpoint.url.request_uri
76
+
77
+ puts "I am going to benchmark #{url}..."
78
+
79
+ Async::Reactor.run do |task|
80
+ statistics = []
81
+
82
+ base = measure_performance(@options[:concurrency], endpoint, request_path)
83
+ end
84
+ end
85
+
86
+ def call
87
+ @hosts.each do |host|
88
+ run(host).wait
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -144,7 +144,7 @@ module Benchmark
144
144
  private
145
145
 
146
146
  def confident?(factor)
147
- if @samples.size > @concurrency
147
+ if @samples.size > @concurrency * 10
148
148
  return self.standard_error < (self.average * factor)
149
149
  end
150
150
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Benchmark
22
22
  module HTTP
23
- VERSION = "0.8.2"
23
+ VERSION = "0.9.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -142,6 +142,7 @@ files:
142
142
  - lib/benchmark/http.rb
143
143
  - lib/benchmark/http/command.rb
144
144
  - lib/benchmark/http/command/concurrency.rb
145
+ - lib/benchmark/http/command/latency.rb
145
146
  - lib/benchmark/http/command/spider.rb
146
147
  - lib/benchmark/http/links_filter.rb
147
148
  - lib/benchmark/http/seconds.rb
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  - !ruby/object:Gem::Version
166
167
  version: '0'
167
168
  requirements: []
168
- rubygems_version: 3.0.6
169
+ rubygems_version: 3.0.4
169
170
  signing_key:
170
171
  specification_version: 4
171
172
  summary: An asynchronous benchmark toolbox for modern HTTP servers.