Mongoid / Rails每请求查询数

问题描述

我们有一个生产应用程序,我们发现最大的瓶颈是数据库查询。很难准确地跟踪用户在做什么,以弄清现实中的需求是什么。我们正在考虑构建每个请求跟踪器。 Mongoid或Rails是否支持按请求数的查询跟踪器?我们想要类似开发中的东西,在这里您可以看到所有查询都经过,但是每个请求都经过。我们实现这样的事情:

application_controller:

before_action :log_request_start
after_action :log_request_end

def log_request_start
    request_log = RequestLog.new  # make a new model to 
    request_log.id = Thread.id # use thread?
    request_log.params = request.whatever # harvest some params from the Rails request


def log_request_end
    request_log = Request.find_by(thread_id: Thread.id) #  look it up
    request.total_queries = # can we get the number of mongo queries that fired in this request?

感谢您的帮助, 凯文

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)