Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventMachine - how can you tell if you're falling behind?

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?

like image 630
makenai Avatar asked Feb 02 '11 06:02

makenai


2 Answers

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 
like image 152
dj2 Avatar answered Nov 08 '22 22:11

dj2


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.

like image 37
the Tin Man Avatar answered Nov 09 '22 00:11

the Tin Man