views:

745

answers:

5

I'm on a 256 slice of Slicehost and running Apache and Passenger to host my Rails app. I've had to do the Hard-Reboot often. When I looked at this Passenger memory stat.

--------- Passenger processes ---------

** [out :: welcometonewnepal.com] PID Threads VMSize Private Name ** [out :: welcometonewnepal.com] --------------------------------------- ** [out :: welcometonewnepal.com] 8246 11 84.1 MB 0.1 MB /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/ApplicationPoolServerExecutable 0 /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/bin/passenger-spawn-server /usr/bin/ruby1.8 /tmp/passenger.4217 ** [out :: welcometonewnepal.com] 8247 2 57.1 MB 0.2 MB Passenger spawn server ** [out :: welcometonewnepal.com] 8903 1 185.6 MB 9.6 MB Passenger ApplicationSpawner: /home/deploy/rails_apps/welcometonewnepal/production/current ** [out :: welcometonewnepal.com] 9065 1 195.1 MB 76.6 MB Rails: /home/deploy/rails_apps/welcometonewnepal/production/current ** [out :: welcometonewnepal.com] ### Processes: 4 ** [out :: welcometonewnepal.com] ### Total private dirty RSS: 86.43 MB

Seeing the sizes in bold, why is it eating up memory so much?

+3  A: 

Can't say for sure based on those stats alone.

But to help lower it:

  • Use Nginx over Apache
  • Use Ruby Enterprise Edition -- looks like you're just using regular 1.8.6/7... that's wasted memory right there

Also, do you have a lot of gems and/or plugins in your app?

fig
+1 for RubyEE. Passenger is almost useless without it. And NginX is blazing fast, but Apache is (IMO) easier to use.
musicfreak
Another +1 for REE.
Tim Haines
I'm using REE already!
Millisami
A: 

You need to do some memory profiling.

srboisvert
+1  A: 

Its not taking up that much memory ... the column you need to pay attention to is the one marked "private".
If you add them all up (and it does at the bottom) you'll see that passenger and its related processes are only taking up 86MB of memory. Most of it is being taken up by the size of your application too (76MB).

You might need to let us know what else you're running on the server ... install htop and sort by memory to get an idea.

concept47
A: 

If you are running in a 64-bit environment, try switching to 32-bit. Rails/Ruby tend to use less memory in a 32-bit environment.

Jared
Why is that? Any reference that I can read about that?
jpartogi
A: 

Have you tuned Apache or your database settings? I found a Wordpress blog + a small Rails app to be too much for a 256MB slice with the default Ubuntu configurations.

Try the following settings in Apache (Prefork MPM):

#KeepAlive On
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 4

<IfModule prefork.c>
StartServers       5
MinSpareServers    5
MaxSpareServers    10
MaxClients         40
MaxRequestsPerChild 1
</IfModule>

In my case, I had to further tune down the MaxClients to 25. I used to get 2-3 swap warning emails per week from Slicehost, but I haven't received any in the 2 weeks since I've switched my settings. If you are using the WorkerMPM fork, then your settings will be different.

If you are using MySQL, disable InnoDB tables if you don't use InnoDB. That can save you quite a bit of memory.

Jared
I've used MpmWorker module instead of Prefork coz with the following config. <pre><IfModule mpm_worker_module> StartServers 1 MaxClients 10 MinSpareThreads 1 MaxSpareThreads 1 ThreadsPerChild 10 MaxRequestsPerChild 50000 ThreadStackSize 500000 </IfModule> </pre>If you google to tune up apache with rails, most uses MpmWorker!!
Millisami