[Twisted-Python] Re: [Twisted-commits] fixed connectionLost calls to accept Failures. Read on, I've got gripes.
On Sat, 31 Aug 2002 11:54:08 -0500, radix CVS
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 |
participants (1)
-
Glyph Lefkowitz