Sha256: e550d059b5c76c15004a377c8fd519e2e952d27dd162733dc3029a2de799db2d

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

$: << File.expand_path('../lib', File.dirname(__FILE__))
require 'sneakers'
require 'sneakers/runner'
require 'logger'


profiling = ARGV[0]
messages = 100_000


if profiling
  require 'ruby-prof'
  messages /= 100 # profiling makes everything much slower (around 300req/s)
end

Sneakers.configure
Sneakers.logger.level = Logger::ERROR

Sneakers::Worker.configure_logger(Logger.new('/dev/null'))

puts "feeding messages in"
messages.times {
  Sneakers.publish("{}", :to_queue => 'downloads')
}
puts "done"


class ProfilingWorker
  include Sneakers::Worker
  from_queue 'downloads',
             :ack => true,
             :threads => 50,
             :prefetch => 50,
             :timeout_job_after => 1,
             :exchange => 'sneakers',
             :heartbeat => 5
  def work(msg)
    ack!
  end
end



r = Sneakers::Runner.new([ProfilingWorker])

# ctrl-c and Ruby 2.0 breaks signal handling
# Sidekiq has same issues
# https://github.com/mperham/sidekiq/issues/728
#
# so we use a timeout and a thread that kills profiling
if profiling
  puts "profiling start"
  RubyProf.start


  Thread.new do
    sleep 10
    puts "stopping profiler"
    result = RubyProf.stop

    # Print a flat profile to text
    printer = RubyProf::FlatPrinter.new(result)
    printer.print(STDOUT)
    exit(0)
  end
end

r.run

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
sneakers_custom_bunny-1.0.4 examples/profiling_worker.rb
sneakers-1.0.4 examples/profiling_worker.rb
sneakers-1.0.3 examples/profiling_worker.rb
sneakers-1.0.2 examples/profiling_worker.rb
sneakers-1.0.1 examples/profiling_worker.rb
sneakers-1.0.0 examples/profiling_worker.rb
sneakers-0.1.1.pre examples/profiling_worker.rb