Rails:如何记录所有执行时间超过 4 秒的请求?

发布于 2024-09-04 06:08:41 字数 228 浏览 5 评论 0原文

我有一个托管在云环境中的 Web 应用程序,可以扩展到多个 Web 节点以服务更高的负载。

我需要做的是当我们收到越来越多的HTTP请求(资产被远程存储)时捕获这种情况。我怎样才能做到这一点?

从这个角度来看,我看到的问题是,如果我们的请求多于混合集群可以处理的数量,那么队列将会增长。在我们的 Rails 应用程序中,我们只能在 mongrel 收到平衡器的请求后才进行计数。

有什么建议吗?

I have a web app hosted in a cloud environment which can be expanded to multiple web-nodes to serve higher load.

What I need to do is to catch this situation when we get more and more HTTP requests (assets are stored remotely). How can I do that?

The problem I see from this point of view is that if we have more requests than mongrel cluster can handle then the queue will grow. And in our Rails app we can only count only after mongrel will receive the request from balancer..

Any recommendations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

南渊 2024-09-11 06:08:41

我会从一个 around_filter 开始,也许类似:

around_filter :time_it

private
  def time_it
    now = DateTime.now
    yield # this is where the request gets made.
    time_span = DateTime.now - now

    # convert to double for better accuracy.
    # (i.e. 3.5 => 4 so you might not want to
    # work with integers here.
    if time_span * 86400.0 > 4.0  
      logger.debug "something is taking a little longer then expected here!"
    end
  end

使用它作为起点。希望有帮助。

编辑:将此代码放入ApplicationController中,以便每个控制器都可以使用它。

I would start with an around_filter maybe something like:

around_filter :time_it

private
  def time_it
    now = DateTime.now
    yield # this is where the request gets made.
    time_span = DateTime.now - now

    # convert to double for better accuracy.
    # (i.e. 3.5 => 4 so you might not want to
    # work with integers here.
    if time_span * 86400.0 > 4.0  
      logger.debug "something is taking a little longer then expected here!"
    end
  end

Use this as a starting point. Hope that helps.

Edit: put this code in the ApplicationController so it can be used by every Controller.

我的黑色迷你裙 2024-09-11 06:08:41

除了 @DJTripleThreat 之外,您还应该看看 NewRelic RPM,以更深入地了解代码的性能。

In addition to @DJTripleThreat, you should have a look at NewRelic RPM to get more insight to your code's performance.

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