如何使 Rails 3 资源预编译速度更快?
我有一个正在运行的 Rails 3.2.1 应用程序,我正在通过 Capistrano 使用运行 deploy:assets:precompile
任务的 deploy/assets
进行部署。
一切工作都很好,除了编译本身非常慢。我没有那么多 CSS 和 JavaScript(总共大约 8200 行)。
编译资产一般需要1-3分钟左右,约占整个部署时间的90%。
有什么办法可以优化这个吗?也许使用不同的程序来编译资产或以某种方式优化它?
我在 1.9.2-p290、Rails 3.2.1 的 Linode 512 上运行该应用程序,并使用 therubyracer
gem(如果有任何相关性的话)。
I have a running Rails 3.2.1 application, that I'm deploying via Capistrano with the deploy/assets
which runs the deploy:assets:precompile
task.
Everything works just fine, except that the compilation itself is really slow. I don't have that much CSS and JavaScript (about 8200 lines total).
It generally takes about 1-3 minutes to compile the assets, which is about 90% of the whole deployment time.
Is there any way to optimize this? Maybe use a different procedure to compile the assets or somehow optimize it?
I'm running the app on Linode 512 on 1.9.2-p290, Rails 3.2.1 and using therubyracer
gem if that's of any relevance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不是让它运行得更快的答案,但就“不同的过程”而言,您可以告诉 Capistrano 仅在您实际对资产进行任何更改时才预编译资产。您可能想要执行类似这样的自定义
assets:precompile
任务,该任务将查看现有代码和新部署代码之间的 git 日志。对我来说,这非常有效,现在我只需要在更新资产时处理缓慢的部署:来源:http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/
This isn't an answer on making it run faster, but as far as a "different procedure" goes, you can tell Capistrano to only precompile assets when you've actually made any changes to your assets. You would want to do a custom
assets:precompile
task something like this, which would look at the git logs between the existing and newly deployed code. For me, this worked great and now I only need to deal with slow deployment when updating assets:Source: http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/
我刚刚在 Rails 中编写了一个 gem 来解决这个问题,名为 turbo-sprockets-rails3。它仅重新编译更改的文件,并且仅编译一次即可生成所有资产,从而加快您的
assets:precompile
速度。它在 Capistrano 中开箱即用,因为您的资产目录在版本之间共享。如果您能帮我测试 turbo-sprockets-rails3 gem,那就太好了,并告诉我如果你有任何问题。
I've just written a gem to solve this problem inside Rails, called turbo-sprockets-rails3. It speeds up your
assets:precompile
by only recompiling changed files, and only compiling once to generate all assets. It works out of the box for Capistrano, since your assets directory is shared between releases.It would be awesome if you could help me test out the turbo-sprockets-rails3 gem, and let me know if you have any problems.