[Twisted-Python] Re: [Twisted-commits] fixed connectionLost calls to accept Failures. Read on, I've got gripes.
glyph at twistedmatrix.com
Sat Aug 31 22:42:40 EDT 2002
On Sat, 31 Aug 2002 11:54:08 -0500, radix CVS <radix at twistedmatrix.com> wrote:
> I think all the methods that are returning CONNECTION_* should be _raising_
> them. "Return victorious or not at all". This has the benefit of useful
> tracebacks in the Failure objects.
Well, it was originally that way.
However, it turns out that creating exception objects in Python, generating
tracebacks et. al. is rather expensive. Losing connections happens a LOT.
Since connectionLost is in the "positive path" of most applications, like, for
example, HTTP, raising them creates an even higher overhead for
creating/destroying connections. At the time I made this change, I benchmarked
twisted.web with a small static page. IIRC there was a 2-3x speedup with doing
these as "return" rather than "raise". Perhaps newer releases of Python don't
have such a wide disparity, and the HTTP parser is a lot more robust (and
attendantly complex) now, so it's possible that this slowdown is now marginal.
Still, let's try to avoid using exceptions as a general-purpose control
structure. They're for handling errors, not just unusual conditions. (The
connection closing is only an error if you don't expect it to close.)
| <`'> | Glyph Lefkowitz: Travelling Sorcerer |
| < _/ > | Lead Developer, the Twisted project |
| < ___/ > | http://www.twistedmatrix.com |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20020831/6679c38d/attachment.pgp
More information about the Twisted-Python