对Rails应用程序的第一个请求非常慢 [英] First request to Rails app is very slow

查看:82
本文介绍了对Rails应用程序的第一个请求非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails应用程序的第一个请求(工作会话)总是滞后。切换到生产模式
无济于事。

always the first request (of a working session) to my Rails app is lagging. Switching to production mode doesn't help.

我使用mongrel,其他请求以可接受的速度处理。

I use mongrel and the other requests are handled with acceptable speed.

如何让它更快?

问候

推荐答案

如果您在处理第一个请求时发布了日志的内容,那么也许我们可以弄清楚是什么让它变得如此之慢。例如,这是我的日志,因为第一个用户访问该站点

If you post the contents of the log as that first request is processed then perhaps we can figure out what's making it so slow. For example, this is my log as the first user accesses the site

Booting Mongrel (use 'script/server webrick' to force WEBrick)    
Rails 2.1.0 application starting on http://0.0.0.0:3000    
Debugger enabled    
Call with -d to detach    
Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_type.rb:66: warning: already initialized constant CSV
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.5 available at 0.0.0.0:3000
** Use CTRL-C to stop.


Processing SessionsController#new (for 127.0.0.1 at 2009-05-26 12:26:00) [GET]
  Session ID: de2acf074759026e1ed6205724f547a9
  Parameters: {"action"=>"new", "controller"=>"sessions"}
Rendering sessions/new
Completed in 0.00587 (170 reqs/sec) | Rendering: 0.00298 (50%) | DB: 0.00092 (15%) | 200 OK [http://localhost/]

我认为170 reqs / sec适合我们的应用但其他人可能会觉得这很慢。您可以从统计信息中看到rails提供了所需的一半时间用于呈现响应 - 在这种情况下为登录屏幕生成HTML。如果这个请求花了很长时间,我的第一个停靠点就是与登录界面相关联的视图和助手。

I think 170 reqs/sec is fine for our app but others may find that slow. You can see from the stats that rails provides that half of the time required is spent rendering the response - in this case generating the HTML for the login screen. If this request was taking a long time, my first port of call would be the views and helpers associated with the login screen.

如果你有一个系统需要一个很长一段时间初始化自己的第一个请求,然后为什么不偷偷摸摸,编写自己的启动程序,首先运行rails,然后发送一个虚假的请求通过curl。这样,您的用户永远不会看到问题。

If you do have a system that takes a long time to initialize itself on the very first request then why not be sneaky and write your own startup program which first runs rails and then sends a fake request in via curl. That way your users never see the problem.

Chris

这篇关于对Rails应用程序的第一个请求非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