I ran into an issue where a Rails 3.1 application running on Ubuntu 12.04 in a VirtualBox instance (development) was running ridiculously slow. Sometimes, before the server would register a request, it would take >5 seconds, then another 5 seconds just to load a simple view.
Obviously, this is an unacceptable amount of time when testing new functionality.
There are two things you can do to make your implementation much faster. The first is relatively easy, the second is a little more complicated.
First thing to do: Fix Webrick
Webrick is performing a reverse DNS lookup. You wouldn’t think this would be an issue, but it is – and it can cause the server to not respond for a non-negligible amount of time, causing slight insanity. To resolve, open your webrick configuration file:
or if you are using RVM:
Locate the DoNotReverseLookup setting and change it from nil to true.
This will significantly increase your server’s response time. However, you’re still not going to be moving fast enough if you are working within a VirtualBox shared directory with your host operating system. This is also slowing you down, as vboxsf is causing a read bottleneck. You can also experience this speed degradation when doing a git status or similar request.
Second thing to do: Move your files to a non vboxsf shared directoy
This isn’t as complicated as it might seem. You’re probably thinking, “how am I supposed to edit my files from my host operating system if my files are located in a non-shared location”. It’s simple:
sudo apt-get install samba
Now, update the configuration file:
sudo nano -w /etc/samba/smb.conf
- Change “Workgroup” to something more relevant to what you are doing.
- Search for the “security = user” setting and change it
- Create a new section at the bottom of the file, like this:
comment = Ubuntu File Server Share (say whatever you want)
path = /srv/samba/share
browsable = yes
guest ok = yes
read only = no
create mask = 0755
Now, create the directory which you are pointing to
sudo mkdir -p /srv/samba/share
sudo chwon nobody.nogroup /srv/samba/share
sudo restart smbd
sudo restart nmbd
You should now be able to locate your new shared guest->host shared directory within your Windows network, along with the shared folder structure.
You can now edit the files within your host operating system and run a super fast Rails webrick implementation. You’ll also find that your Git requests are super quick as well.