在Rails 3中缓慢加载应用程序

时间:2012-01-21 00:43:31

标签: ruby-on-rails ruby-on-rails-3 environment performance

我有一个基于Rails 3(版本Rails 3.1.2)和ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]的应用。应用程序的加载速度很慢,现在,当我尝试它时,我等待 23秒,而不是加载索引页面。它与Heroku上的相同,就像在localhost上一样。

我在SO上发现了类似的主题,但不幸的是我找不到可以解决我问题的解决方案。在我读过的博客的某个地方,可能会引起这个问题,因为这个页面没有长时间访问过。

但是再一次 - 我找不到解决方案...所以我想问你,如果过去有人已经有这个问题并且有解决方案,我会非常感激。

非常感谢。

编辑 - Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.2'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'mysql2'
gem "rvm", "~> 1.9.2"
gem 'authlogic'
gem "rake", "0.8.7"
gem 'json'
gem "declarative_authorization", "~> 0.5.3"
gem "ancestry", "~> 1.2.4"
gem "taps", "~> 0.3.23"
gem "paperclip", "~> 2.4.5"
gem 'aws-s3'
gem "awesome_print", "~> 1.0.1"
gem 'actionmailer'
gem 'wkhtmltopdf-binary'
gem 'rails3-jquery-autocomplete'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.5.rc.2'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

group :production do
  gem 'therubyracer-heroku', '0.8.1.pre3'
  gem 'pg'
end



gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

EDIT2 - 使用过的宝石的版本:

Using rake (0.8.7) 
Using multi_json (1.0.4) 
Using activesupport (3.1.2) 
Using builder (3.0.0) 
Using i18n (0.6.0) 
Using activemodel (3.1.2) 
Using erubis (2.7.0) 
Using rack (1.3.6) 
Using rack-cache (1.1) 
Using rack-mount (0.8.3) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.2) 
Using actionpack (3.1.2) 
Using mime-types (1.17.2) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.3.0) 
Using actionmailer (3.1.2) 
Using arel (2.2.1) 
Using tzinfo (0.3.31) 
Using activerecord (3.1.2) 
Using activeresource (3.1.2) 
Using ancestry (1.2.4) 
Using authlogic (3.1.0) 
Using awesome_print (1.0.2) 
Using xml-simple (1.1.1) 
Using aws-s3 (0.6.2) 
Using bundler (1.0.21) 
Using cocaine (0.2.1) 
Using coffee-script-source (1.2.0) 
Installing execjs (1.3.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.6.5) 
Using rdoc (3.12) 
Using thor (0.14.6) 
Using railties (3.1.2) 
Using coffee-rails (3.1.1) 
Installing declarative_authorization (0.5.5) 
Using jquery-rails (1.0.19) 
Using mysql2 (0.3.11) 
Using paperclip (2.4.5) 
Using rails (3.1.2) 
Using rails3-jquery-autocomplete (1.0.5) 
Using rest-client (1.6.7) 
Using rvm (1.9.2) 
Using sass (3.1.12) 
Using sass-rails (3.1.5) 
Using sequel (3.20.0) 
Using sinatra (1.0) 
Using sqlite3 (1.3.5) 
Using sqlite3-ruby (1.3.3) 
Using taps (0.3.23) 
Using uglifier (1.2.2) 
Using wkhtmltopdf-binary (0.9.5.3) 

2 个答案:

答案 0 :(得分:1)

正如我发现的,问题出在Heroku的dynos上。如果你使用Heroku免费,你已经分配了1个dyno。当没有人在一段时间内(例如1小时)访问您的页面时,所以这个dyno是空闲​​的 - >这就是长时间加载页面的原因。

如果您购买第二个dyno(每月35美元),那么dyno将永远不会闲置,我们永远不会遇到“缓慢负载”的情况。

答案 1 :(得分:0)

我认为这是因为你正在使用旧版本的宝石。请将所有宝石更新为最新版本,然后重试。当我遇到类似问题时,它会帮助我。