On Tue, 2006-08-22 at 11:47 -0400, hax wrote: > Hi mongrel-users, > > This is my first post, so I'm not sure if it's been asked before, but > I can't find an answer anywhere. > > If I have one rails application running, one processor I'm running it > on, and mongrel is multi-threaded, why should I have more than one > mongrel running? > > Everyone seems to agree on 3-5 mongrels per rails app, but why? > > I must be missing something, sorry if it's obvious.
You've got three things you're dealing with when you do this: 1) Ruby uses a select() function to make it seem like it has threads. This is called "green threads" in the Java world. When you put about 2-4 mongrels per CPU on your machine, you get a slightly better utilization. 2) Rails isn't thread safe (as lots of people have said) so requests come in to mongrel, get threaded up, and then queued behind Rails. Once Rails is done then threads send the response out. If you have a small site and most of your rails actions are quick then don't worry about it. If you need more concurrency then you have to use more processes. 3) Because ruby uses select() it has a OS kernel level limit for the number of files it can handle. Usually that's 1024 but it can be 256 on some systems. If you have one mongrel process then you'll really quickly run out of these when serving files, doing fragment/action caching, etc. You have to add more processes to be able to handle more open files concurrently. That's the why. If you're site is small then just do one. It's easier. Then slowly expand it out and get more "hardcore" as you need it. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help. _______________________________________________ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users