Mongrel is a refreshing approach to web servers. We’re all familiar with the Apache server and many of us have used Lighthttpd and Nginx and maybe some others too.
So what makes Mongrel special? It’s language agnostic. It doesn’t have a PHP module, it doesn’t have a Python module, and yet you can still use those languages (and plenty more) with it, with very little effort to integrate new languages.
Simplified overview of mongrel’s architecture
When serving a PHP application, a server like Apache processes the HTTP request and then invokes some module – mod_php in PHP’s case – which then processes the scripting language in question and so on.
Mongrel? It just processes the HTTP request.
How does it do anything useful then, you ask? Well, it uses a message queue – specifically ZeroMQ – to send the request to any takers.
So the HTTP request comes to Mongrel, which then processes it and converts it into a sensible format containing the vital info (headers, parameters, etc., in JSON) and gives it to ZeroMQ. It then just waits for a reply from ZeroMQ.
Since ZeroMQ is just a message queue, you need to have something listening for messages and replying to them. Perhaps it’s a PHP application, Python or whatever – ZeroMQ and Mongrel don’t care.
This makes Mongrel special
Herein lies the thing that makes Mongrel special: It’s easy to replace apps and scale. The server doesn’t care at all what processes the request.
You can have a PHP app. You can then rewrite it in Python, and nobody will notice you changed it. All you had to do was to stop the PHP app and start the Python app – heck, you could even have both running at the same time, serving messages from ZeroMQ on a first-come first-serve basis.
This makes it very simple to scale it too – Just throw in some more applications listening for messages in the queue.
Mongrel2 is also designed so that it’s quite easy to configure, and it has very good documentation making it easy to get started.
I recommend that you check out Mongrel2, if for nothing else, for the simple reason that it’s doing things differently from the mass.
I will probably be doing a post later about my adventures in Mongrel2 and Haskell web application development – once I get it diong anything interesting which may take a bit since I’m a Haskell-noob :)