“耙路线”应该多长时间?跑步?
我刚刚开始使用 Rails,所以请原谅我提出相当基本的问题。我已经注意到,每次运行 rake paths 命令时都需要一段时间才能执行。我有 3 个控制器的大约 20 条路线,执行大约需要 40 秒。
这正常吗?我怎样才能加快速度?
PS:我使用的是带有 Rails 3.1.3 的 Windows 7(使用 Rails Installer 设置)。
I just started out with Rails, so excuse my fairly basic question. I am already noticing that the rake routes
command takes a while to execute everytime I run it. I have about 20 routes for 3 controllers and it takes about 40 seconds to execute.
Is that normal? How could I speed this up?
P.S.: I am on Windows 7 with Rails 3.1.3 (set up with Rails Installer).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
rake 路由任务取决于加载 Rails 环境并需要数千个 Ruby 文件的环境任务。
Rails 环境的启动时间和相应的 rake 路由执行时间非常接近(在我的 Linux on-steroids-laptop 上,Rails 应用程序有大约 50 个路由):
没有简单的方法来减少启动时间,因为它依赖于您的解释器需要脚本文件的方式: http://rhnh.net/2011/05/28/speeding-up-rails-startup-time
The rake routes task depends on the environment task which loads your Rails environment and requires thousands of Ruby files.
The startup time of a Rails environment and the corresponding rake routes execution time are very close (on my Linux on-steroids-laptop with a Rails application with ~ 50 routes):
There is no easy way to decrease startup time as it relies on the way your interpreter requires script files : http://rhnh.net/2011/05/28/speeding-up-rails-startup-time
我想出了一个每次运行大约 8 秒的
rake paths
解决方案。它是一个简单的基于文件的缓存,运行bundle exec rake paths
,将输出存储在 tmp 下的文件中。文件名是config/routes.rb
的 md5 哈希,因此如果您进行更改并将其改回来,它将使用旧的缓存文件。我将以下 bash 函数放入一个名为
fastroutes
的可执行文件中:这是一个 github 链接 也是如此。
这样,您只需生成一次路由,然后
fastroutes
将使用缓存的值。I came up with a solution to
rake routes
taking about 8 seconds to run every time. It's a simple file based cache that runsbundle exec rake routes
, stores the output in a file under tmp. The filename is the md5 hash ofconfig/routes.rb
, so if you make a change and change it back, it will use the old cached file.I put the following bash functions in an executable file I call
fastroutes
:Here's a github link too.
This way, you only have to generate the routes once, and then
fastroutes
will used the cached values.这看起来有点长,但是您真的需要那么频繁地运行 rake 路由吗?在我的系统 OSX Lion/Rails 3.2.0 上,
rake paths
需要大约 10 秒。That seems a bit long, but do you really need to run
rake routes
that often? On my system, OSX Lion/Rails 3.2.0,rake routes
takes ~10s.在你的 Rakefile 中:
In your Rakefile:
Rails 环境需要花费更多时间才能在 Windows 上加载。我建议您尝试一下 Unix,例如 Ubuntu,因为 Windows 是运行和开发 Ruby on Rails 应用程序的最差环境。但如果您只是尝试 Rails,Windows 就足够了:)
Rails environment takes a huge more amount of time to be loaded on Windows. I recommend you to give Unix a try, like Ubuntu, as Windows is the worst environment in which you can run and develop Ruby on Rails applications. But if you are just trying Rails, Windows is enough :)