benchmark-http 0.11.1 → 0.12.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 +4 -4
- data/.gitignore +2 -0
- data/lib/benchmark/http/command.rb +3 -1
- data/lib/benchmark/http/command/hammer.rb +104 -0
- data/lib/benchmark/http/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a4514dcedbb45217da34b36865cee691f89a314f36e22627f940d6660360a46
|
4
|
+
data.tar.gz: cc3f73eb0f546ed85abc38ebbe39ad610b0ce6f7d863c4db00e5b0e8cd6346ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56df6b4986db26a1af4e7d5aecfa2f2c71f2140c3139af40903652412b2218a54858503dd67017e97d37a61f132b82c955484dd09fea7f2b4e12ede73b6f0d5f
|
7
|
+
data.tar.gz: aad17d6df1aa2932484089742f1e0605f9f4bbff09a92717892addf82be72834953c664a22fdeb6b1a69114d2c28d8fff2bf185ddcb3cbaf02d644cfbfa0e46a
|
data/.gitignore
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require_relative 'command/latency'
|
22
22
|
require_relative 'command/concurrency'
|
23
23
|
require_relative 'command/spider'
|
24
|
+
require_relative 'command/hammer'
|
24
25
|
|
25
26
|
require_relative 'version'
|
26
27
|
require 'samovar'
|
@@ -44,7 +45,8 @@ module Benchmark
|
|
44
45
|
nested :command, {
|
45
46
|
'latency' => Latency,
|
46
47
|
'concurrency' => Concurrency,
|
47
|
-
'spider' => Spider
|
48
|
+
'spider' => Spider,
|
49
|
+
'hammer' => Hammer,
|
48
50
|
}
|
49
51
|
|
50
52
|
def verbose?
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Copyright, 2020, 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 Hammer < Samovar::Command
|
34
|
+
self.description = "Hammer a single URL and report statistics."
|
35
|
+
|
36
|
+
options do
|
37
|
+
option "-k/--concurrency <count>", "The number of simultaneous connections to make.", default: 1, type: Integer
|
38
|
+
option '-c/--count <integer>', "The number of requests to make per connection.", default: 10_000, type: Integer
|
39
|
+
end
|
40
|
+
|
41
|
+
many :urls, "The urls to hammer."
|
42
|
+
|
43
|
+
def measure_performance(concurrency, count, endpoint, request_path)
|
44
|
+
puts "I am running #{concurrency} asynchronous tasks that will each make #{count} sequential requests..."
|
45
|
+
|
46
|
+
statistics = Statistics.new(concurrency)
|
47
|
+
task = Async::Task.current
|
48
|
+
running = true
|
49
|
+
|
50
|
+
progress_task = task.async do |child|
|
51
|
+
while true
|
52
|
+
child.sleep(1)
|
53
|
+
statistics.print
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
concurrency.times.map do
|
58
|
+
task.async do
|
59
|
+
client = Async::HTTP::Client.new(endpoint, endpoint.protocol)
|
60
|
+
|
61
|
+
count.times do |i|
|
62
|
+
statistics.measure do
|
63
|
+
response = client.get(request_path).tap(&:finish)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
client.close
|
68
|
+
end
|
69
|
+
end.each(&:wait)
|
70
|
+
|
71
|
+
progress_task&.stop
|
72
|
+
|
73
|
+
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."
|
74
|
+
puts "\t Variance: #{Seconds[statistics.variance]}"
|
75
|
+
puts "\tStandard Deviation: #{Seconds[statistics.standard_deviation]}"
|
76
|
+
puts "\t Standard Error: #{Seconds[statistics.standard_error]}"
|
77
|
+
|
78
|
+
statistics.print
|
79
|
+
|
80
|
+
return statistics
|
81
|
+
end
|
82
|
+
|
83
|
+
def run(url)
|
84
|
+
endpoint = Async::HTTP::Endpoint.parse(url)
|
85
|
+
request_path = endpoint.url.request_uri
|
86
|
+
|
87
|
+
puts "I am going to benchmark #{url}..."
|
88
|
+
|
89
|
+
Async::Reactor.run do |task|
|
90
|
+
statistics = []
|
91
|
+
|
92
|
+
base = measure_performance(@options[:concurrency], @options[:count], endpoint, request_path)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def call
|
97
|
+
@urls.each do |url|
|
98
|
+
run(url).wait
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benchmark-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-io
|
@@ -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/hammer.rb
|
145
146
|
- lib/benchmark/http/command/latency.rb
|
146
147
|
- lib/benchmark/http/command/spider.rb
|
147
148
|
- lib/benchmark/http/links_filter.rb
|