Skip to content

Instantly share code, notes, and snippets.

@gazay
Created October 9, 2015 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gazay/a106917e3adb74a11d50 to your computer and use it in GitHub Desktop.
Save gazay/a106917e3adb74a11d50 to your computer and use it in GitHub Desktop.
Sidekiq threads leaking
require 'sidekiq/cli'
require 'sidekiq/api'
require 'celluloid'
puts Sidekiq::Stats.new.queues
Sidekiq::Queue.new('default').clear
Sidekiq::RetrySet.new.clear
module Count
@count = 0
def self.increment
@count += 1
if @count % 1000 == 0
mem = (`ps -o rss -p #{$$}`.strip.split.last.to_i / 1024).to_i
print "\b"*200 + "#{@count}: #{mem}MB"
end
if @count == 10000
GC.start full_mark: true, immediate_sweep: true
threads = ObjectSpace.each_object(Thread)
fibers = ObjectSpace.each_object(Fiber)
mem = (`ps -o rss -p #{$$}`.strip.split.last.to_i / 1024).to_i
puts "\n#{@count}: #{mem}MB (Fibers: #{fibers.select(&:alive?).count}/#{fibers.count}, Threads: #{threads.select(&:alive?).count}/#{threads.count})\n"
Process.kill 'INT', 0
end
end
end
class Brazay
include Sidekiq::Worker
sidekiq_options retry: false
def perform
Count.increment
raise StandardError
end
end
10000.times { Brazay.perform_async }
Sidekiq.logger = nil
Sidekiq::CLI.instance.tap do |cli|
%w(validate! boot_system).each {|stub| cli.define_singleton_method(stub) {}}
cli.parse ['-qdefault', '-c 10']
cli.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment