kilik52
kilik52
2012-06-29 08:10

rails服务器明明cache hit,但是DB用了很多时间为什么?

已采纳

最近我服务器相应变得非常慢,以下是log:

Processing HomepageController#iphone to xml (for 123.150.158.147 at 2012-06-29 07:59:37) [GET]
User Columns (12.6ms) SHOW FIELDS FROM users
User Load (4758.7ms) SELECT * FROM users WHERE (users.id IS NULL) LIMIT 1
Cached fragment hit: views/www.xxx.com/homepage/iphone.xml (26.4ms)
Filter chain halted as [#nil, :only=>#, :if=>nil}, @identifier=nil, @method=#Proc:0xb7aa8bf8@/usr/local/rvm/gems/ruby-1.8.7-p352/gems/actionpack-2.3.4/lib/action_controller/caching/actions.rb:64>] did_not_yield.
Completed in 4870ms (View: 9, DB: 4777) | 200 OK [http://www.xxxcom/homepage/iphone.xml]

我不知道为什么DB用了4777ms。。。。请问这个怎么查为什么?并不是所有请求都是这样的,就是有些请求会特别长。

另外:有些log是这样的:
Processing ProductsController#index to xml (for 222.134.168.129 at 2012-06-29 08:05:53) [GET]
Parameters: {"page"=>"1", "page_size"=>"15"}
User Load (0.7ms) SELECT * FROM users WHERE (users.id IS NULL) LIMIT 1
Cached fragment hit: views/www.xxx.com/products.xml?page=1&page_size=15.xml (3.8ms)
Filter chain halted as [#nil, :only=>#, :if=>nil}, @identifier=nil, @method=#Proc:0xb7aa8bf8@/usr/local/rvm/gems/ruby-1.8.7-p352/gems/actionpack-2.3.4/lib/action_controller/caching/actions.rb:64>] did_not_yield.
Completed in 35ms (View: 1, DB: 1) | 200 OK [http://www.xxx.com/products.xml?page=1&page_size=15]

请问这35ms占用了啥?我看出来cache hit用了3.8,view和DB都用了1?,那怎么会要35ms?

谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • hooopo Hooopo 9年前

    [quote]User Load (4758.7ms) SELECT * FROM users WHERE (users.id IS NULL) LIMIT 1[/quote]
    是这句的时间过长。你的片段缓存命中和controller里的查询没关系。

    点赞 7 评论 复制链接分享
  • iteye_12540 iteye_12540 9年前

    需要你对每一步的消耗进行分析,搞清楚到底是哪里消耗最大。

    点赞 评论 复制链接分享

相关推荐