1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Garbage optimizations

This commit is contained in:
Mike Perham 2015-10-07 09:43:08 -07:00
parent 71eaac11bd
commit 314a6b64f8
2 changed files with 13 additions and 5 deletions

View file

@ -120,7 +120,10 @@ module Sidekiq
def initialize(options)
@strictly_ordered_queues = !!options[:strict]
@queues = options[:queues].map { |q| "queue:#{q}" }
@unique_queues = @queues.uniq
if @strictly_ordered_queues
@queues = @queues.uniq
@queues << Sidekiq::Fetcher::TIMEOUT
end
end
def retrieve_work
@ -158,7 +161,7 @@ module Sidekiq
end
def queue_name
queue.gsub(/.*queue:/, '')
queue.gsub(/.*queue:/, ''.freeze)
end
def requeue
@ -174,8 +177,13 @@ module Sidekiq
# recreate the queue command each time we invoke Redis#brpop
# to honor weights and avoid queue starvation.
def queues_cmd
queues = @strictly_ordered_queues ? @unique_queues.dup : @queues.shuffle.uniq
queues << Sidekiq::Fetcher::TIMEOUT
if @strictly_ordered_queues
@queues
else
queues = @queues.shuffle.uniq
queues << Sidekiq::Fetcher::TIMEOUT
queues
end
end
end
end

View file

@ -16,7 +16,7 @@ module Sidekiq
# We need to go through the list one at a time to reduce the risk of something
# going wrong between the time jobs are popped from the scheduled queue and when
# they are pushed onto a work queue and losing the jobs.
while job = conn.zrangebyscore(sorted_set, '-inf', now, :limit => [0, 1]).first do
while job = conn.zrangebyscore(sorted_set, '-inf'.freeze, now, :limit => [0, 1]).first do
# Pop item off the queue and add it to the work queue. If the job can't be popped from
# the queue, it's because another process already popped it so we can move on to the