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.
A07ec64186c6d821ca51abb2df646dda?d=identicon&s=25 Johan (Guest)
on 2007-05-17 23: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.
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2007-05-18 03: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 Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi
A7b8d5ddf540e5f465abd0fb3b7cdfcb?d=identicon&s=25 Jesse Proudman (Guest)
on 2007-05-18 03: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 Proudman
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. jesse@blueboxgrp.com
A07ec64186c6d821ca51abb2df646dda?d=identicon&s=25 Johan (Guest)
on 2007-05-18 11:45
Jarkko Laine 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?
A07ec64186c6d821ca51abb2df646dda?d=identicon&s=25 Johan (Guest)
on 2007-05-18 11: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.
A07ec64186c6d821ca51abb2df646dda?d=identicon&s=25 Johan (Guest)
on 2007-05-18 11: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...?
61db6498ec9b44d88445d05aad8816af?d=identicon&s=25 Kyle Mathews (Guest)
on 2007-05-18 14: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 Mathews
http://www.titaniumdev.com
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-08-20 22:23
Wondering what they did to overcome that problem...

Jesse Proudman 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 Proudman
> Blue Box Group, LLC
>
> p. +1.800.613.4305 x801
> e. jesse@blueboxgrp.com
89441a6c74647d292f5cc951eae24cfa?d=identicon&s=25 Jack Christensen (Guest)
on 2007-08-20 22: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 Pack wrote:
<blockquote cite="midf460fe044fc530f4f96e77b5e64bcafa@ruby-forum.com"
 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="midf460fe044fc530f4f96e77b5e64bcafa@ruby-forum.com"
 type="cite">
  <pre wrap="">
Jesse Proudman 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 Proudman
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. <a class="moz-txt-link-abbreviated"
href="mailto:jesse@blueboxgrp.com">jesse@blueboxgrp.com</a>
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Jack Christensen
<a class="moz-txt-link-abbreviated"
href="mailto:jackc@hylesanderson.edu">jackc@hylesanderson.edu</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 rubyonrails-deployment@googlegroups.com <br> To
unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribe@googlegroups.com <br> For more
options, visit this group at
http://groups.google.com/group/rubyonrails-deployment?hl=en <br>
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-08-20 22:50
GC.start maybe? :) [do garbage collection more often?] hmm
A7b8d5ddf540e5f465abd0fb3b7cdfcb?d=identicon&s=25 Jesse Proudman (Guest)
on 2007-08-20 22: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 Proudman
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. jesse@blueboxgrp.com
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-08-20 23: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 Proudman 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 Proudman
> Blue Box Group, LLC
>
> p. +1.800.613.4305 x801
> e. jesse@blueboxgrp.com
8f977c0870d57e52e488dc3546fb7f24?d=identicon&s=25 Raul (Guest)
on 2007-08-20 23:10
(Received via mailing list)
Wow, so what kind of hardware is this happening with?

Raul Rubio


----- Original Message -----
From: "Jesse Proudman" <jesse@blueboxgrp.com>
To: <rubyonrails-deployment@googlegroups.com>
Sent: Monday, August 20, 2007 1:58 PM
Subject: [Rails-deploy] Re: How does Mongrel (http) work, compared to
Fast(CGI)?
A7b8d5ddf540e5f465abd0fb3b7cdfcb?d=identicon&s=25 Jesse Proudman (Guest)
on 2007-08-21 22: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 Proudman
Blue Box Group, LLC

p. +1.800.613.4305 x801
e. jesse@blueboxgrp.com
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-09-27 17:07
Might get slightly higher performance with evented mongrel.
Take care!
-Roger

Jesse Proudman 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 Proudman
> Blue Box Group, LLC
>
> p. +1.800.613.4305 x801
> e. jesse@blueboxgrp.com
This topic is locked and can not be replied to.