Richard Bucker

Mongrel2 = mongrel + python

Posted at — Dec 30, 2011

mongrel was originally written for the ruby folk by a programmer named Zed. I cannot speak to how useful it is or was but I remember reading the name a few times and that was about that.Recently while I was reading up on ZeroMQ I ran into a reference to a framework called Mongrel2. Mongrel 2 was implemented using Python and ZeroMQ. It was also written by Zed.It uses the single process/thread eventd model to implement the client-side web server. Requests are taken in from inside an IOloop and those messages are forwarded to and through ZeroMQ as quickly as possible. The programmer need only implement a route table and the “handler” (a ZeroMQ worker).What makes it interesting is that it implements a 1:Many (client to worker ratio). And; it is implemented in a brokerless structure. In a brokered structure a single incoming transaction can yield 4x transactions on the same box and between 6x and 8x if shifting the transaction off of the current cluster. Also, they did not implement a traditional REQ/RSP (request/response) workflow. In fact on the inbound transaction the webserver pushes to the ZMQ' queue and the worker pulls from the queue. ¬†When the worker has a response it uses a publish/subscribe in order to deliver the response to the awaiting webserver instance.It would be nice to have a picture to go along with that description but I do not have one.And now the shortcomings. While the source code is available the last thing I want to do is instrument all of that code. ZeroMQ does not have any queue management APIs. So there is no way to know what the TTL for a particular message is… every message must be processed meaning that you can DOS yourself.There are some APIs in the IOLoop class that could be used: setup all the callback handlers send() the message receive the “sent” trigger wait for the response… if there is a timeout then try to reverse the request and release the clientIn one other use-case: setup all the callback handlers send() the message wait for the response… if there is a timeout and the “sent” was never received then the message is queued. abort the request.In conclusion, while I like many of the design decisions in Mongrel2 and it clearly benefits from being V2, it’s still incomplete in many ways due to ZMQ and not itself.