Running Ruby on Rails App on Apache + Passenger == to much memory

5,290

Solution 1

You can configure how many Rails processes Apache/passenger spawns. For your size (3 concurrent requests) you should be fine with 2 rails processes:

Set these in your apache config:

PassengerMaxPoolSize 2
PassengerMaxInstancesPerApp 2

The MaxPoolSize determines how many instances can be started maximally, the MaxInstancesPerApp determines how many instances each web-app can have.

You might want to play with:

PassengerPoolIdleTime 

to specify how many seconds an instance must be idle before it is unloaded. Default is 300 seconds.

I run pretty high traffic web application with 3 instances without any problems.

Oh and - the Ruby Enterprise Edition helps too.

Solution 2

Are you using ruby enterprise? http://www.rubyenterpriseedition.com/

Solution 3

Either use Ruby Enterprise Edition (recommended with Passenger), or use Ruby 1.9, which is also loads faster.

Solution 4

How many concurrent requests do you need to support ? I would use nginx and a small cluster of mongrels. This way you can limit the amount of resource your ruby application uses.

Share:
5,290

Related videos on Youtube

Rich
Author by

Rich

Freelance Django developer from Sydney Australia

Updated on September 17, 2022

Comments

  • Rich
    Rich over 1 year

    I'm running redmine (a RoR app) on my server using passenger / Apache 2.2. Passenger and ruby are using way too much memory.

    Is there a more memory effective way to run redmine/ruby?

    I only need to support a half dozen redmine users. I want to continue to use Apache, but I'm open to all suggestions that aren't "use nginx/lighttpd" instead.

    (The following data is from a 512MB VPS, so Ruby is using more than 128MB just for redmine)

    user ....... %mem   ....... process
    -----------------------------------
    www-data ... 13.6   0:00.65 ruby1.8
    www-data ... 12.2   0:04.86 ruby1.8
    
    www-data ...  9.4   0:04.15 apache2
    www-data ...  9.0   0:13.94 apache2
    www-data ...  3.2   0:00.27 apache2
    
    root     ...  2.5   0:00.23 apache2 
    root     ...  1.9   0:01.19 ruby1.8 
    

    So, what's better for me than Passenger?

    Thanks for your thoughts!!

  • Rich
    Rich almost 15 years
    What's nginx got to do with it? clearly you missed that part of my question :-)
  • Rich
    Rich almost 15 years
    Thanks - that looks like a good tip. 33% less memory isn't to be sniffed at, but I kind of feel that it's using like 10x as much memory as trac? Surely Ruby isn't that greedy with memory??
  • Rich
    Rich almost 15 years
    Regarding concurrent requests - 3 at most. This is 'teamware' for a small project.
  • Dave Cheney
    Dave Cheney almost 15 years
    Doesn't passenger spawn a ruby process inside the apache worker ? I'm not sure, but it this is true then you're talking about a huge amount of memory being pinned inside apache workers (yes, some of it will be CoW, but once the rails VM does its first garbage collect, that won't apply any more)
  • Rich
    Rich almost 15 years
    So, mongreals are an alternative to passenger? And I can use them with Apache? Sorry but I'm completely ignorant when it comes to Ruby :-) thanks very much.
  • Rich
    Rich almost 15 years
    > Doesn't passenger spawn a ruby process inside the apache worker ? BTW: that would explain why the Apache processes are so big.
  • Rich
    Rich almost 15 years
    Ah thanks and sorry I didn't see your answer until now. I just tried those settings and they didn't make any difference, I think I only have 2 instances running anyway (see above).
  • jcfischer
    jcfischer almost 15 years
    The other thing to be aware of: 512 mb isn't that much memory, and RedMine could be leaking memory. A 'regular' Rails app should consume between 30 - 60 mb per app server instance. 128 mb doesn't sound too bad for 2 instances though.
  • Rich
    Rich almost 15 years
    OK, thanks for the comparison. I know it's not fair to compare, but I'm just not used to my own apps (python) using up nearly as much memory. I guess Ruby loads everything into memory? I think I'll give this ruby enterprise a go, and probably mongrels too.
  • jcfischer
    jcfischer almost 15 years
    you are loading the Rails stack into memory - and that's the one that uses a lot...
  • srp
    srp over 14 years
    Redmine isn't compatible with Ruby 1.9.
  • Catfish
    Catfish over 11 years
    This helped keep my memory down to a manageable size. Thanks!