Forum: Rails deployment How does Mongrel (http) work, compared to Fast(CGI)?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Johan (Guest)
on 2007-05-18 01:19
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? ...

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.
Jarkko L. (Guest)
on 2007-05-18 05:18
(Received via mailing list)
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
Jesse P. (Guest)
on 2007-05-18 05:34
(Received via mailing list)
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
Johan (Guest)
on 2007-05-18 13:45
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?
Johan (Guest)
on 2007-05-18 13:51
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.
Johan (Guest)
on 2007-05-18 13:57
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...?
Kyle M. (Guest)
on 2007-05-18 16:23
(Received via mailing list)
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
Roger P. (Guest)
on 2007-08-21 00:23
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
Jack C. (Guest)
on 2007-08-21 00:48
(Received via mailing list)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Roger P. wrote:
<blockquote cite="removed_email_address@domain.invalid"
 type="cite">
  <pre wrap="">Wondering what they did to overcome that problem...
  </pre>
</blockquote>
Perhaps monit to restart the processes that go too big? It's what I
use.<br>
<blockquote cite="removed_email_address@domain.invalid"
 type="cite">
  <pre wrap="">
Jesse P. wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">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. <a class="moz-txt-link-abbreviated"
href="mailto:removed_email_address@domain.invalid">removed_email_address@domain.invalid</a>
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Jack C.
<a class="moz-txt-link-abbreviated"
href="mailto:removed_email_address@domain.invalid">removed_email_address@domain.invalid</a></pre>
<br>
--~--~---------~--~----~------------~-------~--~----~<br>
You received this message because you are subscribed to the Google
Groups &quot;Deploying Rails&quot; group. <br> To post to this group,
send email to removed_email_address@domain.invalid <br> To
unsubscribe from this group, send email to
removed_email_address@domain.invalid <br> For more
options, visit this group at
http://groups.google.com/group/rubyonrails-deployment?hl=en <br>
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
Roger P. (Guest)
on 2007-08-21 00:50
GC.start maybe? :) [do garbage collection more often?] hmm
Jesse P. (Guest)
on 2007-08-21 00:59
(Received via mailing list)
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
Roger P. (Guest)
on 2007-08-21 01:06
So how many back end servers, with each serving what, might I ask?  Do
you use memcached? Just curious about RoR scaling :)
-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
Raul (Guest)
on 2007-08-21 01:10
(Received via mailing list)
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)?
Jesse P. (Guest)
on 2007-08-22 00:07
(Received via mailing list)
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
Roger P. (Guest)
on 2007-09-27 19:07
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
This topic is locked and can not be replied to.