Article:
 |
|
Untwisting Python Network Programming
|
| Subject: |
|
Why untwisting? |
| Date: |
|
2006-08-11 10:34:28 |
| From: |
|
glyph@divmod.com
|
|
|
|
Many of the examples in this article are wrong. I'll just point out the errors in the telnet example, because I'm more familiar with Twisted than non-Twisted code, and I also don't have too much time to spend reviewing it...
By overriding Telnet's dataReceived method, it short-circuits the machinery which actually speaks the telnet protocol. By inspecting the 'data' argument for full strings, it depends on implementation accidents of the transport to deliver whole messages - TCP does not guarantee that, and although packets are rarely fragmented at such small sizes, as example code this is very bad form.
Try looking at TelnetTransport and ITelnetProtocol for a more correct way to implement this; you should probably use something like StatefulTelnetProtocol to verify that you're processing whole lines, and to deal with the negotiation of various telnet options.
"For basic programs such as the command-line client of this example, the Python core networking modules are more desirable due to the simplicity and performance advantages."
What do you mean by "performance advantages"? Have you done any measurements indicating that the core networking modules are ever faster?
|
Showing messages 1 through 1 of 1.
-
Why untwisting?
2006-08-13 22:19:59
Kendrew
[View]
Regarding performance, I observed the core modules runs faster than Twisted when running the programs. I also briefly did some measurements and here are the results:
These numbers are the average of 10 runs, and the mail server is run in localhost. While the measurements are by no means vigorous, they basically agree with the observations. Of course, the differences may not be significant in real uses when the network delay counts for majority of the execution time.