Rails VERY slow in development using Ubuntu VVM - ruby-on-rails

I have the following config
Ubuntu server 10.04 running on a VirtualBox VM (RAM and cpu usage are low)
ruby 1.9.3
rails 3.2.12
webrick
If I do any of the things below the system seems to wait for about 15 seconds before executing the command
- rake taks
- rails s
- navigating to a new page in the app
Things I have looked at
- this is before the sprockets section, and does the same with rake, so at the moment I am not looking at things such as dev-tweaks
- I have changed the webrick config.rb to have the line :DoNotReverseLookup => true
- I have host entries for my host machine on the VM. ping is very fast between both machines
- I have tried Thin and experienced the same issue. I haven't tried mongrel but am thinking I will see the same
But still it is excruciatingly slow.
Any thoughts?
Michael

If you're using VirtualBox shared folders (vboxfs), disk I/O is probably the issue.
vboxfs is really slow, and Ruby on Rails does a lot of files operations in development mode (checking if any files changed etc.).
If you're not using Windows, sharing folders with NFS is the way to go.
Check this link:
http://meta.discourse.org/t/shared-folder-performance-on-vagrant/2443/14

I had this issue using VirtualBox shared folders. As soon as I switched to NFS, I couldn't really make a difference between running natively or in the VM. I imagine Rails autoloading in dev mode is the culprit here. See here on how to configure vagrant to use NFS: https://coderwall.com/p/uaohzg
If you can't setup NFS properly (on OSX 10.7 I had to install NFS Manager to make it work), you can always script away and rsync your rails folder every time you modify files locally in your editor. You don't want to run rails on a VirtualBox shared folder.

Related

Vagrant Workflow - vagrant ssh, vagrant destroy, vagrant up commands

I am having some trouble understanding the vagrant workflow from their website.
I had previously been working on a project and had gone through the whole process of changing directory and setting up the vagrant box, etc. I had even run bundle install that installed all of the gems of the forked project I am working on. I configured the web server to work and was even able to go to see the project on my browser through the web server connection.
Later on I had to go get dinner so I did
vagrant destroy
When I returned, in the same directory I ran
vagrant up
Then I did
vagrant ssh
followed by
cd /vagrant
when I get here I run
rails s
and I get the following error:
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Shouldn't running vagrant up remember all of the work I had previously done? Or do I have to restart from scratch and rebuild all of my gems every time? Am I missing something?
vagrant destroy does literally what the command says - destroys started up VM, completely with disc images. Every change (i.e. installation of software, results of running bundle install, etc) is lost, beyond the changes that happened in /vagrant directory.
If you want to just stop the VM without destroying disc images - you should use vagrant halt instead (or just power off VM as you would do with a real server - i.e. by issuing poweroff).
The general workflow for deploying a vagrant-powered VM outlined in documentation is that you distribute Vagrantfile along with your sources that includes provisioning section (config.vm.provision) which does the stuff you've described - installation of additional software not bundled in a box image (i.e. Rails, gems), setting up the databases, etc. It can be implemented in several ways, starting from just running a simple shell script (with sequential commands to execute), up to using high-profile configuration management systems like Chef, Puppet, CFEngine, Ansible, etc.
Temporary break (like going for dinner) generally does not require even halting a VM, less destroying it. Even a full-fledged VM running under VirtualBox / VMware / KVM with a single-user Rails application hardly consumes lots of resources to worry about.

deploy ruby or rails on windows [duplicate]

I'm looking to run Redmine, a Ruby on Rails app, on a VPS windows box. The only thing I can really think of is running a virtual Linux machine and hosting it from there. If that is my only option, am I going to run into problems running a virtual machine inside of a virtual machine?
Also, this will be an internal app, so performance isn't my number once concern.
Windows is not the usual place to deploy production Rails apps, but there are people who do it. Mongrel was originally written to give better deployment options for Windows. As it turned out the UNIX deployment options weren't that good either. :)
Start with the Ruby One Click installer so you have a sane installation of ruby and rubygems.
From there, you install the rails gem and the gem for your database like you normally would. Most if not all of the databases have Windows gems.
Make sure to install mongrel_service to be able to control each mongrel like a normal windows service. See mongrel_rails service::install -h for details.
Once you have your mongrels set up, it's similar to a UNIX deployment. You set up a reverse proxy, such as Apache2 and you're set.
You might run into some gems (such as BackgroundRB) that will not work under Windows because they have C code that either rely on UNIX libraries or expect a UNIX-like build system at installation time. However, all of the really important Rails gems, such as Mongrel and the database adapters, have gems with pre-built binaries available, so you'll be fine.
Just grab the Bitnami RedMine stack.
Or the Bitnami Ruby on Rails stack.
Redmine ran fine on our Windows build server from the command line, sans IDE, using Mongrel and SQLite. Granted, ours isn't a VPS, but at any rate Linux isn't required for this app.
The BitNami Redmine Stack is a free, up to date Windows installer package for Redmine on Windows, Linux, OS X... give it a try. You can also download a VMWare Virtual Machine as well
I had good luck in the past with InstantRails, but I'm not sure how up-to-date it is now, as the project has changed hands several times.
You might also try ruby stack or flash rails, though I've not used either personally.
You can install SQLite and a Rails server like Mongrel on a Windows machine. I used Aptana to run a development environment, but I'm sure that there are better alternatives that don't require the IDE to be open to run. But this proves it is possible.
Try using a Rails distribution like: http://instantrails.rubyforge.org/wiki/wiki.pl
One download install for rails+ruby+mysql on Windows.

