开发者

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

开发者 https://www.devze.com 2023-02-08 14:36 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消