[Mongrel] Multiple mongrels for one app

Zed Shaw zedshaw at zedshaw.com
Tue Aug 22 18:26:03 EDT 2006

On Tue, 2006-08-22 at 15:11 -0400, hax wrote:
> > Rails is not threadsafe.
> >
> > http://rubyforge.org/pipermail/mongrel-users/2006-August/000930.html
> >
> > //jarkko
> So what happens when the mongrel gets more than one request at a time?
> When I run httpref against it, the mongrel process can serve up large  
> number of rails pages before it gets bogged down.
> And when it does break, it says "mongrel timed out this thread: too  
> many open files".  So it must be doing some threading, even if rails  
> isn't threadsafe.
> If it was 1 request per mongrel process, 1 process shouldn't be able  
> to serve up very many per second.  httpref tells me its prettty fast  
> though.

You actually can find out for yourself right now.  I have the latest
pre-release up with a new debugging feature just for folks like you.

First, install the pre-release like this:

  sudo gem install mongrel

Then run your application in production mode like normal.  Right after
it starts up, do this:

  killall -USR1 mongrel_rails

Go look at the log/mongrel.log and you'll see that it says it set
$mongrel_debug_client to true.  The USR1 signal toggles this "client
debugging" true/false.  When it's true Mongrel will print out log
messages that help you debug client interactions:

* BAD CLIENT is only logged now when USR1 is on.
* Full request data is printed out when there's an HTTP parsing error so
you can see what the problem is.
* It will print the number of threads waiting for rails on 10 second
* It prints stack traces for exceptions found (I'm expanding this more).

It's also very light, so you could enable it all the time if you want.

Now, what you want to do is hit your app with httperf like this:

httperf --server --port 3000 --uri /some/rails/uri --num-conns
1000 --rate 100

And then watch your mongrel.log print out the request counts as they
pile up behind rails and then move out.  Play with num-conns and rate
until you can choke mongrel, find the sweet spot, etc.

Have fun and let me know if you find bugs.

Zed A. Shaw
http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.

More information about the Mongrel-users mailing list