How does Mongrel (http) work, compared to Fast(CGI)?


#1

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 :smiley: ) 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? …

I don’t find answers to these questions on the Mongrel homepage…
I only find guides to install it (which is super-easy by the way - as
easy a using Webrick).

Can anybody help me out please?

regards,

Johan.


#2

On 17.5.2007, at 14.19, Johan wrote:

(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 L.
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


#3

We’re running Hardware Load Balancers in front of nginx in front of
mongrel_clusters on a site that averages 40 million hits a day. The
biggest problem we’ve see involves memory leaks in the rails app. In
a load balanced situation, that’s no the end of the world, as we just
run scripts to fix those problems when they crop up. Besides that,
we can only rant and rave about the success of this setup.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid


#4

Another thing: to implement fastcgi or mongrel server(s),
you would use Apache modules:

mod_proxy (http://httpd.apache.org/docs/1.3/mod/mod_proxy.html)
or
mod_fast_cgi (http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html)

They offer about the same performance?
But mod_proxy and Mongrel are preferred because of ease of use and
stability isues?
Am I right?

regards,

Johan.


#5

Oh, and finally:

Can 1 Mongrel server be useful (for small websites)?
I mean: can’t you just use Mongrel on itself without putting an Apache
proxy in front of it?
I would think this makes things even easier…?


#6

You will still want to use Apache in front because it handles static
files much faster than Mongrel. Plus as your site grows you can simply
just add more Mongrels to handle the load.


Kyle M.
http://www.titaniumdev.com


#7

Wondering what they did to overcome that problem…

Jesse P. wrote:

We’re running Hardware Load Balancers in front of nginx in front of
mongrel_clusters on a site that averages 40 million hits a day. The
biggest problem we’ve see involves memory leaks in the rails app. In
a load balanced situation, that’s no the end of the world, as we just
run scripts to fix those problems when they crop up. Besides that,
we can only rant and rave about the success of this setup.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid


#8

Jarkko L. wrote:

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.

Thank you, this explanation was very useful.
I have used Mongrel on my local computer (as you mentioned just like you
use Webrick).
But I’m really interested in the real-life use of Mongrel…
So the setup would be: Apache (as reverse proxy:
http://en.wikipedia.org/wiki/Reverse_proxy) with one or more Mongrel
servers behind it.
What does Apache handle? Static requests? Or does it pass every
request to a Mongrel server, so that it exclusively acts as a proxy?


#9

That’s exactly what we use. Nginx + Mongrel + Monit + F5 Load
Balancers. We had another client this last weekend do 18 million
hits at 66 megs / second using that combination. Flawless may be an
overstatement, but I’m pretty satisfied with the combo.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid


#10

GC.start maybe? :slight_smile: [do garbage collection more often?] hmm


#11
Roger P. wrote:
Wondering what they did to overcome that problem...
  
Perhaps monit to restart the processes that go too big? It's what I use.
Jesse P. wrote:
  
We're running Hardware Load Balancers in front of nginx 
in front of
mongrel_clusters on a site that averages 40 million hits a day.  The
biggest problem we've see involves memory leaks in the rails app.  In
a load balanced situation, that's no the end of the world, as we just
run scripts to fix those problems when they crop up.  Besides that,
we can only rant and rave about the success of this setup.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid

  


--
Jack C.
removed_email_address@domain.invalid

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Deploying Rails" group.
To post to this group, send email to removed_email_address@domain.invalid
To unsubscribe from this group, send email to removed_email_address@domain.invalid
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment?hl=en
-~----------~----~----~----~------~----~------~--~---


#12

Wow, so what kind of hardware is this happening with?

Raul Rubio

----- Original Message -----
From: “Jesse P.” removed_email_address@domain.invalid
To: removed_email_address@domain.invalid
Sent: Monday, August 20, 2007 1:58 PM
Subject: [Rails-deploy] Re: How does Mongrel (http) work, compared to
Fast(CGI)?


#13

That particular site is running on 5 app boxes serving both static
and rails content, a NFS box, a Memcached server, and a rather large
DB box.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid


#14

Might get slightly higher performance with evented mongrel.
Take care!
-Roger

Jesse P. wrote:

That particular site is running on 5 app boxes serving both static
and rails content, a NFS box, a Memcached server, and a rather large
DB box.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid


#15

So how many back end servers, with each serving what, might I ask? Do
you use memcached? Just curious about RoR scaling :slight_smile:
-Roger

Jesse P. wrote:

That’s exactly what we use. Nginx + Mongrel + Monit + F5 Load
Balancers. We had another client this last weekend do 18 million
hits at 66 megs / second using that combination. Flawless may be an
overstatement, but I’m pretty satisfied with the combo.

Jesse P.
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. removed_email_address@domain.invalid