EventMachine - 如何判断自己是否落后?

发布于 2024-10-15 04:11:18 字数 122 浏览 5 评论 0原文

我正在研究使用 EventMachine 支持的 twitter-stream ruby​​gem 来跟踪和捕获推文。我对整个事件编程这件事有点陌生。我如何判断我在事件循环中所做的任何处理是否导致我落后?有没有简单的方法可以检查?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笔一画续写前缘 2024-10-22 04:11:18

您可以通过使用定期计时器并打印出经过的时间来确定延迟。如果您使用 1 秒的计时器,则应该经过大约 1 秒,如果更长,您就会知道反应堆的速度减慢了多少。

@last = Time.now.to_f
EM.add_periodic_timer(1) do
  puts "LATENCY: #{Time.now.to_f - @last}"
  @last = Time.now.to_f
end 

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 
薄暮涼年 2024-10-22 04:11:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文