Skip to content

Instantly share code, notes, and snippets.

@apolzon
Created March 8, 2012 18:14
Show Gist options
  • Save apolzon/2002447 to your computer and use it in GitHub Desktop.
Save apolzon/2002447 to your computer and use it in GitHub Desktop.
Resque Profiler
def time_queue_chomping(size = 10)
if Resque.redis.llen("queue:robot_events").to_i > 0
puts "no way jose, the queue is full of junk!"
return
end
Rails.application.config.logger.level = Logger::WARN
ActiveRecord::Base.logger = ::Logger.new(StringIO.new)
t0 = Time.now.to_i
size.times { Resque.push("robot_events", :class => "RobotEventHandler", :args => [{:occurred_at => DateTime.now, :mailer => Mailer.first.attributes, :action => "fetch_top_line_data", :status => "success", :duration => "5", :response_queue => "ROBOT_EVENTS"}]) }
printed = []
while(Resque.redis.llen("queue:robot_events").to_i > 0) do
diff = Time.now.to_i - t0
if diff != 0 && (diff % 60) == 0 && !printed.include?(diff)
printed << diff
puts "1 minute has passed...#{Resque.redis.llen("queue:robot_events")} remain"
end
end
t1 = Time.now.to_i
puts "It took #{t1 - t0} seconds to process #{size} RobotEvents"
puts "Thats a rate of #{size*1.0/(t1-t0)} robot events per second"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment