Skip to content

Commit

Permalink
Modernize code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 17, 2024
1 parent 4285829 commit f50ff87
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 128 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/documentation-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Documentation Coverage

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm
COVERAGE: PartialSummary

jobs:
validate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- name: Validate coverage
timeout-minutes: 5
run: bundle exec bake decode:index:coverage lib
24 changes: 24 additions & 0 deletions .github/workflows/rubocop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: RuboCop

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
bundler-cache: true

- name: Run RuboCop
timeout-minutes: 10
run: bundle exec rubocop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage
name: Test Coverage

on: [push, pull_request]

Expand Down Expand Up @@ -33,9 +33,11 @@ jobs:
- name: Run tests
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand All @@ -50,7 +52,7 @@ jobs:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- name: Validate coverage
timeout-minutes: 5
Expand Down
53 changes: 53 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
AllCops:
DisabledByDefault: true

Layout/IndentationStyle:
Enabled: true
EnforcedStyle: tabs

Layout/InitialIndentation:
Enabled: true

Layout/IndentationWidth:
Enabled: true
Width: 1

Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: normal

Layout/BlockAlignment:
Enabled: true

Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/BeginEndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/ElseAlignment:
Enabled: true

Layout/DefEndAlignment:
Enabled: true

Layout/CaseIndentation:
Enabled: true

Layout/CommentIndentation:
Enabled: true

Layout/EmptyLinesAroundClassBody:
Enabled: true

Layout/EmptyLinesAroundModuleBody:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
9 changes: 4 additions & 5 deletions benchmark-http.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
spec.authors = ["Samuel Williams", "Olle Jonsson"]
spec.license = "MIT"

spec.cert_chain = ['release.cert']
spec.signing_key = File.expand_path('~/.gem/release.pem')
spec.cert_chain = ["release.cert"]
spec.signing_key = File.expand_path("~/.gem/release.pem")

spec.homepage = "https://github.com/socketry/benchmark-http"

Expand All @@ -20,15 +20,14 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/socketry/benchmark-http.git",
}

