Mongrel Cluster and Apache Need Memory

I use a VPS hosted by SliceHost as my personal server. SliceHost uses Xen to host multiple instances of Linux on a single machine. The performance of this setup has been very good.

I have been running:

  • Apache 2.2 with PHP
  • MySQL 5
  • Postfix Mail Server
  • Courier IMAP Server
  • ssh for remote access of course

I recently started playing with a site built using Radiant CMS which is itself built on top of Ruby on Rails. So, I’ve added to the mix:

  • 3 Mongrel instances running under mongrel_cluster

These mongrel instances are proxied behind Apache using mod_proxy_balance as described here. This setup works very well and is more and more becoming the defacto standard for deploying Rails applications. Even the Ruby on Rails sites are deployed with this setup now. It allows you to serve all of your dynamic content through Rails and all of your static content through Apache. This gives you all of the speed and robustness that Apache has to offer (afterall it runs over 50% of all the hosts on the internet) for serving static content without burdening Mongrel with this task.

I was noticing that the site was pretty slow though. I tracked it down to the fact that I had started using too much memory. I was running the site on a VPS with 256M of RAM, but with the new Mongrel instances I had just pushed my server into swap space. Web applications in general are happier with more RAM. In this case it is definitely born out. I upped the VPS to have 512M of RAM and things became VERY SNAPPY! While I didn’t do a scientific before and after. The page loads prior to the upgrade were taking about 5-10s. After the memory increase you can’t tell if the application is static or dynamic.

So, if you’re running into performance issues with Mongrel behind an Apache mod_proxy_balance setup, check your memory. If you are running into swap space then you are likely to see serious performance issues. Let me know of any other simple tweaks to get more performance out of this setup if you have them.

As an aside:
Big kudos to SliceHost on their VPS upgrade capabilities. I clicked 2 buttons on my web-based management console and about 10 minutes later I was running on a bigger VPS. You can’t ask for much better than that if you need to scale up a server!

I guess Lighttpd and Nginx do both support running PHP applications under fast_cgi. You might want to try this kind of setup if you are so inclined. I’m still an Apache partisan.

5 Replies to “Mongrel Cluster and Apache Need Memory”

  1. Thanks for the write up. A 512slice will definitely help alleviate memory crunches. One thing worth considering if you are on a 256slice and don’t want to upgrade is switching to Lighttpd or Nginx. Both perform very well proxying for mongrels and serving static content. The plus is a smaller memory footprint, when compared to Apache. A 256 can typically run 3 mongrel and Nginx/Lightty without problems.

  2. Thanks for the tip.
    I’m also running WordPress and subversion – using PHP and mod_dav_svn – so in this case the flexibility of Apache is going to be hard to beat. Do Lightty support PHP?

  3. Hi there,

    Thanks for the info mate…Is it possible by any chance to have some SliceHost employee fix that setup for me if I signup for a slice?


  4. Mike,
    I think SliceHost is a bit more of a DIY (do it yourself) setup, but you might want to contact them and see if they’re setup for those kinds of services. Short answer, I don’t know if they would.

Leave a Reply

Your email address will not be published. Required fields are marked *