EventMachine - 如何判断自己是否落后?
我正在研究使用 EventMachine 支持的 twitter-stream rubygem 来跟踪和捕获推文。我对整个事件编程这件事有点陌生。我如何判断我在事件循环中所做的任何处理是否导致我落后?有没有简单的方法可以检查?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过使用定期计时器并打印出经过的时间来确定延迟。如果您使用 1 秒的计时器,则应该经过大约 1 秒,如果更长,您就会知道反应堆的速度减慢了多少。
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.
EventMachine 有一个
EventMachine::Queue.size
方法,可让您查看当前队列并了解它有多大。您可以
add_periodic_timer()
,在这种情况下,获取队列的大小并打印它。如果这个数字没有变小,那么你们就处于平等状态。如果它上升,你就落后了。
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.