[英]Rails 3.1 on Ubuntu 11.10 under VirtualBox very slow
I have VirtualBox with Ubuntu 11.10 on Windows7. 我在Windows7上安装了带有Ubuntu 11.10的VirtualBox。 I run Rails 3.1 on webrick (rails s) and go to VirtualBox's IP adress (192.168.2.xxx:3000) from browser on Windows.
我在webrick(rails s)上运行Rails 3.1并从Windows上的浏览器转到VirtualBox的IP地址(192.168.2.xxx:3000)。 At this moment I face troubles - page loads very very slowly, on Rails console i see how slowly it responses files (css, js, images): up to 5 seconds for each!
此刻我遇到麻烦 - 页面加载速度非常慢,在Rails控制台上我看到它响应文件的速度有多慢(css,js,images):每个最多5秒! But: if I go 0.0.0.0:3000 inside Ubuntu - it works perfect.
但是:如果我在Ubuntu中去0.0.0.0:3000 - 它完美无缺。
Where is the problem? 问题出在哪儿? Where to look for a solution?
在哪里寻找解决方案?
As mentioned above, it appears this is a duplicate of another issue, though that issue specifically mentions webrick and a remote desktop connection, neither of which was I looking for, as I didn't know it was specific to webrick. 如上所述,它似乎是另一个问题的重复,虽然该问题特别提到了webrick和远程桌面连接,我都没有找到,因为我不知道它是webrick特有的。
So I think it should be noted that this is NOT a misconfiguration of the virtual machine or BIOS settings or anything like that. 所以我认为应该注意的是,这不是虚拟机或BIOS设置或类似设置的错误配置。 This is strictly a webrick issue.
这绝对是一个问题。 Other services work just fine if they aren't trying to do reverse DNS lookups.
如果他们不尝试进行反向DNS查找,其他服务也可以正常工作。
The problem stems from Webrick's default setting to try and do a reverse DNS lookup, which has issues when the lookup fails, as it tends to do consistently for me on my local machine. 问题源于Webrick的默认设置,即尝试进行反向DNS查找,这在查找失败时会出现问题,因为它往往会在我的本地计算机上始终如一地执行。
There are a few ways to fix this. 有几种方法可以解决这个问题。
The first is to hack /etc/hosts
so your client machine has an entry. 第一种是破解
/etc/hosts
这样你的客户端机器就有了一个条目。 Hacking /etc/hosts
is semi-advanced, but basically amounts to figuring out what you host machine's IP address is and adding a line to your /etc/hosts
file. 黑客
/etc/hosts
是半高级的,但基本上相当于计算你主机的IP地址是什么,并在/etc/hosts
文件中添加一行。 This requires root-level permissions. 这需要根级权限。
Started GET "/" for 10.0.2.2 at Tue Aug 21 11:33:23 -0700 2012
- in this case, the IP address is 10.0.2.2. Started GET "/" for 10.0.2.2 at Tue Aug 21 11:33:23 -0700 2012
- 在此case,IP地址是10.0.2.2。 /etc/hosts
to identify that IP address: 10.0.2.2 Nerdmaster
/etc/hosts
添加一行以标识该IP地址: 10.0.2.2 Nerdmaster
All should be well! 一切都应该好!
This seemed to work for some ubuntu users: 这似乎适用于一些ubuntu用户:
service avahi-daemon stop
Given you're killing a service, there may be other apps which have issues. 鉴于您正在查杀服务,可能还有其他应用程序存在问题。 This is probably best as a temporary measure, not a permanent one, but I know very little about the service, so avoid taking my word for this one :)
这可能是最好的临时措施,而不是永久措施,但我对服务知之甚少,所以不要相信我的话:)
This also requires root-level permissions. 这还需要根级权限。
I really despise hacking core Ruby code that I have to re-hack on every update, but this is what a lot of people do: 我真的很鄙视黑客核心Ruby代码,我必须在每次更新时重新破解,但这是许多人所做的:
webrick/config.rb
webrick/config.rb
/usr/lib/ruby/[version]/webrick/config.rb
if you're running a normal Ruby /usr/lib/ruby/[version]/webrick/config.rb
如果你正在运行一个普通的Ruby /home/username/.rvm/rubies/[version]/lib/ruby/[version]/webrick/config.rb
/home/username/.rvm/rubies/[version]/lib/ruby/[version]/webrick/config.rb
find / -type d -name "webrick"
find / -type d -name "webrick"
:DoNotReverseLookup => nil
. :DoNotReverseLookup => nil
。 nil
to true
. nil
更改为true
。 /etc/hosts
hack above. /etc/hosts
hack。 If you aren't using rvm or something similar, this will require root-level permissions. 如果您不使用rvm或类似的东西,这将需要根级权限。
I don't think this is a real solution, as webrick is sometimes your best (or at least quickest) option, but you can try a different server. 我不认为这是一个真正的解决方案,因为webrick有时候是你最好的(或者至少是最快的)选项,但是你可以尝试不同的服务器。 Thin and mongrel seem to have good support and, based on what others with this problem are saying, appear not to do a reverse DNS lookup.
瘦和杂种似乎有很好的支持,并根据这个问题的其他人说,似乎不进行反向DNS查找。 I haven't tried these approaches, so I don't know for sure how good they are.
我没有尝试过这些方法,所以我不确定它们有多好。
This can be done without root-level permissions. 这可以在没有根级权限的情况下完成。
For me the slowness of Rails 4 (1 second+ for each asset 304) on an Ubuntu guest VM turned out to be Virtualbox shared folders . 对我来说,Ubuntu来宾VM上的Rails 4(每个资产304的1秒+)的缓慢结果是Virtualbox共享文件夹 。 Found that cause in this thread , moving away from shared folders fixed the speed issue for me.
发现原因在这个线程中 ,远离共享文件夹为我修复了速度问题。
我正在使用带有8 ram,250g ssd的windows10家庭版,当我在ubuntu服务器16的虚拟盒子上运行Rails4.x(瘦)时,我发现渲染时间非常慢,大多长达4 - 5秒,最后我感动了rails项目从主机共享文件夹到Virtualbox vm里面,现在变得非常快。
Edit your Gemfile to add: 编辑您的Gemfile以添加:
gem 'mongrel'
bundle install
rails s -> will use mongrel instead of webrick and be lightning fast.
I liked Scott's answer of just switching to mongrel, but if you're using a modern version of ruby (> 1.9.1), mongrel is no longer supported. 我喜欢Scott的回答只是转换为mongrel,但如果你使用现代版本的ruby(> 1.9.1),则不再支持mongrel。 ( Install Mongrel in Ruby 1.9.3 )
( 在Ruby 1.9.3中安装Mongrel )
I switched over to thin - http://code.macournoyer.com/thin/ 我切换到瘦 - http://code.macournoyer.com/thin/
sudo gem install thin
sudo gem安装瘦
thin start
薄的开始
and it's super snappy for me. 这对我来说非常活泼。
尝试在Windows上关闭防火墙或防病毒软件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.