Rails 3.1 on Ubuntu 11.10 under VirtualBox is very slow

I have a VirtualBox with Ubuntu 11.10 on Windows7. I run Rails 3.1 on webrick (rails s) and navigate to the VirtualBox IP address (192.168.2.xxxhaps000) from a browser on Windows. At this moment I am facing problems: the page loads very slowly, on the Rails console I see how slowly it responds with files (css, js, images): up to 5 seconds for each! But: if I go 0.0.0.0 opin000 inside Ubuntu - it works fine.

Where is the problem? Where to look for a solution?

+4
source share
6 answers

As mentioned above, this seems to be a duplicate of another problem, although this issue specifically mentions webrick and Remote Desktop Connection, none of which I was looking for since I did not know that this was specific to webrick.

Therefore, I think it should be noted that this is NOT the wrong setting for the parameters of a virtual machine or BIOS, or something like that. This is strictly a problem with the case. Other services work very well if they are not trying to perform reverse DNS queries.

The problem is related to the default setting for Webrick to try to do a reverse DNS lookup, which has problems when the lookup fails, as it tends to work consistently for me on my local machine.

There are several ways to fix this.

Hack / etc / hosts

First, hack /etc/hosts so that your client machine has a record. Hacking /etc/hosts is semi-mobile, but basically it is figuring out what is the IP address of your host machine and adding a line to your /etc/hosts . This requires root privileges.

  • Get your IP address - this will be visible in the Rails console when the request is made and will look something like this: Started GET "/" for 10.0.2.2 at Tue Aug 21 11:33:23 -0700 2012 - in this case the IP address will be 10.0.2.2.
  • Add a line to /etc/hosts to identify this IP address: 10.0.2.2 Nerdmaster

Everything should be fine!

Disable daemon

This seems to work for some ubuntu users:

service avahi-daemon stop

Given that you are killing the service, there may be other applications that have problems. This is probably best as a temporary measure, but not permanent, but I know little about the service, so don’t think about it :)

It also requires root privileges.

Hack webrick

I really despise the Ruby kernel hacker code, which I have to re-crack with every update, but this is what many people do:

  • Find webrick/config.rb
    • Could be in /usr/lib/ruby/[version]/webrick/config.rb if you use regular Ruby
    • If you use RVM, you need to find the appropriate ruby ​​directory, for example. /home/username/.rvm/rubies/[version]/lib/ruby/[version]/webrick/config.rb
    • I don't know jack about other options like rbenv
    • In the worst case, try find / -type d -name "webrick"
  • Edit in your favorite editor (obviously it will be vim)
    • Find :DoNotReverseLookup => nil .
    • Change nil to true .
    • If you do not see this option, you may need to use /etc/hosts hack above.

If you are not using rvm or something similar, this will require root permissions.

Do not use webrick

I don't think this is a real solution, as webrick is sometimes your best (or at least the fastest) option, but you can try a different server. Thin and mongrel seem to have good support and, based on what others say with this problem, do not seem to do a reverse DNS lookup. I have not tried these approaches, so I don’t know exactly how good they are.

This can be done without root permissions.

+5
source

Modify your gemfile to add:

 gem 'mongrel' bundle install rails s -> will use mongrel instead of webrick and be lightning fast. 
+1
source

For me, the slowness of Rails 4 (1 second + for each asset 304) in the Ubuntu guest virtual machine turned out to be shared folders . It was discovered that the reason for this flow , disconnecting from shared folders fixed the speed for me.

+1
source

I liked Scott's answer simply by switching to mongrel, but if you are using the modern version of ruby ​​(> 1.9.1), mongrel is no longer supported. ( Install Mongrel in Ruby 1.9.3 )

I switched to thin - http://code.macournoyer.com/thin/

sudo gem install thin

thin start

and it is very fast for me.

0
source

I use Windows10 home edition with 8 ram, 250g ssd, when I run Rails4.x (thin) on a virtual box with ubuntu 16 server, I found that the rendering time is very slow, mainly up to 4 - 5 seconds, finally I moved rails project from the host shared folder in Virtualbox vm inside, now it has become faster.

0
source

Try disabling the firewall or antivirus in Windows.

-1
source

Source: https://habr.com/ru/post/1388486/


All Articles