From e5bb177f4636f280289420e8e5b6a00abbece23a Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Fri, 12 Feb 2021 14:58:31 +0100 Subject: [PATCH 1/9] Reduce the number of threads used for reaping --- Gemfile | 2 + bin/profiling | 42 +++++++++++++ lib/sidekiq_unique_jobs.rb | 4 +- lib/sidekiq_unique_jobs/orphans/manager.rb | 16 ++++- lib/sidekiq_unique_jobs/timer_task.rb | 63 +++++++++++++++++++ .../orphans/manager_spec.rb | 8 +-- 6 files changed, 127 insertions(+), 8 deletions(-) create mode 100755 bin/profiling create mode 100644 lib/sidekiq_unique_jobs/timer_task.rb diff --git a/Gemfile b/Gemfile index 575964f15..293a2af19 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem "timecop" gem "yard" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -30,6 +31,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end diff --git a/bin/profiling b/bin/profiling new file mode 100755 index 000000000..30cb48f0e --- /dev/null +++ b/bin/profiling @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Trap interrupts to quit cleanly. See +# https://twitter.com/mitchellh/status/283014103189053442 +Signal.trap("INT") { abort } + +require "bundler/setup" +require "ruby-prof" +require "sidekiq-unique-jobs" + +SidekiqUniqueJobs.configure do |config| + config.reaper_interval = 2 + config.reaper_timeout = 1 + config.reaper_count = 10000 +end + +TASK = SidekiqUniqueJobs::TimerTask.new(SidekiqUniqueJobs::Orphans::Manager.timer_task_options) do + SidekiqUniqueJobs::Orphans::Manager.with_logging_context do + SidekiqUniqueJobs::Orphans::Manager.redis do |conn| + SidekiqUniqueJobs::Orphans::Manager.refresh_reaper_mutex + sleep(1) + end + end +end + +counter = 0 +result = RubyProf.profile do + 100.times do + SidekiqUniqueJobs::Orphans::Manager.start(TASK) + end + + while counter < 60 + sleep(1) + + counter += 1 + end +end + +result.exclude_common_methods! +printer = RubyProf::GraphPrinter.new(result) +printer.print($stdout, min_percent: 2) diff --git a/lib/sidekiq_unique_jobs.rb b/lib/sidekiq_unique_jobs.rb index 9d1b0a6a6..3936f9be3 100644 --- a/lib/sidekiq_unique_jobs.rb +++ b/lib/sidekiq_unique_jobs.rb @@ -3,9 +3,10 @@ require "brpoplpush/redis_script" require "concurrent/future" require "concurrent/promises" -require "concurrent/timer_task" require "concurrent/map" require "concurrent/mutable_struct" +require 'concurrent/timer_task' +require 'concurrent/executor/ruby_single_thread_executor' require "digest" require "digest/sha1" require "erb" @@ -14,6 +15,7 @@ require "pathname" require "sidekiq" +require "sidekiq_unique_jobs/timer_task" require "sidekiq_unique_jobs/version" require "sidekiq_unique_jobs/version_check" require "sidekiq_unique_jobs/constants" diff --git a/lib/sidekiq_unique_jobs/orphans/manager.rb b/lib/sidekiq_unique_jobs/orphans/manager.rb index d98424f91..720c56e2d 100644 --- a/lib/sidekiq_unique_jobs/orphans/manager.rb +++ b/lib/sidekiq_unique_jobs/orphans/manager.rb @@ -20,12 +20,14 @@ module Manager # Starts a separate thread that periodically reaps orphans # # - # @return [Concurrent::TimerTask] the task that was started + # @return [SidekiqUniqueJobs::TimerTask] the task that was started # - def start # rubocop:disable + def start(test_task = nil) # rubocop:disable return if disabled? return if registered? + self.task = test_task || default_task + with_logging_context do register_reaper_process log_info("Starting Reaper") @@ -59,7 +61,11 @@ def stop # @return [] # def task - @task ||= Concurrent::TimerTask.new(timer_task_options) do + @task ||= default_task + end + + def default_task + SidekiqUniqueJobs::TimerTask.new(timer_task_options) do with_logging_context do redis do |conn| refresh_reaper_mutex @@ -69,6 +75,10 @@ def task end end + def task=(task) + @task = task + end + # # Arguments passed on to the timer task # diff --git a/lib/sidekiq_unique_jobs/timer_task.rb b/lib/sidekiq_unique_jobs/timer_task.rb new file mode 100644 index 000000000..7089c1347 --- /dev/null +++ b/lib/sidekiq_unique_jobs/timer_task.rb @@ -0,0 +1,63 @@ +module SidekiqUniqueJobs + class TimerTask < ::Concurrent::TimerTask + private + + def ns_initialize(opts, &task) + set_deref_options(opts) + + self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL + self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL + @run_now = opts[:now] || opts[:run_now] + @executor = Concurrent::RubySingleThreadExecutor.new + @running = Concurrent::AtomicBoolean.new(false) + @task = task + @value = nil + + self.observers = Concurrent::Collection::CopyOnNotifyObserverSet.new + end + + # @!visibility private + def execute_task(completion) + return nil unless @running.true? + Concurrent::ScheduledTask.execute(timeout_interval, args: [completion], &method(:timeout_task)) + @thread_completed = Concurrent::Event.new + + @value = @reason = nil + @executor.post do + begin + @value = @task.call(self) + rescue Exception => ex + @reason = ex + ensure + @thread_completed.set + end + end + + @thread_completed.wait + + if completion.try? + schedule_next_task + time = Time.now + observers.notify_observers do + [time, self.value, @reason] + end + end + nil + end + + # @!visibility private + def timeout_task(completion) + return unless @running.true? + if completion.try? + @executor.kill + @executor.wait_for_termination + @executor = Concurrent::RubySingleThreadExecutor.new + + @thread_completed.set + + schedule_next_task + observers.notify_observers(Time.now, nil, Concurrent::TimeoutError.new) + end + end + end +end diff --git a/spec/sidekiq_unique_jobs/orphans/manager_spec.rb b/spec/sidekiq_unique_jobs/orphans/manager_spec.rb index 12cdd92bb..fb895258b 100644 --- a/spec/sidekiq_unique_jobs/orphans/manager_spec.rb +++ b/spec/sidekiq_unique_jobs/orphans/manager_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SidekiqUniqueJobs::Orphans::Manager do - let(:task) { instance_spy(Concurrent::TimerTask) } + let(:task) { instance_spy(SidekiqUniqueJobs::TimerTask) } let(:observer) { instance_spy(SidekiqUniqueJobs::Orphans::Observer) } describe ".start" do @@ -301,16 +301,16 @@ subject(:task) { described_class.task } before do - allow(Concurrent::TimerTask).to receive(:new).and_call_original + allow(SidekiqUniqueJobs::TimerTask).to receive(:new).and_call_original allow(described_class).to receive(:with_logging_context).and_yield allow(described_class).to receive(:refresh_reaper_mutex).and_return(true) allow(SidekiqUniqueJobs::Orphans::Reaper).to receive(:call).and_return(true) end it "initializes a new timer task with the correct arguments" do - expect(task).to be_a(Concurrent::TimerTask) + expect(task).to be_a(SidekiqUniqueJobs::TimerTask) - expect(Concurrent::TimerTask).to have_received(:new) + expect(SidekiqUniqueJobs::TimerTask).to have_received(:new) .with(described_class.timer_task_options) end end From 089b77374492f6cfa96e8a8a81443600979be52a Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 15 Feb 2021 09:38:03 +0100 Subject: [PATCH 2/9] Fix specs --- bin/profiling | 4 ++-- lib/sidekiq_unique_jobs.rb | 4 ++-- lib/sidekiq_unique_jobs/timer_task.rb | 18 ++++++++++-------- .../orphans/manager_spec.rb | 6 +++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bin/profiling b/bin/profiling index 30cb48f0e..e23c6b3d5 100755 --- a/bin/profiling +++ b/bin/profiling @@ -12,12 +12,12 @@ require "sidekiq-unique-jobs" SidekiqUniqueJobs.configure do |config| config.reaper_interval = 2 config.reaper_timeout = 1 - config.reaper_count = 10000 + config.reaper_count = 10_000 end TASK = SidekiqUniqueJobs::TimerTask.new(SidekiqUniqueJobs::Orphans::Manager.timer_task_options) do SidekiqUniqueJobs::Orphans::Manager.with_logging_context do - SidekiqUniqueJobs::Orphans::Manager.redis do |conn| + SidekiqUniqueJobs::Orphans::Manager.redis do |_conn| SidekiqUniqueJobs::Orphans::Manager.refresh_reaper_mutex sleep(1) end diff --git a/lib/sidekiq_unique_jobs.rb b/lib/sidekiq_unique_jobs.rb index 3936f9be3..46f080038 100644 --- a/lib/sidekiq_unique_jobs.rb +++ b/lib/sidekiq_unique_jobs.rb @@ -5,8 +5,8 @@ require "concurrent/promises" require "concurrent/map" require "concurrent/mutable_struct" -require 'concurrent/timer_task' -require 'concurrent/executor/ruby_single_thread_executor' +require "concurrent/timer_task" +require "concurrent/executor/ruby_single_thread_executor" require "digest" require "digest/sha1" require "erb" diff --git a/lib/sidekiq_unique_jobs/timer_task.rb b/lib/sidekiq_unique_jobs/timer_task.rb index 7089c1347..93c2f148f 100644 --- a/lib/sidekiq_unique_jobs/timer_task.rb +++ b/lib/sidekiq_unique_jobs/timer_task.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SidekiqUniqueJobs class TimerTask < ::Concurrent::TimerTask private @@ -19,18 +21,17 @@ def ns_initialize(opts, &task) # @!visibility private def execute_task(completion) return nil unless @running.true? + Concurrent::ScheduledTask.execute(timeout_interval, args: [completion], &method(:timeout_task)) @thread_completed = Concurrent::Event.new @value = @reason = nil @executor.post do - begin - @value = @task.call(self) - rescue Exception => ex - @reason = ex - ensure - @thread_completed.set - end + @value = @task.call(self) + rescue Exception => ex + @reason = ex + ensure + @thread_completed.set end @thread_completed.wait @@ -39,7 +40,7 @@ def execute_task(completion) schedule_next_task time = Time.now observers.notify_observers do - [time, self.value, @reason] + [time, value, @reason] end end nil @@ -48,6 +49,7 @@ def execute_task(completion) # @!visibility private def timeout_task(completion) return unless @running.true? + if completion.try? @executor.kill @executor.wait_for_termination diff --git a/spec/sidekiq_unique_jobs/orphans/manager_spec.rb b/spec/sidekiq_unique_jobs/orphans/manager_spec.rb index fb895258b..d660407a5 100644 --- a/spec/sidekiq_unique_jobs/orphans/manager_spec.rb +++ b/spec/sidekiq_unique_jobs/orphans/manager_spec.rb @@ -297,8 +297,8 @@ end end - describe "#task" do - subject(:task) { described_class.task } + describe "#default_task" do + subject(:default_task) { described_class.default_task } before do allow(SidekiqUniqueJobs::TimerTask).to receive(:new).and_call_original @@ -308,7 +308,7 @@ end it "initializes a new timer task with the correct arguments" do - expect(task).to be_a(SidekiqUniqueJobs::TimerTask) + expect(default_task).to be_a(SidekiqUniqueJobs::TimerTask) expect(SidekiqUniqueJobs::TimerTask).to have_received(:new) .with(described_class.timer_task_options) From bcd09d621433f7d1f9ef3b0e018ebe6e51ea30c9 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 15 Feb 2021 09:38:09 +0100 Subject: [PATCH 3/9] Fix specs --- spec/sidekiq_unique_jobs/web_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/sidekiq_unique_jobs/web_spec.rb b/spec/sidekiq_unique_jobs/web_spec.rb index 8ed841fc5..892543c71 100644 --- a/spec/sidekiq_unique_jobs/web_spec.rb +++ b/spec/sidekiq_unique_jobs/web_spec.rb @@ -7,7 +7,17 @@ include Rack::Test::Methods def app - Sidekiq::Web + @app ||= Rack::Builder.new do + use Rack::Session::Cookie, + key: "rack.session", + domain: "foo.com", + path: "/", + expire_after: 2_592_000, + secret: "change_me", + old_secret: "also_change_me" + + run Sidekiq::Web + end end before do From c4b1a1e91ca2c34e28766ebad187d3ca42c60dca Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 15 Feb 2021 09:38:18 +0100 Subject: [PATCH 4/9] Fix Gemfiles --- gemfiles/sidekiq_5.0.gemfile | 2 ++ gemfiles/sidekiq_5.1.gemfile | 2 ++ gemfiles/sidekiq_5.2.gemfile | 2 ++ gemfiles/sidekiq_6.0.gemfile | 2 ++ gemfiles/sidekiq_6.1.gemfile | 2 ++ gemfiles/sidekiq_develop.gemfile | 2 ++ 6 files changed, 12 insertions(+) diff --git a/gemfiles/sidekiq_5.0.gemfile b/gemfiles/sidekiq_5.0.gemfile index 71e4186dc..2dc5589fc 100644 --- a/gemfiles/sidekiq_5.0.gemfile +++ b/gemfiles/sidekiq_5.0.gemfile @@ -16,6 +16,7 @@ gem "yard" gem "sidekiq", "~> 5.0.0" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -28,6 +29,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end diff --git a/gemfiles/sidekiq_5.1.gemfile b/gemfiles/sidekiq_5.1.gemfile index c32cfbd22..d6b811cb0 100644 --- a/gemfiles/sidekiq_5.1.gemfile +++ b/gemfiles/sidekiq_5.1.gemfile @@ -16,6 +16,7 @@ gem "yard" gem "sidekiq", "~> 5.1.0" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -28,6 +29,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end diff --git a/gemfiles/sidekiq_5.2.gemfile b/gemfiles/sidekiq_5.2.gemfile index 08fa30e31..5d478d1e1 100644 --- a/gemfiles/sidekiq_5.2.gemfile +++ b/gemfiles/sidekiq_5.2.gemfile @@ -16,6 +16,7 @@ gem "yard" gem "sidekiq", "~> 5.2.0" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -28,6 +29,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end diff --git a/gemfiles/sidekiq_6.0.gemfile b/gemfiles/sidekiq_6.0.gemfile index 89cde0dea..c8a4ccd1a 100644 --- a/gemfiles/sidekiq_6.0.gemfile +++ b/gemfiles/sidekiq_6.0.gemfile @@ -16,6 +16,7 @@ gem "yard" gem "sidekiq", "~> 6.0.0" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -28,6 +29,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end diff --git a/gemfiles/sidekiq_6.1.gemfile b/gemfiles/sidekiq_6.1.gemfile index 04c4a2b9d..fec09b09c 100644 --- a/gemfiles/sidekiq_6.1.gemfile +++ b/gemfiles/sidekiq_6.1.gemfile @@ -16,6 +16,7 @@ gem "yard" gem "sidekiq", "~> 6.1.0" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -28,6 +29,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end diff --git a/gemfiles/sidekiq_develop.gemfile b/gemfiles/sidekiq_develop.gemfile index a5f1b6e36..4f8fddd16 100644 --- a/gemfiles/sidekiq_develop.gemfile +++ b/gemfiles/sidekiq_develop.gemfile @@ -16,6 +16,7 @@ gem "yard" gem "sidekiq", git: "https://github.com/mperham/sidekiq.git" platforms :mri do + gem "concurrent-ruby-ext" gem "fasterer" gem "github_changelog_generator" gem "guard" @@ -28,6 +29,7 @@ platforms :mri do gem "reek", ">= 5.3" gem "rspec-benchmark" gem "rubocop-mhenrixon" + gem "ruby-prof", require: false gem "simplecov-sublime", "0.21.0", require: false gem "travis" end From 4126988b1ccae19967abf09c2c090c2161235057 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 15 Feb 2021 09:53:45 +0100 Subject: [PATCH 5/9] Mandatory rubocop commit --- lib/sidekiq_unique_jobs/timer_task.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/sidekiq_unique_jobs/timer_task.rb b/lib/sidekiq_unique_jobs/timer_task.rb index 93c2f148f..802b7fbe9 100644 --- a/lib/sidekiq_unique_jobs/timer_task.rb +++ b/lib/sidekiq_unique_jobs/timer_task.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true module SidekiqUniqueJobs + # @see [Concurrent::TimerTask] https://www.rubydoc.info/gems/concurrent-ruby/Concurrent/TimerTask + # class TimerTask < ::Concurrent::TimerTask private @@ -19,16 +21,20 @@ def ns_initialize(opts, &task) end # @!visibility private - def execute_task(completion) + def execute_task(completion) # rubocop:disable Metrics/MethodLength return nil unless @running.true? - Concurrent::ScheduledTask.execute(timeout_interval, args: [completion], &method(:timeout_task)) + Concurrent::ScheduledTask.execute( + timeout_interval, + args: [completion], + &method(:timeout_task) # rubocop:disable Performance/MethodObjectAsBlock + ) @thread_completed = Concurrent::Event.new @value = @reason = nil @executor.post do @value = @task.call(self) - rescue Exception => ex + rescue Exception => ex # rubocop:disable Lint/RescueException @reason = ex ensure @thread_completed.set @@ -49,17 +55,16 @@ def execute_task(completion) # @!visibility private def timeout_task(completion) return unless @running.true? + return unless completion.try? - if completion.try? - @executor.kill - @executor.wait_for_termination - @executor = Concurrent::RubySingleThreadExecutor.new + @executor.kill + @executor.wait_for_termination + @executor = Concurrent::RubySingleThreadExecutor.new - @thread_completed.set + @thread_completed.set - schedule_next_task - observers.notify_observers(Time.now, nil, Concurrent::TimeoutError.new) - end + schedule_next_task + observers.notify_observers(Time.now, nil, Concurrent::TimeoutError.new) end end end From 63fcee23f897b7838d47393496042f49c3eccef3 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 15 Feb 2021 09:56:31 +0100 Subject: [PATCH 6/9] Reduce performance impact of method as block --- lib/sidekiq_unique_jobs/timer_task.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sidekiq_unique_jobs/timer_task.rb b/lib/sidekiq_unique_jobs/timer_task.rb index 802b7fbe9..da374c603 100644 --- a/lib/sidekiq_unique_jobs/timer_task.rb +++ b/lib/sidekiq_unique_jobs/timer_task.rb @@ -24,10 +24,12 @@ def ns_initialize(opts, &task) def execute_task(completion) # rubocop:disable Metrics/MethodLength return nil unless @running.true? + timeout_task = -> { timeout_task(completion) } + Concurrent::ScheduledTask.execute( timeout_interval, args: [completion], - &method(:timeout_task) # rubocop:disable Performance/MethodObjectAsBlock + &timeout_task ) @thread_completed = Concurrent::Event.new From 5b04e1fd29d7d793592ba68efd46320dba2d23ee Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 15 Feb 2021 10:03:30 +0100 Subject: [PATCH 7/9] Smelly --- .reek.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.reek.yml b/.reek.yml index 0e1cc3340..31c684a0e 100644 --- a/.reek.yml +++ b/.reek.yml @@ -18,6 +18,7 @@ detectors: exclude: - Sidekiq::JobSet::UniqueExtension#delete_by_value - Sidekiq::ScheduledSet::UniqueExtension#delete + - SidekiqUniqueJobs::Orphans::Manager#start - SidekiqUniqueJobs::Orphans::RubyReaper#active? - SidekiqUniqueJobs::Redis::Hash#entries DataClump: @@ -58,6 +59,9 @@ detectors: - SidekiqUniqueJobs::SidekiqWorkerMethods#worker_class_constantize - SidekiqUniqueJobs::Web::Helpers#cparams - SidekiqUniqueJobs::Web::Helpers#display_lock_args + InstanceVariableAssumption: + exclude: + - SidekiqUniqueJobs::TimerTask IrresponsibleModule: enabled: true LongParameterList: @@ -139,6 +143,8 @@ detectors: - SidekiqUniqueJobs::Script::Caller#call_script - SidekiqUniqueJobs::Script::Caller#extract_args - SidekiqUniqueJobs::SidekiqWorkerMethods#worker_class_constantize + - SidekiqUniqueJobs::TimerTask#execute_task + - SidekiqUniqueJobs::TimerTask#timeout_task - SidekiqUniqueJobs::UpgradeLocks#call - SidekiqUniqueJobs::UpgradeLocks#upgrade_v6_lock - SidekiqUniqueJobs::Web#self.registered @@ -148,6 +154,7 @@ detectors: - SidekiqUniqueJobs::LockConfig - SidekiqUniqueJobs::Locksmith - SidekiqUniqueJobs::Lock::BaseLock + - SidekiqUniqueJobs::TimerTask TooManyMethods: exclude: - SidekiqUniqueJobs::Lock::BaseLock From 3de6ed92aec62a0f89fc30d2d58f2bbbffce4a91 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Wed, 17 Feb 2021 08:46:49 +0100 Subject: [PATCH 8/9] Update README to a more sensible default --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9a013e451..1a70103e1 100644 --- a/README.md +++ b/README.md @@ -185,16 +185,16 @@ Configure SidekiqUniqueJobs in an initializer or the sidekiq initializer on appl ```ruby SidekiqUniqueJobs.configure do |config| - config.debug_lua = true - config.lock_info = true - config.lock_ttl = 10.minutes - config.lock_timeout = 10.minutes - config.logger = Sidekiq.logger - config.max_history = 10_000 - config.reaper = :lua - config.reaper_count = 100 - config.reaper_interval = 10 - config.reaper_timeout = 5 + config.logger = Sidekiq.logger # default, change at your own discretion + config.debug_lua = false # Turn on when debugging + config.lock_info = false # Turn on when debugging + config.lock_ttl = 600 # Expire locks after 10 minutes + config.lock_timeout = nil # turn off lock timeout + config.max_history = 0 # Turn on when debugging + config.reaper = :ruby # :ruby, :lua or :none/nil + config.reaper_count = 1000 # Stop reaping after this many keys + config.reaper_interval = 600 # Reap orphans every 10 minutes + config.reaper_timeout = 150 # Timeout reaper after 1,5 minutes end ``` From 2e0867b8fd4e34fb62da87c196dcc27b3966eff3 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Wed, 17 Feb 2021 08:47:09 +0100 Subject: [PATCH 9/9] Reduce overhead of schedule_next_task as well --- lib/sidekiq_unique_jobs/timer_task.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/sidekiq_unique_jobs/timer_task.rb b/lib/sidekiq_unique_jobs/timer_task.rb index da374c603..38d0e13be 100644 --- a/lib/sidekiq_unique_jobs/timer_task.rb +++ b/lib/sidekiq_unique_jobs/timer_task.rb @@ -20,6 +20,12 @@ def ns_initialize(opts, &task) self.observers = Concurrent::Collection::CopyOnNotifyObserverSet.new end + def schedule_next_task(interval = execution_interval) + exec_task = ->(completion) { execute_task(completion) } + ScheduledTask.execute(interval, args: [Concurrent::Event.new], &exec_task) + nil + end + # @!visibility private def execute_task(completion) # rubocop:disable Metrics/MethodLength return nil unless @running.true?