Skip to content

Commit

Permalink
Try a larger batch to make it fail for older redis versions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed Dec 4, 2023
1 parent 3a379e6 commit 0da483e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/judoscale-sidekiq-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- "2.7"
- "3.1"
redis:
- "5.0"
- "6.0"
- "7.0"

Expand Down
30 changes: 24 additions & 6 deletions judoscale-sidekiq/test/benchmarks/collect_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,44 @@
require "judoscale/sidekiq/metrics_collector"

class CollectBenchmark < Minitest::Benchmark
# performance assertions will iterate over `bench_range`
BATCH_SIZE = 1_000
MAX_RETRIES = 3

# performance assertions will iterate over `bench_range`.
# We'll use it to define the number Sidekiq jobs we enqueue in Redis.
def self.bench_range
bench_exp 10, 100_000 #=> [10, 100, 1000, 10_000, 100_000]
bench_exp 10, 1_000_000 #=> [10, 100, 1000, 10000, 100000, 1000000]
end

def setup
# Override ConfigHelpers and log to STDOUT for debugging
Judoscale::Config.instance.reset

@collector = Judoscale::Sidekiq::MetricsCollector.new
sidekiq_args = BATCH_SIZE.times.map { [] }

# We need to prepare data for all benchmarks in advance. Each benchmark
# will target an isolated Redis DB with a different number of jobs.
self.class.bench_range.each do |n|
with_isolated_redis(n) do
Sidekiq.redis(&:flushdb)

# Enqueue n Sidekiq jobs
sidekiq_args = n.times.map { [] }
Sidekiq::Client.push_bulk "class" => "DoesNotMatter", "args" => sidekiq_args
(n / BATCH_SIZE).times do |i|
attempts = 0

begin
Sidekiq::Client.push_bulk "class" => "Foo", "args" => sidekiq_args
rescue RedisClient::CannotConnectError => e
attempts += 1
puts "RESCUED batch #{i}, attempt #{attempts}: #{e.message}"

# Give the connection a moment to recover
sleep(1)

retry if attempts < MAX_RETRIES
raise e
end
end
end
end
end
Expand All @@ -41,7 +59,7 @@ def bench_collect
private

def with_isolated_redis(n, &block)
# n is in powers of 10, but we want to use a database number in the range 1-9
# n is in powers of 10, but we want to use a database number in the range 0-9
db_number = Math.log10(n).to_i

if Sidekiq.respond_to?(:default_configuration)
Expand Down

0 comments on commit 0da483e

Please sign in to comment.