Skip to content

Commit

Permalink
Setup and enforce a reasonable rubocop config
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jun 9, 2020
1 parent 287276c commit efe158b
Show file tree
Hide file tree
Showing 117 changed files with 1,159 additions and 1,034 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ on:
branches:
- "*"
jobs:
lint:
name: Rubocop
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: "2.4"
- name: Set up Gems
run: |
gem update --system --no-document
gem install bundler --no-document
bundle install --jobs 4 --retry 3 --path=.bundle
- name: Lint
run: bundle exec rubocop

main:
name: Main
timeout-minutes: 30
Expand Down
114 changes: 114 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
AllCops:
TargetRubyVersion: 2.3

Layout/LineLength:
Max: 120
Exclude:
- 'test/**/*'

Layout/CaseIndentation:
EnforcedStyle: end

Lint/RescueException:
Enabled: false

Lint/SuppressedException:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Lint/UnifiedInteger:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Metrics/ParameterLists:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Style/PercentLiteralDelimiters:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/SignalException:
Exclude:
- 'lib/redis/connection/synchrony.rb'

Style/MethodMissingSuper:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/DoubleNegation:
Enabled: false

Style/MultipleComparison:
Enabled: false

Style/GuardClause:
Enabled: false

Style/Semicolon:
Enabled: false

Style/Documentation:
Enabled: false

Style/FormatStringToken:
Enabled: false

Style/FormatString:
Enabled: false

Style/RescueStandardError:
Enabled: false

Style/WordArray:
Enabled: false

Lint/NonLocalExitFromIterator:
Enabled: false

Lint/EndAlignment:
EnforcedStyleAlignWith: variable

Layout/ElseAlignment:
Enabled: false

Naming/HeredocDelimiterNaming:
Enabled: false

Naming/FileName:
Enabled: false

Naming/RescuedExceptionsVariableName:
Enabled: false

Naming/AccessorMethodName:
Exclude:
- lib/redis/connection/ruby.rb
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

gem 'rake'
gem 'minitest'
gem 'rake'
gem 'rubocop', '0.81'

# Using jruby-openssl 0.10.0, we get NPEs in jruby tests: https://github.com/redis/redis-rb/issues/756
platform :jruby do
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new :test do |t|
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
HOST = '127.0.0.1'
STANDALONE_PORT = 6381
CLUSTER_PORT = 7000
N = (ARGV.first || 100000).to_i
N = (ARGV.first || 100_000).to_i

rn = Redis.new(host: HOST, port: STANDALONE_PORT)
rc = Redis.new(host: HOST, port: CLUSTER_PORT)
Expand Down
12 changes: 6 additions & 6 deletions benchmarking/cluster_slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
require 'redis'
require 'benchmark'

N = (ARGV.first || 100000).to_i
N = (ARGV.first || 100_000).to_i

available_slots = {
"127.0.0.1:7000" => [0..5460],
"127.0.0.1:7003" => [0..5460],
"127.0.0.1:7001" => [5461..10922],
"127.0.0.1:7004" => [5461..10922],
"127.0.0.1:7002" => [10923..16383],
"127.0.0.1:7005" => [10923..16383]
"127.0.0.1:7001" => [5461..10_922],
"127.0.0.1:7004" => [5461..10_922],
"127.0.0.1:7002" => [10_923..16_383],
"127.0.0.1:7005" => [10_923..16_383]
}

