On 17.5.2007, at 14.19, Johan wrote:
Hi, I know Mongrel is one of the best performing methods to host rails. I know CGI is to be avoided because the ruby interpreter and the rails framework have to be loaded for every request. I know FastCGI is faster then CGI (what's in a name :-D ) because is works with a long-running proces, so that the ruby interpreter, the rails framework, the database connection, ... only have to be loaded once. And I do know that this has an influence on CPU and RAM usage (shared environments!). What I don't know is the reason why Mongrel performs better: How does http work compared to (fast)cgi? Why is it fast? Does it need a lot of CPU power or RAM, ...? Does it only work with Apache, or can you use any server? What exactly is Mongrel? Is it a server? An extension? ...
Mongrel is a standalone ruby program, so yes, it is a server. It loads the Rails code on startup just like a FastCGI process does. You can use it by itself as a web server just like webrick. However, the normal use is to use a web server like nginx, lighttpd or apache in front of multiple mongrels as an http proxy. In that case the setup is similar to the FastCGI setup, with the exception that the frontend server uses http to connect to mongrel instead of unix sockets. For that reason you can also use a load balancer like pen, pound or haproxy directly in front of the mongrels.
Mongrel's speed is in the same ballpark as FastCGI's with Rails (it is, after all, a similarly long-running process). It might be a tad slower because sockets are probably a bit faster than going through http. However, the difference is normally negligible and will be more than offset by the flexibility it brings you. There have also been some stability problems with the FastCGI approach which are exceedingly harder to debug than plain http connections.
//jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
smime.p7s
Description: S/MIME cryptographic signature