Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I can't find clear answers / methods on this. As seen elsewhere, passenger and RoR under apache gobble up ram on my VPS.

I've tried a multitude of stacks and implementations, currently resting on a sub optimal apache/cgi/rails configuration, which has swapped my ram usage for CPU time and slow response to requests.

Can anyone recommend an efficient and preferably simple to administer method of setting up rails apps in ubuntu 10.04 server?

share|improve this question
    
How much RAM does you VPS have? How many ruby-on-rails applications are running on it? The most efficient solution depends on the context in which you are using RoR. –  rubenvdg Feb 5 '11 at 10:14
    
It has 512mb, but is dedicated to this task, more or less (a few standard php pages on another virtual host). In fact, it was Redmine that I was trying to deploy here, to support development of sites on another server. It was also going to be my intro to RoR, but left me underwhelmed! –  Kurucu Feb 6 '11 at 22:54

1 Answer 1

Here's the method I've been using.

  1. Install threaded Apache and apr and assort Apache dev libs.
  2. Create a deploy user and then install RVM in the deploy users homedir
  3. Now install either REE 1.8.7 or Ruby 1.9.2 via rvm. Both use less memory than standard 1.8.7 and you'll have to pick based on which one works best with your application.
  4. Now remove the Ubuntu mod_passenger packages and install Passenger as a gem through your deploy user using RVM with the ruby you want to use. Make sure you build the Passenger binaries using RVM as well. Make sure you're installing the correct Passenger for system as well which is either 2.x or 3.x
  5. Create /etc/apache2/mods-available/passenger2.conf or passenger3.conf as well as the matching passenger.load so they don't conflict with the passenger.conf the mod_passenger package uses. Make sure you copy the output from building Passenger correct as well as make sure you're specifying the RVM paths correctly for your version of Passenger which will very slightly depending on version 2.x or 3.x.

As thing point you should try to run your application and make sure it works. Once you have the site loading normally you can now start tweaking your Passenger config. The config I use looks like this.

# rvm and passenger paths
PassengerRoot /home/deploy/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2
PassengerRuby /home/deploy/.rvm/wrappers/ruby-1.9.2-p136/ruby

# set max instances
PassengerMaxPoolSize 6
# Always have one instance running
PassengerMinInstances 1
# recyle an instance after 10k requests
PassengerMaxRequests 10000
# check tmp for restarts one request per 10 secs rather than every request
PassengerStatThrottleRate 10

# don't shutdown any of the spawners
RailsFrameworkSpawnerIdleTime 0
RailsAppSpawnerIdleTime 0

My config tries to keep an active instance at all times and uses a bit more memory by not shutting down the spawners. You want to use very little ram, but you don't want to to wait 15-30 seconds to serve a request because all the Rack process have been shutdown. I'd try something like the following in your case.

PassengerMaxPoolSize 2
PassengerMinInstances 1
PassengerPoolIdleTime 3600
RailsFrameworkSpawnerIdleTime 1800
RailsAppSpawnerIdleTime 600
PassengerStatThrottleRate 10

If things look pretty good you can start lowering settings and see how it works for you.

share|improve this answer
    
I'll give this a go and get back to you. Thanks for the detailed response! –  Kurucu Feb 6 '11 at 22:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.