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

**URL:** <https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438>\
**Category:** Deployment\
**Created:** [May 17, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438 "2007-05-17T23:19:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 17, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/1 "2007-05-17T23:19:58Z")

</div>

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 😃 ) 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.

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 18, 2007, 3:18am UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/2 "2007-05-18T03:18:00Z")

</div>

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.

> **[jlaine.net](https://jlaine.net/)**
>
> Your freedom to carry a gun messes with my freedom to walk around without fear. Your freedom to “stand your ground” with force is at odds with my …

> **[Home](https://dotherightthing.com/)**
>
> do the right thing

[http://www.railsecommerce.com](http://www.railsecommerce.com)  
[http://odesign.fi](http://odesign.fi)

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 18, 2007, 3:34am UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/3 "2007-05-18T03:34:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 18, 2007, 11:51am UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/4 "2007-05-18T11:51:53Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 18, 2007, 11:57am UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/5 "2007-05-18T11:57:21Z")

</div>

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…?

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 18, 2007, 2:23pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/6 "2007-05-18T14:23:13Z")

</div>

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](http://www.titaniumdev.com)

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 20, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/7 "2007-08-20T22:23:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [May 18, 2007, 11:45am UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/8 "2007-05-18T11:45:20Z")

</div>

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:  
[Reverse proxy - Wikipedia](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?

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 20, 2007, 10:59pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/9 "2007-08-20T22:59:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 20, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/10 "2007-08-20T22:50:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 20, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/11 "2007-08-20T22:48:22Z")

</div>

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](mailto:removed_email_address@domain.invalid)
> > ```
> 
> ```
> 
> ```

  
  

```
--
Jack C.[removed\_email\_address@domain.invalid](mailto: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   
 -~----------~----~----~----~------~----~------~--~---

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 20, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/12 "2007-08-20T23:10:26Z")

</div>

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

Raul Rubio

----- Original Message -----  
From: “Jesse P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto: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)?

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 21, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/13 "2007-08-21T22:07:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [September 27, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/14 "2007-09-27T17:07:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [August 20, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/how-does-mongrel-http-work-compared-to-fast-cgi/104438/15 "2007-08-20T23:06:29Z")

</div>

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
