mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Remove global 'busy' counter, too easy to skew in the face of crashy processes
This commit is contained in:
parent
d233b4f650
commit
8f49ee96ac
3 changed files with 13 additions and 11 deletions
|
@ -497,8 +497,20 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
|
||||
# Not very efficient if you have lots of Sidekiq
|
||||
# processes but the alternative is a global counter
|
||||
# which can easily get out of sync with crashy processes.
|
||||
def size
|
||||
Sidekiq.redis { |conn| conn.get('busy') }.to_i
|
||||
Sidekiq.redis do |conn|
|
||||
procs = conn.smembers('processes')
|
||||
return 0 if procs.empty?
|
||||
|
||||
conn.multi do
|
||||
procs.each do |key|
|
||||
conn.hget(key, 'busy')
|
||||
end
|
||||
end.map(&:to_i).inject(:+)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ module Sidekiq
|
|||
hash = Sidekiq.dump_json({:queue => queue, :payload => msg, :run_at => Time.now.to_i })
|
||||
Sidekiq.redis do |conn|
|
||||
conn.multi do
|
||||
conn.incr('busy')
|
||||
conn.hmset("#{identity}:workers", Thread.current.object_id, hash)
|
||||
conn.expire("#{identity}:workers", 60*60)
|
||||
end
|
||||
|
@ -106,7 +105,6 @@ module Sidekiq
|
|||
Sidekiq.redis do |conn|
|
||||
processed = "stat:processed:#{Time.now.utc.to_date}"
|
||||
result = conn.multi do
|
||||
conn.decr('busy')
|
||||
conn.hdel("#{identity}:workers", Thread.current.object_id)
|
||||
conn.incrby("stat:processed", 1)
|
||||
conn.incrby(processed, 1)
|
||||
|
|
|
@ -378,14 +378,6 @@ class TestApi < Sidekiq::Test
|
|||
c.hmset(s, '1234', data)
|
||||
end
|
||||
|
||||
Sidekiq.redis do |c|
|
||||
assert_equal 0, w.size
|
||||
c.incr("busy")
|
||||
assert_equal 1, w.size
|
||||
c.decr("busy")
|
||||
assert_equal 0, w.size
|
||||
end
|
||||
|
||||
w.each do |x, y|
|
||||
assert_equal "1234", x
|
||||
assert_equal 'default', y['queue']
|
||||
|
|
Loading…
Reference in a new issue