Windows 上的 Rails 太慢了(rails -v 需要 4 秒)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4627888/
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
Rails on Windows is so slow (rails -v takes 4 seconds)
提问by user331471
I'm using rails Version 3.0.3 and ruby Version 1.9.2p136 (2010-12-15) on a Intel Core 2 Duo 2,6 Ghz with 4 GB Ram and Windows Vista Business SP2 with no other (heavy) applications running. I have already read that rails development on Windows is slower than on Unices and most people do there for not recommend it but this is silly.
我在 Intel Core 2 Duo 2,6 Ghz 和 4 GB Ram 和 Windows Vista Business SP2 上使用 rails 版本 3.0.3 和 ruby 版本 1.9.2p136 (2010-12-15),没有其他(重)应用程序在运行。我已经读到 Windows 上的 Rails 开发比 Unices 上的要慢,而且大多数人都不推荐它,但这很愚蠢。
I can't think of any good reason for using 4 seconds to display a simple Version number. And rails generate needs up to 10 seconds to complete!
我想不出使用 4 秒来显示简单版本号的任何充分理由。而 rails generate 需要长达 10 秒才能完成!
Something in my setup must be wrong (at least I hope).
我的设置中的某些内容一定是错误的(至少我希望如此)。
Has someone a good idea how to proceed? Thanks in advance!
有人知道如何进行吗?提前致谢!
采纳答案by Luis Lavena
There are a few key points that combined generate the slow performance you're noticing.
有几个关键点结合在一起会产生您注意到的缓慢性能。
- Ruby IO performance (on any version) is up to 3 times slower than Linux counterparts. This is because several unoptimized hops in the Windows codebase of Ruby. This requires further analysis, investigation and optimization not done until today.
- Ruby 1.9.2 produces several
stat()
calls per file been required, which can increase the slowdown of Ruby itself. This is not present in Ruby 1.8.6 or 1.8.7. This is also solved in Ruby 1.9.3 (trunk) not released yet. - Projects like Rails requires around 500 files, which combined with above points make Ruby for Windows the snail lot of folks see.
- Ruby IO 性能(在任何版本上)比 Linux 同类产品慢 3 倍。这是因为 Ruby 的 Windows 代码库中有几个未优化的跃点。这需要进一步的分析、调查和优化,直到今天才完成。
- Ruby 1.9.2
stat()
需要为每个文件生成多次调用,这会增加 Ruby 本身的运行速度。这在 Ruby 1.8.6 或 1.8.7 中不存在。这也在尚未发布的 Ruby 1.9.3 (trunk) 中解决。 - 像 Rails 这样的项目需要大约 500 个文件,结合以上几点,使 Ruby for Windows 成为很多人看到的蜗牛。
Now, there are workaround to that, some simple and some complex ones.
现在,有一些解决方法,一些简单的和一些复杂的。
- Move back to Ruby 1.8.7 instead of Ruby 1.9.2. That will bring again certain level of speed to your application. Unless you're taking advantage of Unicode support, then 1.8.7 could work for you.
- Look into tools like Spork to provide scenario/forking for your RSpec/Cucumber
- Move your development to RAM, using a RAMDisk like ImDisk. Move both Ruby and your application to it and time of loading will be reduced (this is associated with your available RAM too)
- 移回 Ruby 1.8.7 而不是 Ruby 1.9.2。这将再次为您的应用程序带来一定程度的速度。除非您正在利用 Unicode 支持,否则 1.8.7 可能适合您。
- 研究像 Spork 这样的工具来为你的 RSpec/Cucumber 提供场景/分叉
- 使用像ImDisk这样的 RAMDisk 将您的开发转移到 RAM 。将 Ruby 和您的应用程序都移动到它,加载时间将减少(这也与您的可用 RAM 相关联)
Hope some of these options help you.
希望其中一些选项对您有所帮助。
回答by carlosvini
It is faster to use Ruby inside an Ubuntu Virtual Machine than using it directly with Windows.
在 Ubuntu 虚拟机中使用 Ruby 比直接在 Windows 中使用更快。
A good option is to use Vagrant: You develop on your Windows IDE, and files are "shared" with the Ubuntu VM, you run "vagrant ssh", then run "rails server", or any other command you'd like to run. There are other benefits as well:
一个不错的选择是使用 Vagrant:你在 Windows IDE 上开发,文件与 Ubuntu VM“共享”,你运行“vagrant ssh”,然后运行“rails server”,或者你想运行的任何其他命令. 还有其他好处:
- Your don't need to install RVM, or switch ruby versions, just use a VM for each project. VMs can be small, like 500MB of data, using up to 100MB of RAM, but YMMV
- You don't need to worry about gem's compatibility with Windows
- 您不需要安装 RVM 或切换 ruby 版本,只需为每个项目使用一个 VM。VM 可以很小,例如 500MB 的数据,最多使用 100MB 的 RAM,但 YMMV
- 您无需担心 gem 与 Windows 的兼容性
Take a look: http://www.vagrantup.com/
看一看:http: //www.vagrantup.com/
回答by rogerdpack
For a speedup you could try my loader speeder upper (helps rails run faster in Windows): https://github.com/rdp/faster_require
为了加速,你可以试试我的 loader speeder upper(帮助 Rails 在 Windows 中运行得更快):https: //github.com/rdp/faster_require
Also checkout spork, which works in Windows, and jruby also works well.
还可以在 Windows 中查看 spork,而 jruby 也可以很好地运行。
回答by Nick Ginanto
you can try playing with ruby's garbage collecter to make ruby faster, since the defaults variable settings don't match how windows work
您可以尝试使用 ruby 的垃圾收集器来使 ruby 更快,因为默认变量设置与 Windows 的工作方式不匹配
回答by jschorr
More than likely, it's anti-virus affecting it. That combined with Vista's speed issues are probably affecting it. I agree with Justice, run Linux in a VM.
更有可能的是,它是影响它的防病毒软件。这与 Vista 的速度问题相结合可能会影响它。我同意正义,在 VM 中运行 Linux。