Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause before dispatching to avoid CPU overload #354

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/shoryuken/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Manager
include Util

BATCH_LIMIT = 10
# See https://github.com/phstc/shoryuken/issues/348#issuecomment-292847028
MIN_DISPATCH_INTERVAL = 0.1

def initialize(fetcher, polling_strategy)
@count = Shoryuken.options.fetch(:concurrency, 25)
Expand Down Expand Up @@ -61,8 +63,10 @@ def dispatch_now
return if @done.true?

begin
return if ready.zero?
return unless (queue = @polling_strategy.next_queue)
if ready.zero? || (queue = @polling_strategy.next_queue).nil?
sleep MIN_DISPATCH_INTERVAL
return
end

logger.debug { "Ready: #{ready}, Busy: #{busy}, Active Queues: #{@polling_strategy.active_queues}" }

Expand Down