我正在使用Rails 3.2.x和Thin 1.5.0,并且在最初加载我的应用程序时,在24小时未加载后,它需要很长时间。起初我以为这只是我的macbook - 因为它处于睡眠模式,并且它第一次因为某种原因而永远消失。
但是,我意识到它在Heroku上也是如此,对其他人也是如此。就像当他们没有访问Heroku网站一段时间时,他们第一次加载它(不是每次都有,但有时候)它需要永远。
根据日志,似乎我的样式表的编译需要永远。但令我困惑的是,当我推送到Heroku时,它应该在推送期间编译资产......对吗?因此,从理论上讲,这不应该是减缓生产速度的因素。或者我错过了什么?
虽然最近,Heroku一直拒绝推送,所以我不得不启用它:
# Don't initialize app on pre-compile
config.assets.initialize_on_precompile = false
所以我不确定这是否有助于它。
Started GET "/" for 127.0.0.1 at 2013-02-19 02:44:14 -0500
Processing by HomeController#index as HTML
Category Load (56.6ms) SELECT "categories".* FROM "categories" LIMIT 6
EXPLAIN (14.6ms) EXPLAIN QUERY PLAN SELECT "categories".* FROM "categories" LIMIT 6
EXPLAIN for: SELECT "categories".* FROM "categories" LIMIT 6
0|0|0|SCAN TABLE categories (~1000000 rows)
Banner Load (44.4ms) SELECT "banners".* FROM "banners" INNER JOIN "banner_types" ON "banner_types"."id" = "banners"."banner_type_id" WHERE (banner_types.name = 'Featured')
Banner Load (0.3ms) SELECT "banners".* FROM "banners" INNER JOIN "banner_types" ON "banner_types"."id" = "banners"."banner_type_id" WHERE (banner_types.name = 'Side')
Product Load (3.4ms) SELECT "products".* FROM "products"
Vendor Load (15.9ms) SELECT "vendors".* FROM "vendors"
User Load (50.0ms) SELECT "users".* FROM "users"
EXPLAIN (0.1ms) EXPLAIN QUERY PLAN SELECT "users".* FROM "users"
EXPLAIN for: SELECT "users".* FROM "users"
0|0|0|SCAN TABLE users (~1000000 rows)
Vendor Load (0.3ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 12 LIMIT 1
Vendor Load (0.2ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
Vendor Load (0.2ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 10 LIMIT 1
CACHE (0.0ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 12 LIMIT 1
CACHE (0.0ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 12 LIMIT 1
CACHE (0.0ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 10 LIMIT 1
Rendered home/_popular_products.html.erb (303.0ms)
Rendered home/_popular_stores.html.erb (2.4ms)
Rendered home/index.html.erb within layouts/application (570.6ms)
Compiled main.css (20360ms) (pid 86898)
Compiled application.css (2366ms) (pid 86898)
Rendered layouts/_login_nav.html.erb (1.0ms)
Rendered layouts/_navigation.html.erb (1.7ms)
Rendered layouts/_header.html.erb (47.3ms)
Rendered layouts/_messages.html.erb (0.2ms)
Rendered layouts/_footer.html.erb (0.5ms)
Completed 200 OK in 38402ms (Views: 30707.1ms | ActiveRecord: 1830.8ms)
思想?
修改1:
请注意,此问题尚未得到充分解答。回答都谈到了Heroku上的问题 - 这是问题的一部分。但是,他们未能解决开发过程中发生的这个问题。
答案 0 :(得分:2)
如果在一定时间内没有访问,Heroku会降低您的应用程序以节省资源。因此,必须再次启动整个应用程序会导致缓慢。
有关详细信息,请参阅https://devcenter.heroku.com/articles/dynos上的Dyno空闲。
为了解决这个问题,您可以使用New Relic插件等服务,这些服务会经常ping您的应用,以阻止旋转。
您还应该在部署时编译资产,而不是按需编译。 Heroku默认情况下应该这样做 - 你改变了什么来阻止它发生?
答案 1 :(得分:1)
如果你在Heroku上只有1个dyno(免费计划),那么它会在一段时间后闲置以节省资源。然后,当有人在一段时间后访问您的应用程序时,它将再次启动。
因此,访问您应用的第一个人必须等待一段时间。