Any clues to source of this delay?

Bill Tutt billtut at microsoft.com
Fri Aug 6 05:12:52 CEST 1999


Windows does indeed support this socket option.
Here's what MSDN has to say about the option (in order to fill in all of the
icky details):

TCP_NODELAY 
The TCP_NODELAY option is specific to TCP/IP service providers. The Nagle
algorithm is disabled if the TCP_NODELAY option is enabled (and vice versa).
The process involves buffering send data when there is unacknowledged data
already in flight or buffering send data until a full-size packet can be
sent. It is highly recommended that TCP/IP service providers enable the
Nagle Algorithm by default, and for the vast majority of application
protocols the Nagle Algorithm can deliver significant performance
enhancements. However, for some applications this algorithm can impede
performance, and TCP_NODELAY can be used to turn it off. These are
applications where many small messages are sent, and the time delays between
the messages are maintained. Application writers should not set TCP_NODELAY
unless the impact of doing so is well-understood and desired because setting
TCP_NODELAY can have a significant negative impact on network and
application performance. 

Bill


> -----Original Message-----
> From: Bruce Dodson [mailto:bruce_dodson at bigfoot.com]
> 
> 
> This isn't unique to Python.  It has to do with the way TCP 
> buffers data
> within a time window by default.  The data is sent when some 
> threshold size
> is surpassed or when the time window expires (and I guess you saw that
> sending zero bytes can force it to flush on some platforms).  For many
> applications this buffering gives a performance improvement, 
> but in your
> case (the kind of application that wants to do lots 
> round-trips per second
> with small amounts of data in each request), it kills performance.
> 
> To optimize a socket for this kind of conversation, you can use socket
> option TCP_NODELAY, but this is not a portable solution; I 
> think it's a bit
> different on Windows than on Linux, and it is not available on all
> platforms.  I found no reference to TCP_NODELAY in the Python 
> reference,
> which is probably for the best given its non-portability.  If you are
> targetting a platform that supports it, you can probably do 
> something like:
> 
>   if (os.name == 'nt'):
>     TCP_NODELAY = 1
>     theSocket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
> 
> Depending on the nature of the conversation, one or both sides of your
> connection may want to do that.  Protecting the nonstandard 
> NODELAY option
> with a platform test means the code will still work on other 
> platforms,
> although it will still have a "glass ceiling" on platforms 
> that you haven't
> planned for.
> 
> Bruce
> 
> 




More information about the Python-list mailing list