examples/profiling_worker.rb in sneakers-0.1.0.pre vs examples/profiling_worker.rb in sneakers-0.1.1.pre
- old
+ new
@@ -1,55 +1,69 @@
$: << File.expand_path('../lib', File.dirname(__FILE__))
require 'sneakers'
require 'sneakers/runner'
-require 'ruby-prof'
+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"
-1000.times {
+messages.times {
Sneakers.publish("{}", :to_queue => 'downloads')
+}
puts "done"
class ProfilingWorker
include Sneakers::Worker
from_queue 'downloads',
- :env => '',
- :durable => false,
:ack => true,
:threads => 50,
:prefetch => 50,
:timeout_job_after => 1,
- :exchange => 'dummy',
+ :exchange => 'sneakers',
:heartbeat => 5
def work(msg)
ack!
end
end
-r = Sneakers::Runner.new
-Sneakers::Worker.configure_logger(Logger.new('/dev/null'))
+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
-puts "profiling start"
-RubyProf.start
+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)
- r.stop
- exit(0)
+ 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([ ProfilingWorker ])
+r.run