Friday, April 20, 2007

Python Twisted and Apache Mina, Two Great Asynchronous Network Application Frameworks

For last 10 months I have been working on a high scalable asynchronous network messaging gateway project using Apache MINA(Multipurpose Infrastructure for Network Applications), which is a Java Network Application Framework based on Java NIO.

One challenge to develop a high scalable asynchronous network messaging gateway is how you test it for functionality, load and performance. I eventually developed several Test Simulators and Drivers using Python Twisted, "an event-driven networking engine written in Python".

Twisted obviously is THE python framework if you want to develop a scalable asynchronous network application using Python. Personally, I think that Apache Mina has a very good chance to become the De facto java framework for developing NIO based network applications.

If you compare Twisted with Mina, they both adopt the "reactor pattern", they both have the goal to encapsulate/hide the complexity of Non-blocking network IO and provide a simple and elegant framework for developer to use. Actually, they are very similar at concept level as the following table shows:

Python TwistedApache MINA
ProtocolProtocolEncoder/ProtocolDecoder
LineRecevierTextLineEncoder/TextLineDecoder
protocol.ClientFactoryIoConnector
protocol.ServerFactoryIoAcceptor
DeferredIoFuture
callback chain/errback chainIoFilterChain
reactor ThreadPoolExecutorFilter