I'm looking into using the EventMachine powered twitter-stream rubygem to track and capture tweets. I'm kind of new to the whole evented programming thing. How can I tell if whatever processing I'm doing in my event loop is causing me to fall behind? Is there an easy way to check?
You can determine the latency by using a periodic timer and printing out the elapsed time. If you're using a timer of 1 second you should have about 1 second elapsed, if it's greater you know how much you're slowing down the reactor.
@last = Time.now.to_f
EM.add_periodic_timer(1) do
puts "LATENCY: #{Time.now.to_f - @last}"
@last = Time.now.to_f
end
EventMachine has a EventMachine::Queue.size
method that lets you peek at the current queue and get an idea how big it is.
You could add_periodic_timer()
and, in that event, get the size of the queue and print it.
If the number is not getting smaller you are at parity. If it's going up you are falling behind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With