Skip to content

Instantly share code, notes, and snippets.

@gazay
Last active November 13, 2015 22:41
Show Gist options
  • Save gazay/3aa78e515ab05cb79f76 to your computer and use it in GitHub Desktop.
Save gazay/3aa78e515ab05cb79f76 to your computer and use it in GitHub Desktop.
require 'celluloid'
puts Celluloid::VERSION
puts '\n\n'
module Count
@count = 0
def self.increment
@count += 1
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
print "\b"*100 + "#{@count}: #{mem}MB (Fibers: #{fibers.select(&:alive?).count}/#{fibers.count}, Threads: #{threads.select(&:alive?).count}/#{threads.count})"
if @count >= 1000
Process.kill 'INT', 0
end
end
end
Celluloid.logger = nil
class Manager
include Celluloid
trap_exit :processor_died
def initialize
@busy = []
@ready = 1.times.map do
Processor.new_link
end
end
def start
@ready.each { dispatch }
end
def dispatch
processor = @ready.pop
@busy << processor
processor.async.process
end
def processor_died(processor, reason)
@busy.delete processor
@ready << Processor.new_link
dispatch
end
end
class Processor
include Celluloid
def process
Count.increment
raise StandardError
end
end
Manager.new.async.start
sleep
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
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
print "\b"*100 + "#{@count}: #{mem}MB (Fibers: #{fibers.select(&:alive?).count}/#{fibers.count}, Threads: #{threads.select(&:alive?).count}/#{threads.count})"
if @count >= 1000
Process.kill 'INT', 0
end
end
end
class Brazay
include Sidekiq::Worker
sidekiq_options retry: false
def perform
Count.increment
raise StandardError
end
end
1000.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 1']
cli.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment