[Mongrel] Determining ideal number of Mongrels for an app?

Zed A. Shaw zedshaw at zedshaw.com
Tue Nov 28 15:49:09 EST 2006

On Tue, 28 Nov 2006 08:27:38 -0800 (PST)
Joe Ruby <joeat303 at yahoo.com> wrote:

> What's a rule of thumb for guesstimating how many
> Mongrels to use in a cluster for an app? I have an app
> that gets about 5000 unique visitors per day. 

Pathetic.  5000/day?  Sad.  Oh wait, is that 5000 visitors doing 100k request/second during the whole day, or 5000 visitors doing .005 request/second at noon?

(I'm jokingly saying you should find out what their usage pattern is and translate that to req/sec processed and kb/second transfered first.)

> I figured I'd give it plenty of Mongrels -- twenty to be
> specific. After running out of memory and hitting the
> swap periodically, I scaled it back to five and it
> still seems to serve up visitors fine. So, is there
> some super-secret math fomula I can use to determine
> the ideal number of Mongrels I should start in a
> cluster for an app?

Many folks pointed you at the semi-official tuning documentation.  20 is totally over kill and will hurt you more than you know.  I find it's about 2-4/CPU depending on the amount of ram you have and the speed of your CPU.  BUT YOU SHOULD TUNE EVERY APP EVERY TIME NO MATTER WHAT YOU CHANGED.  Don't believe anything as gospel, always test it yourself.

Now, lately I've been wanting to add a couple of qualifiers on the scaling issue related to your resource usage.  In some situations people are using up tons of ram or tons of files.  If you have 2-4 mongrels you quickly outstrip the ram and files.  For these folks I tell them to do a different test that tries to do a lot of concurrent but slow connections to eat up as much ram and file handles as they can.  Then, they expand the mongrels out to handle the number of connections they need.  Many times, people in these situations have to buy more machines.

The main culprit of this is RMagick.  If you have RMagick you need to simulate a ton of people concurrently slamming you with files to make sure you have the resources.

This is also a reasonably good description of file limit defaults and HTTP performance:


Play with these settings as well for each, maybe even just increasing the defaults.

Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu
http://www.awprofessional.com/title/0321483502 -- The Mongrel Book
http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.

More information about the Mongrel-users mailing list