← Back to team overview

nova team mailing list archive

Re: Twisted or Eventlet?


On Thu, Jul 29, 2010 at 02:24:14PM -0500, Eric Day wrote:
> For web-based services it shouldn't matter too much since the WSGI
> interface should be fairly interchangeable.

Yes, assuming we're doing WSGI rather than e.g. twisted web.

> I'm leaning towards Eventlet since it provides a more straight forward
> approach to programming, letting the coroutines and method wrappers
> underneath take care of the non-blocking hooks. This will make it
> easier for new developers jumping in to wrap their head around the
> code, where Twisted has a bit more of a learning curve for those not
> familiar with non-blocking/deferred techniques.

I'm not afraid to admit that it took me a couple of days of head
scratching to understand deferreds and getting to grips with Twisted in
general, but now that I feel I've got the hang of it, it seems like time
/very/ well spent.

I find Twisted code lovely to unit test and Twisted itself is easily
some of the highest quality Python code, I've ever come across.

Twisted has several tricks up its sleeve to make code look more
sequentially readable, like defer.inlineCallbacks which lets you just
yield inside a method and resume where you left off. This is already
used in a bunch of places in Nova.

There's also corotwine which lets you use Twisted with a blocking API.
That way you still get to use Twisted's fantastic set of protocol
implementations, but with the apparantly much coveted blocking API. It
was developed in response to eventlet.

I've not really used eventlet myself for anything serious, and perhaps
I'm not looking in the right places, but from what I can gather about
eventlet, it seems like a much more low-level sort of framework than
Twisted.  Example from Eric's performance tests:

Twisted provides (among many others) a line based protocol:

class Echo(Protocol):
    def dataReceived(self, data):

Eventlet gives you a file descriptor:

def handle(fd):
  while True:
    c = fd.recv(16384)
    if not c: break

At any rate, I'm not convinced a vote is the right way to make this
decision. At least not yet. I think it would be an interesting and
useful experiment to come up with an actual problem and try to solve it
with both Twisted and Eventlet and discuss the results. No, I don't
believe an Echo server is an actual problem :)

Soren Hansen
Systems Architect
The Rackspace Cloud