Make stuff to do things

Subscribe (?) Subscribe to RSS

Better Performance from Python AMQP Clients

Published on April 10th, 2009 by Matt Heitzenroder in Comments Tools:

Bruce Lee Will Block You!

Bruce Lee Will Block You!

Recently in the Twitterverse, I happened to notice a lot of linkshare regarding the blog post “Rabbits and Warrens”.  And rightfully so, the author did an excellent job explaining AMQP.  However, it fell short of explaining the importance of asynchronous programming when it comes to the python AMQP client libraries.  The author did touch on the topic, Esteve Fernandez commented with an example on how to achieve the same results, but with txAQMP.

I want to highlight Esteve’s comment and the importance of using asynchronous client code. Dan recently posted how to install txAMQP and a quick guide to test it out. In his next post, he’ll be showing us more examples using txAMQP.

Why you want to use txAMQP

txAMQP (just like AMQP and all other related AMQP libraries) is in early stages of development. If you’re working on a project that is using the AMQP protocol and your message queue clients are written in python, there is a fairly compelling reason to use txAMQP – it is based on Twisted.

Twisted is an event-driven networking engine. Being event-driven is important when implementing AMQP in your project, because it creates a concurrency model using non blocking calls. Consider the following use case:

One process engages the amqp client to put a message on the queue. Microseconds later, a second request to the client api attempts to put a message. Now multiple that volume of by 10,000  or more.

If  you are using a python client like py-amqplib,  will only process each message once it finished the message before. This can create a “traffic jam”, if the volume is great enough.

[NOTEDmitriy Samovskiy wrote about non-blocking sockets for py-amqplib on his blog. He included an add-on to support non-blocking calls for py-amqplib. This has not been merged into the py-amqplib at the time of this writing.]

By using an event-based architecture (as created by Twisted), this allows txAMQP client to proceed to publish (or consume) messages without having to wait for the last message to finish processing. Basically if there’s someone knocking at the door (the event), txAMQP is going to answer.  Whereas py-amqplib will not be able to answer the door because it is still with the last person.  Because of Twisted, we can acheive a greater volume of messaging through concurrency/asynchronous programming.

Also noteworthy, txAMQP gives us support for using Thrift and can quickly implement any version specification for AMQP.

So I encourage all of you AMQP’ers & pythonistas to contribute to txAMQP.

  • ovidiu
    I just did some tests with txamqp vs py-amqplib. I used the examples from here as a starting point for writing the txamqp test: http://app.arat.us/blog/?p=38

    The test consists in sending 10000 messages 1000 bytes each.

    py-amqplib version receives 10000 messages in 3-4 seconds
    txamqp receives 10000messages in 10-15 seconds.

    I don't do anything when the message is received. I only check if all messages have been receaved and I increase a counter. When I reach 10000 messages I print the timedelta.

    I can send the sources if you want.

    Any idea what might be wrong?
  • @ovidiu

    Thanks for your feedback.

    I suspect my blog post title may have been misleading - after all, what is "Performance"? In terms of your comment on this blog, you are talking about speed.

    While, in the blog post I was speaking more to the event-based twisted framework that prevents blocking calls from a client - which lends itself to greater scalability.

    I'd be interested in seeing your code as we'll be doing some performance analysis of txamqp in the future on this blog.
blog comments powered by Disqus
Switch to our mobile site