spec.files = Dir.glob(['{bin,lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
spec.files = Dir.glob(["{bin,lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)

spec.executables = ["benchmark-http"]

spec.required_ruby_version = ">= 3.1"

spec.add_dependency "async-await"
spec.add_dependency "async-http", "~> 0.54"
spec.add_dependency "async-io", "~> 1.5"
spec.add_dependency "async-http", "~> 0.83"
spec.add_dependency "console"
spec.add_dependency "samovar", "~> 2.0"
spec.add_dependency "xrb-sanitize"
Expand Down
3 changes: 2 additions & 1 deletion bin/benchmark-http
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
Expand All @@ -20,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require_relative '../lib/benchmark/http'
require_relative "../lib/benchmark/http"

begin
Benchmark::HTTP::Command.call
Expand Down
4 changes: 2 additions & 2 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2022, by Samuel Williams.
# Copyright, 2022-2024, by Samuel Williams.

require 'covered/sus'
require "covered/sus"
include Covered::Sus
17 changes: 0 additions & 17 deletions fixtures/disable_console_context.rb

This file was deleted.

8 changes: 6 additions & 2 deletions gems.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2022, by Samuel Williams.
# Copyright, 2018-2024, by Samuel Williams.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

Expand All @@ -17,6 +17,10 @@
group :test do
gem "sus"
gem "covered"
gem "decode"
gem "rubocop"

gem "sus-fixtures-console"

gem "bake-test"
gem "bake-test-external"
Expand Down
34 changes: 17 additions & 17 deletions lib/benchmark/http/command.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2022, by Samuel Williams.
# Copyright, 2018-2024, by Samuel Williams.

require_relative 'command/latency'
require_relative 'command/concurrency'
require_relative 'command/spider'
require_relative 'command/hammer'
require_relative 'command/wait'
require_relative "command/latency"
require_relative "command/concurrency"
require_relative "command/spider"
require_relative "command/hammer"
require_relative "command/wait"

require_relative 'version'
require 'samovar'
require 'console'
require_relative "version"
require "samovar"
require "console"

module Benchmark
module HTTP
Expand All @@ -24,17 +24,17 @@ class Top < Samovar::Command
self.description = "An asynchronous HTTP server benchmark."

options do
option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
option '-h/--help', "Print out help information."
option '-v/--version', "Print out the application version."
option "--verbose | --quiet", "Verbosity of output for debugging.", key: :logging
option "-h/--help", "Print out help information."
option "-v/--version", "Print out the application version."
end

nested :command, {
'latency' => Latency,
'concurrency' => Concurrency,
'spider' => Spider,
'hammer' => Hammer,
'wait' => Wait,
"latency" => Latency,
"concurrency" => Concurrency,
"spider" => Spider,
"hammer" => Hammer,
"wait" => Wait,
}

def verbose?
Expand Down
20 changes: 10 additions & 10 deletions lib/benchmark/http/command/concurrency.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2022, by Samuel Williams.
# Copyright, 2018-2024, by Samuel Williams.

require_relative '../seconds'
require_relative '../statistics'
require_relative "../seconds"
require_relative "../statistics"

require 'async'
require 'async/http/client'
require 'async/http/endpoint'
require "async"
require "async/http/client"
require "async/http/endpoint"

require 'samovar'
require "samovar"

module Benchmark
module HTTP
Expand All @@ -19,9 +19,9 @@ class Concurrency < Samovar::Command
self.description = "Determine the optimal level of concurrency."

options do
option '-t/--threshold <factor>', "The acceptable latency penalty when making concurrent requests", default: 1.2, type: Float
option '-c/--confidence <factor>', "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
option '-m/--minimum <count>', "The minimum number of connections to make", default: 1, type: Integer
option "-t/--threshold <factor>", "The acceptable latency penalty when making concurrent requests", default: 1.2, type: Float
option "-c/--confidence <factor>", "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
option "-m/--minimum <count>", "The minimum number of connections to make", default: 1, type: Integer
end

many :hosts, "One or more hosts to benchmark"
Expand Down
22 changes: 11 additions & 11 deletions lib/benchmark/http/command/hammer.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2020-2022, by Samuel Williams.
# Copyright, 2020-2024, by Samuel Williams.

require_relative '../seconds'
require_relative '../statistics'
require_relative "../seconds"
require_relative "../statistics"

require 'async'
require 'async/http/client'
require 'async/http/endpoint'
require "async"
require "async/http/client"
require "async/http/endpoint"

require 'samovar'
require "samovar"

module Benchmark
module HTTP
Expand All @@ -20,10 +20,10 @@ class Hammer < Samovar::Command

options do
option "-k/--concurrency <count>", "The number of simultaneous connections to make.", default: 1, type: Integer
option '-c/--count <integer>', "The number of requests to make per connection.", default: 10_000, type: Integer
option "-c/--count <integer>", "The number of requests to make per connection.", default: 10_000, type: Integer

option '-i/--interval <integer>', "The time to wait between measurements.", default: nil, type: Integer
option '--alpn-protocols <name,name>', "Force specific ALPN protocols during connection negotiation.", default: nil, type: String
option "-i/--interval <integer>", "The time to wait between measurements.", default: nil, type: Integer
option "--alpn-protocols <name,name>", "Force specific ALPN protocols during connection negotiation.", default: nil, type: String
end

many :urls, "The urls to hammer."
Expand Down Expand Up @@ -70,7 +70,7 @@ def measure_performance(concurrency, count, endpoint, request_path)
end

def alpn_protocols
@options[:alpn_protocols]&.split(',')
@options[:alpn_protocols]&.split(",")
end

def run(url)
Expand Down
16 changes: 8 additions & 8 deletions lib/benchmark/http/command/latency.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2022, by Samuel Williams.
# Copyright, 2019-2024, by Samuel Williams.

require_relative '../seconds'
require_relative '../statistics'
require_relative "../seconds"
require_relative "../statistics"

require 'async'
require 'async/http/client'
require 'async/http/endpoint'
require "async"
require "async/http/client"
require "async/http/endpoint"

require 'samovar'
require "samovar"

module Benchmark
module HTTP
Expand All @@ -20,7 +20,7 @@ class Latency < Samovar::Command

options do
option "-k/--concurrency <count>", "The number of simultaneous connections to make.", default: 1, type: Integer
option '-c/--confidence <factor>', "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
option "-c/--confidence <factor>", "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
end

many :hosts, "One or more hosts to benchmark"
Expand Down
Loading

0 comments on commit f50ff87

Please # to comment.