windows 我可以做些什么来加速 Rails 开发模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1263664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What can I do to speed up Rails development mode?
提问by user94154
Rails, on development mode is SLOW. Very, very slow. I run Vista, and I set config.cache_classes = true
in development.rb
... But, it's still slow and I have to restart the server after I change my code.
Rails,开发模式很慢。非常非常缓慢。我运行Vista,并且我将config.cache_classes = true
在development.rb
...但是,它仍然是缓慢的,我后,我改变我的代码,以重新启动服务器。
My coworker develops Rails on a Mac and sees similar slowness.
我的同事在 Mac 上开发 Rails 并看到类似的缓慢。
My development time slows down significantly because it takes minutes to test out code changes.
我的开发时间显着减慢,因为测试代码更改需要几分钟。
Is this as good as Rails development gets? Or am I missing something that'll make it fast and my life happy?
这和 Rails 开发一样好吗?还是我错过了一些可以让我的生活变得更快和我的生活快乐的东西?
采纳答案by askegg
Andrews-MacBook-Pro:Sites askegg$ rails test
Andrews-MacBook-Pro:Sites askegg$ cd test
Andrews-MacBook-Pro:test askegg$ ./script/generate model test
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/test.rb
create test/unit/test_test.rb
create test/fixtures/tests.yml
create db/migrate
create db/migrate/20090812005217_create_tests.rb
Andrews-MacBook-Pro:test askegg$ ./script/performance/benchmarker 1000000 Test.new
user system total real
#1 25.140000 0.200000 25.340000 ( 25.549605)
Hmmm. 25 seconds to instantiate 1 million objects in development mode on a macbook pro with 12 other programs loaded. Seems OK to me.
嗯。在加载了 12 个其他程序的 macbook pro 上以开发模式实例化 100 万个对象需要 25 秒。对我来说似乎没问题。
回答by Richard Millan
The rails-dev-boost plugin speeds up Rails development mode. I was having the same problem, and this plugin made my application very snappy (compared to few second load per page). It will run at similar speed as production!
rails-dev-boost 插件加速了 Rails 开发模式。我遇到了同样的问题,这个插件使我的应用程序非常活泼(与每页几秒钟的加载相比)。它将以与生产相似的速度运行!
http://github.com/thedarkone/rails-dev-boost
http://github.com/thedarkone/rails-dev-boost
To install it:
要安装它:
script/plugin install git://github.com/thedarkone/rails-dev-boost
回答by Jeff Whitmire
Are you talking about:
你在说:
Slowness starting the app (like running script/server)?
If it's the server startup, then what server are you using? From my experience webrick is slower than mongrel is slower than thin. Passenger really is the most efficient for local development (though I've never tried to get it running on windows).
启动应用程序很慢(比如运行脚本/服务器)?
如果是服务器启动,那么您使用的是什么服务器?根据我的经验,webrick 比 mongrel 慢,比 Thin 慢。对于本地开发来说,Passenger 确实是最有效的(尽管我从未尝试过让它在 Windows 上运行)。
Slow page responses from hitting the dev server?
This could be inefficient database queries, too much computation in the view that could be reworked, etc. If it's running ok in production this is probably not your issue. However, the web server you run will make a difference in your speed locally as well. I think the same order for startup applies for execution as well.
访问开发服务器时页面响应缓慢?
这可能是低效的数据库查询、视图中可以返工的过多计算等。如果它在生产中运行正常,这可能不是您的问题。但是,您运行的 Web 服务器也会对本地速度产生影响。我认为同样的启动顺序也适用于执行。
Rake tasks taking forever to start?
I've had this issue as well. If you have a large project with lots of plugins (which means lots of initialization that needs to run), it can take a while to ramp up the rails environment. There are things that will probably speed it up, but there's no silver bullet. Make sure you don't have any plugins installed you are no longer using, take a careful look at your environment and initializers to make sure it's in good shape, etc.
耙任务需要永远开始?
我也遇到过这个问题。如果您有一个包含大量插件的大型项目(这意味着需要运行大量初始化),则可能需要一段时间来提升 rails 环境。有些事情可能会加快速度,但没有灵丹妙药。确保您没有安装任何不再使用的插件,仔细查看您的环境和初始化程序以确保它处于良好状态等。
Bottom line being, stating "Rails is slow in development" doesn't really pinpoint the problem. If you can clarify what is slow, then you can get specific help to speed it up. I've worked on lots of pretty large projects that have suffered from performance issues in development as well as production. I've never had a situation that couldn't be improved if given the right attention. Pinpoint the problem and you can usually diagnose a better solution to speed things up.
底线是,声明“Rails 开发缓慢”并不能真正指出问题所在。如果你能澄清什么是缓慢的,那么你可以获得特定的帮助来加速它。我曾参与过许多大型项目,这些项目在开发和生产中都存在性能问题。如果给予适当的关注,我从来没有遇到过无法改善的情况。查明问题,您通常可以诊断出更好的解决方案来加快速度。
回答by rogerdpack
faster_require
更快_需要
http://github.com/rdp/faster_require
http://github.com/rdp/faster_require
might help
可能有帮助
speeds mine up significantlyon windows
在 Windows上显着加快挖掘速度
also spork can be used with jruby to speed up unit tests
spork 也可以与 jruby 一起使用来加速单元测试
回答by Carlos
I have been running into the same issues. My app, in dev mode, keeps getting slower and slower. As an example, I create a new controller with a new action:
我一直遇到同样的问题。我的应用程序在开发模式下越来越慢。例如,我创建了一个带有新操作的新控制器:
def test
render :text => 'nothing'
end
In dev mode, this takes between 12-15 seconds to complete (when requesting via FF and IE). I am using mongrel (not clustered). I am on a macbook pro.
在开发模式下,这需要 12-15 秒才能完成(当通过 FF 和 IE 请求时)。我正在使用杂种(非集群)。我在 macbook pro 上。
In prod mode this takes ~130ms.
在生产模式下,这需要大约 130 毫秒。
There has to be a way to find out which files are being loaded per request (basic profiling) so I can try to figure out what is going on and where the bottleneck is.
必须有一种方法可以找出每个请求正在加载哪些文件(基本分析),以便我可以尝试找出发生了什么以及瓶颈在哪里。
FF Firebug Net shows that most of the time (11-14 seconds) are spent in WAIT state.
FF Firebug Net 显示大部分时间(11-14 秒)都花费在 WAIT 状态。
Console shows:
控制台显示:
Completed in 2ms (View: 0, DB: 152)
.
.
Any ideas?
有任何想法吗?
回答by Akshay Mohite
The best wayto make development faster is installing gem
named active_reload
.
加快开发速度的最佳方法是安装gem
named active_reload
。
To install this gem
, you can enter command,
要安装它gem
,您可以输入命令,
gem install active_reload
gem install active_reload
And, in your rails project gemfile, add
并且,在您的 rails 项目 gemfile 中,添加
gem 'active_reload'
gem 'active_reload'
Then, restart your server and you will find development mode much faster than it used to be.
然后,重新启动您的服务器,您会发现开发模式比以前快得多。
回答by scottburton11
I arrived at this post trying to understand why I was seeing so much time between requests in development mode.
我来到这篇文章试图理解为什么我在开发模式下看到请求之间的时间如此之长。
I'm working on a modest-size application - 4000 LOC, 113 classes - and slumming it on a slow machine. More than 9/10ths of the time between requests happens while loading model code.
我正在开发一个中等大小的应用程序 - 4000 LOC,113 个类 - 并在一台慢速机器上运行它。超过 9/10 的请求之间的时间发生在加载模型代码时。
Predictably, config.cache_classes = true speeds things up considerably.
可以预见, config.cache_classes = true 大大加快了速度。
回答by Will Tomlins
Setting config.cache_classes = true in development.rb will always speed up larger apps in dev mode. I like to have this line in my dev environment:
在 development.rb 中设置 config.cache_classes = true 将始终在开发模式下加速较大的应用程序。我喜欢在我的开发环境中有这一行:
config.cache_classes = ENV["CACHE_CLASSES"] ? ENV["CACHE_CLASSES"] == "true" : false
Then you can start your server with:
然后您可以使用以下命令启动服务器:
CACHE_CLASSES=true script/server
when you want faster response time and don't mind that the classes don't reload on each request.
当您想要更快的响应时间并且不介意这些类不会在每个请求上重新加载时。
回答by Tim Fletcher
If you're using versions 3.0 or 3.1 of Rails you can use active reloadto speed up page load times condsiderably. It was rolled into Rails 3.2.
如果您使用的是 Rails 3.0 或 3.1 版,您可以使用主动重新加载来显着加快页面加载时间。它被纳入到 Rails 3.2 中。
回答by Sean Clark Hess
I'm assuming your requests are taking seconds? (Otherwise you probably wouldn't have noticed). It has always been fast for me. Especially since I started using sinatra instead of rails :D
我假设您的请求需要几秒钟?(否则你可能不会注意到)。对我来说一直很快。特别是自从我开始使用 sinatra 而不是 rails :D
Oh, and I forgot to mention - I used to run rails locally, but I currently use a virtual centos server with VMWare. Both were fast
哦,我忘了提及 - 我曾经在本地运行 rails,但我目前使用带有 VMWare 的虚拟 centos 服务器。两者都很快
回答by Thilo
I set config.cache_classes = true in development.rb. It's still slow and I have to restart the server after I change my code.
我在 development.rb 中设置了 config.cache_classes = true。它仍然很慢,我必须在更改代码后重新启动服务器。
You should not use that cache in development (especially if it is still slow when using it). Having to restart the server all the time will slow you down even more.
您不应该在开发中使用该缓存(尤其是在使用它时仍然很慢的情况下)。必须一直重新启动服务器会使您的速度更慢。
Are you sure Ruby itself is slow? Not for example some DB access code that you run? Is a simple "Hello World" demo equally slow?
你确定 Ruby 本身很慢吗?不是例如您运行的某些数据库访问代码?一个简单的“Hello World”演示是否同样慢?
And how slow are we talking? Page load times more than 10 seconds?
我们说话的速度有多慢?页面加载时间超过 10 秒?