[Twisted-Python] Some suggestions

Glyph Lefkowitz glyph at twistedmatrix.com
Fri Aug 10 19:05:20 EDT 2001

On Thu, 9 Aug 2001, Itamar wrote:

> Hi all,
> I spent some time on my 11 hour flight to the US porting my servers to 
> twisted, and here's what I've come up with so far:
> 0) Twisted is very cool.

We know, of course, but glad to hear it anyway :)

> 1) Pickle on save should be optional.
> One of my objects is unpicklable, so every time I shutdown I get an 
> exception. You could say I should rewrite, but I feel developing a 
> server should not have to support all kinds of extra features that 
> twisted provides. Obviously it'd be nice to have them, but it's one more 
> thing you have to learn up front that isn't really necessary.

I think moshe has already added this, does his patch resolve your

> 2) Why is the number of clients that socket.listen() queues hard-coded 
> to 5? this should be an option.

Frankly I can't imagine why anyone would care.  5 is supposed to be a
reasonable and recommended maximum.  But it's an option now :-)

> 3) If writing to a connection and closing a connection are thread safe 
> then writing threaded servers is trivial. I'll try to write some patches 
> that don't slow down the default non-threaded code tommorow.  Again, 
> rewriting my code from scratch as event driven is a waste of a time - I 
> might do it someday, but I want working code now.

OK, I already responded to this in a later email, but I have 2 more things
to add:

  * If your server is multithreaded, it will be *significantly* slower
    than if it is not.  This is a well-documented fact even for servers 
    in C, and context switching + resource contention on the main
    interpreter thread is going to kill you well before you get into
    problems with contention for individual write locks. 

  * _That is okay_.  Don't start worrying too much about the performance
   of Twisted's threading until you've got some significant benchmarking
   problem; and when you discover that threading is slow, you can always
   optimize by making it asynchronous instead :)  Chances are, however,
   that your app can afford the speed hit if it's at all a typical server.

  * There are some interesting ideas in this half/sync half/async pattern
    that may be useful for your app, available at:


> 4) I'll submit a working twisted.internet.ssl after I do (3).

See that this has already been done.  Impressive turnaround time ;)

> 5) More docstrings!

As always.

                      ______      __   __  _____  _     _
                     |  ____ |      \_/   |_____] |_____|
                     |_____| |_____  |    |       |     |
                     @ t w i s t e d m a t r i x  . c o m

More information about the Twisted-Python mailing list