Rails 3.1 on Ubuntu 11.10 under VirtualBox very slow

I have VirtualBox with Ubuntu 11.10 on Windows7.
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.
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!
But: if I go 0.0.0.0:3000 inside Ubuntu - it works perfect.
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.
So I think it should be noted that this is NOT a misconfiguration of the virtual machine or BIOS settings or anything like that. This is strictly a webrick issue. Other services work just fine if they aren't trying to do reverse DNS lookups.
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.
There are a few ways to fix this.
Hack /etc/hosts
The first is to hack /etc/hosts so your client machine has an entry. 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. This requires root-level permissions.
Get your IP address - this will be seen in the Rails console when you make a request, 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 is 10.0.2.2.
Add a line to /etc/hosts to identify that IP address: 10.0.2.2 Nerdmaster
All should be well!
Disable daemon
This seemed to work for some ubuntu users:
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.
Hack webrick
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:
Find your webrick/config.rb
It may be in /usr/lib/ruby/[version]/webrick/config.rb if you're running a normal Ruby
If you use RVM, you'll have to find the appropriate ruby directory, e.g. /home/username/.rvm/rubies/[version]/lib/ruby/[version]/webrick/config.rb
I don't know jack about other options like rbenv
Worst-case scenario, try find / -type d -name "webrick"
Edit in your favorite editor (obviously this would be vim)
Look for :DoNotReverseLookup => nil.
Change nil to true.
If you don't see this setting, you may have to use the /etc/hosts hack above.
If you aren't using rvm or something similar, this will require root-level permissions.
Don't use webrick
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. 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. 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.
Edit your Gemfile to add:
gem 'mongrel'
bundle install
rails s -> will use mongrel instead of webrick and be lightning fast.
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. Found that cause in this thread, moving away from shared folders fixed the speed issue for me.
I am using windows10 home edition with 8 ram, 250g ssd, when I run Rails4.x (thin) on Virtual box with ubuntu server 16, I found the render time is extreamlly slow, mostly up to 4 - 5 seconds, finally I moved rails project from host shared folder to Virtualbox vm inside, it's become quite faster now.
Try turning off your firewall or antivirus on Windows.
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. (Install Mongrel in Ruby 1.9.3)
I switched over to thin - http://code.macournoyer.com/thin/
sudo gem install thin
thin start
and it's super snappy for me.

How to use a VM to create a Rails staging environment

My app is in development and I do all my testing using WEBrick (I like the terminal output).
On the production server it will run on Phusion Passenger.
I'm running Snow Leopard and wish to test the app in an environment similar to the production environment.
Can I use Parallels to run a Debian install with Apache and Passenger and configure Capistrano to deploy to that?
Thanks!
I have been using VMware for that sort of thing. Its really easy to deal with network wise. I have recently switched to Virtualbox which is much nicer to actually work in (at least for me), does the same things, and is free. Download the Debian iso and create a new VM that uses it as its CDrom. Thats about all you need to do. Good luck.
This may not be the answer you're looking for but I've found it very straightforward to just run passenger locally for development. You can always tail the development.log, it's really just as easy as watching the terminal output from webrick.
Dev setup is made all the easier with the drag and drop ease of the phusion passenger pref pane.
http://www.fngtps.com/passenger-preference-pane
Seems like it would be easier than setting up the VM and all. Though yes, there could still be differences if your not hosting on OS X server I suppose.

Is there anyway to run Ruby on Rails applications on a Windows box?

I'm looking to run Redmine, a Ruby on Rails app, on a VPS windows box. The only thing I can really think of is running a virtual Linux machine and hosting it from there. If that is my only option, am I going to run into problems running a virtual machine inside of a virtual machine?
Also, this will be an internal app, so performance isn't my number once concern.
Windows is not the usual place to deploy production Rails apps, but there are people who do it. Mongrel was originally written to give better deployment options for Windows. As it turned out the UNIX deployment options weren't that good either. :)
Start with the Ruby One Click installer so you have a sane installation of ruby and rubygems.
From there, you install the rails gem and the gem for your database like you normally would. Most if not all of the databases have Windows gems.
Make sure to install mongrel_service to be able to control each mongrel like a normal windows service. See mongrel_rails service::install -h for details.
Once you have your mongrels set up, it's similar to a UNIX deployment. You set up a reverse proxy, such as Apache2 and you're set.
You might run into some gems (such as BackgroundRB) that will not work under Windows because they have C code that either rely on UNIX libraries or expect a UNIX-like build system at installation time. However, all of the really important Rails gems, such as Mongrel and the database adapters, have gems with pre-built binaries available, so you'll be fine.
Just grab the Bitnami RedMine stack.
Or the Bitnami Ruby on Rails stack.
Redmine ran fine on our Windows build server from the command line, sans IDE, using Mongrel and SQLite. Granted, ours isn't a VPS, but at any rate Linux isn't required for this app.
The BitNami Redmine Stack is a free, up to date Windows installer package for Redmine on Windows, Linux, OS X... give it a try. You can also download a VMWare Virtual Machine as well
I had good luck in the past with InstantRails, but I'm not sure how up-to-date it is now, as the project has changed hands several times.
You might also try ruby stack or flash rails, though I've not used either personally.
You can install SQLite and a Rails server like Mongrel on a Windows machine. I used Aptana to run a development environment, but I'm sure that there are better alternatives that don't require the IDE to be open to run. But this proves it is possible.
Try using a Rails distribution like: http://instantrails.rubyforge.org/wiki/wiki.pl
One download install for rails+ruby+mysql on Windows.

Resources