Skip to content

Commit

Permalink
Warn on boot if maxmemory policy is not 'noeviction' (#4752)
Browse files Browse the repository at this point in the history
  • Loading branch information
odlp committed Dec 2, 2020
1 parent 622adfe commit c4c01f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/sidekiq/cli.rb
Expand Up @@ -62,6 +62,11 @@ def run(boot_app: true)
ver = Sidekiq.redis_info["redis_version"]
raise "You are connecting to Redis v#{ver}, Sidekiq requires Redis v4.0.0 or greater" if ver < "4"

maxmemory_policy = Sidekiq.redis_info["maxmemory_policy"]
if maxmemory_policy != "noeviction"
logger.warn "'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}'). See: https://github.com/mperham/sidekiq/wiki/Using-Redis#memory"
end

# Since the user can pass us a connection pool explicitly in the initializer, we
# need to verify the size is large enough or else Sidekiq's performance is dramatically slowed.
cursize = Sidekiq.redis_pool.size
Expand Down
26 changes: 26 additions & 0 deletions test/test_cli.rb
Expand Up @@ -481,6 +481,32 @@ def logdev
assert_includes @logdev.string, "Booted Rails #{::Rails.version} application in production environment"
end
end

describe 'checking maxmemory policy' do
it 'warns if the policy is not noeviction' do
redis_info = { "maxmemory_policy" => "allkeys-lru", "redis_version" => "6" }

Sidekiq.stub(:redis_info, redis_info) do
subject.stub(:launch, nil) do
subject.run
end
end

assert_includes @logdev.string, "'noeviction' maxmemory policy is recommended (current policy: 'allkeys-lru')"
end

it 'silent if the policy is noeviction' do
redis_info = { "maxmemory_policy" => "noeviction", "redis_version" => "6" }

Sidekiq.stub(:redis_info, redis_info) do
subject.stub(:launch, nil) do
subject.run
end
end

refute_includes @logdev.string, "'noeviction' maxmemory policy is recommended"
end
end
end

describe 'signal handling' do
Expand Down

0 comments on commit c4c01f8

Please sign in to comment.