benchmark-http 0.11.1 → 0.12.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
  SHA256:
3
- metadata.gz: 1ef251d13a8e0a6c8966d03056203fb57b465f5a110f602fabd208232f06cd69
4
- data.tar.gz: fabf1b8be4f2f21a74dd8a626c9a2d1d99bed5e6eb6161b49ae629c19b24790e
3
+ metadata.gz: 7a4514dcedbb45217da34b36865cee691f89a314f36e22627f940d6660360a46
4
+ data.tar.gz: cc3f73eb0f546ed85abc38ebbe39ad610b0ce6f7d863c4db00e5b0e8cd6346ae
5
5
  SHA512:
6
- metadata.gz: 8c61036734fbd5642c63ced591f049d77cf37a6849953f80150000b2c3d318d5a700d90ccc238d23793700dc27909a1dc37ed01e7d1924af6ebca8e0d931f984
7
- data.tar.gz: a8a0ae66402b1bf147bcab1af6ab2a73d7cf0654ea345466ec9baa972ccc87cbe6a7c5d426869e334de92f31cefbe07fdf1a41b67aea6df42b174a2d47add62a
6
+ metadata.gz: 56df6b4986db26a1af4e7d5aecfa2f2c71f2140c3139af40903652412b2218a54858503dd67017e97d37a61f132b82c955484dd09fea7f2b4e12ede73b6f0d5f
7
+ data.tar.gz: aad17d6df1aa2932484089742f1e0605f9f4bbff09a92717892addf82be72834953c664a22fdeb6b1a69114d2c28d8fff2bf185ddcb3cbaf02d644cfbfa0e46a
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ Gemfile.lock
@@ -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
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Benchmark
22
22
  module HTTP
23
- VERSION = "0.11.1"
23
+ VERSION = "0.12.0"
24
24
  end
25
25
  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.11.1
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-10 00:00:00.000000000 Z
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