node_flags = {
Expand All @@ -33,4 +33,4 @@

puts GC.stat(:total_allocated_objects) - allocs
end
end
end
14 changes: 8 additions & 6 deletions benchmarking/logging.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Run with
#
# $ ruby -Ilib benchmarking/logging.rb
Expand All @@ -7,7 +8,7 @@
begin
require "bench"
rescue LoadError
$stderr.puts "`gem install bench` and try again."
warn "`gem install bench` and try again."
exit 1
end

Expand Down Expand Up @@ -35,19 +36,20 @@ def stress(redis)
default = Redis.new

logging_redises = [
Redis.new(:logger => log(:DEBUG)),
Redis.new(:logger => log(:INFO)),
Redis.new(logger: log(:DEBUG)),
Redis.new(logger: log(:INFO))
]

begin
require "log4r"

logging_redises += [
Redis.new(:logger => log(:DEBUG, Log4r)),
Redis.new(:logger => log(:INFO, Log4r)),
Redis.new(logger: log(:DEBUG, Log4r)),
Redis.new(logger: log(:INFO, Log4r))
]
rescue LoadError
$stderr.puts "Log4r not installed. `gem install log4r` if you want to compare it against Ruby's Logger (spoiler: it's much faster)."
warn "Log4r not installed. `gem install log4r` if you want to compare it against Ruby's " \
"Logger (spoiler: it's much faster)."
end

benchmark "Default options (no logger)" do
Expand Down
5 changes: 3 additions & 2 deletions benchmarking/pipeline.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# frozen_string_literal: true

require "benchmark"

$:.push File.join(File.dirname(__FILE__), 'lib')
$LOAD_PATH.push File.join(File.dirname(__FILE__), 'lib')

require 'redis'

ITERATIONS = 10000
ITERATIONS = 10_000

@r = Redis.new

Expand Down
3 changes: 2 additions & 1 deletion benchmarking/speed.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Run with
#
# $ ruby -Ilib benchmarking/speed.rb
Expand All @@ -8,7 +9,7 @@
require "redis"

r = Redis.new
n = (ARGV.shift || 20000).to_i
n = (ARGV.shift || 20_000).to_i

elapsed = Benchmark.realtime do
# n sets, n gets
Expand Down
7 changes: 4 additions & 3 deletions benchmarking/suite.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'fileutils'

def run_in_background(command)
Expand All @@ -7,17 +8,17 @@ def run_in_background(command)

def with_all_segments(&block)
0.upto(9) do |segment_number|
block_size = 100000
block_size = 100_000
start_index = segment_number * block_size
end_index = start_index + block_size - 1
block.call(start_index, end_index)
end
end

#with_all_segments do |start_index, end_index|
# with_all_segments do |start_index, end_index|
# puts "Initializing keys from #{start_index} to #{end_index}"
# system "ruby worker.rb initialize #{start_index} #{end_index} 0"
#end
# end

with_all_segments do |start_index, end_index|
run_in_background "ruby worker.rb write #{start_index} #{end_index} 10"
Expand Down
65 changes: 33 additions & 32 deletions benchmarking/worker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

BENCHMARK_ROOT = File.dirname(__FILE__)
REDIS_ROOT = File.join(BENCHMARK_ROOT, "..", "lib")

$: << REDIS_ROOT
$LOAD_PATH << REDIS_ROOT
require 'redis'
require 'benchmark'

Expand All @@ -16,7 +17,7 @@ def shift_from_argv
value = ARGV.shift
unless value
show_usage
exit -1
exit(-1)
end
value
end
Expand All @@ -25,48 +26,48 @@ def shift_from_argv
start_index = shift_from_argv.to_i
end_index = shift_from_argv.to_i
sleep_msec = shift_from_argv.to_i
sleep_duration = sleep_msec/1000.0
sleep_duration = sleep_msec / 1000.0

redis = Redis.new

case operation
when :initialize
when :initialize

start_index.upto(end_index) do |i|
redis[i] = 0
end
start_index.upto(end_index) do |i|
redis[i] = 0
end

when :clear
when :clear

start_index.upto(end_index) do |i|
redis.delete(i)
end
start_index.upto(end_index) do |i|
redis.delete(i)
end

when :read, :write
when :read, :write

puts "Starting to #{operation} at segment #{end_index + 1}"
puts "Starting to #{operation} at segment #{end_index + 1}"

loop do
t1 = Time.now
start_index.upto(end_index) do |i|
case operation
when :read
redis.get(i)
when :write
redis.incr(i)
else
raise "Unknown operation: #{operation}"
end
sleep sleep_duration
loop do
t1 = Time.now
start_index.upto(end_index) do |i|
case operation
when :read
redis.get(i)
when :write
redis.incr(i)
else
raise "Unknown operation: #{operation}"
end
t2 = Time.now

requests_processed = end_index - start_index
time = t2 - t1
puts "#{t2.strftime("%H:%M")} [segment #{end_index + 1}] : Processed #{requests_processed} requests in #{time} seconds - #{(requests_processed/time).round} requests/sec"
sleep sleep_duration
end
t2 = Time.now

requests_processed = end_index - start_index
time = t2 - t1
puts "#{t2.strftime('%H:%M')} [segment #{end_index + 1}] : Processed #{requests_processed} requests " \
"in #{time} seconds - #{(requests_processed / time).round} requests/sec"
end

else
raise "Unknown operation: #{operation}"
raise "Unknown operation: #{operation}"
end

Loading

0 comments on commit efe158b

Please sign in to comment.