问题描述
最近我服务器相应变得非常慢,以下是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 1Cached fragment hit: views/www.xxx.com/homepage/iphone.xml (26.4ms)Filter chain halted as [#<ActionController::Filters::AroundFilter:0xb7771b10 @kind=:filter, @options={:unless=>nil,nly=>#<Set: {"iphone"}>, :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 1Cached fragment hit: views/www.xxx.com/products.xml?page=1&page_size=15.xml (3.8ms)Filter chain halted as [#<ActionController::Filters::AroundFilter:0xb77478ec @kind=:filter, @options={:unless=>nil,nly=>#<Set: {"index"}>, :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?谢谢!
解决方案
引用User Load (4758.7ms) SELECT * FROM `users` WHERE (`users`.`id` IS NULL) LIMIT 1是这句的时间过长。你的片段缓存命中和controller里的查询没关系。
解决方案二:
需要你对每一步的消耗进行分析,搞清楚到底是哪里消耗最大。