httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pane <bri...@apache.org>
Subject TCP_CORK in Linux 2.6: not broken, but it doesn't work with TCP_NODELAY
Date Sun, 21 Aug 2005 23:25:19 GMT
There was some discussion a few weeks ago about whether TCP_CORK was
broken on Linux 2.6.

I did some tests on Linux 2.6.12 and found that TCP_CORK *does*  
appear to
work.  However, it doesn't work if TCP_NODELAY is also set on the  
socket (as
the tcp(7) manual page warns).

I've attached my test program in case it's useful to others.  It's  
run as
   sendfile_test [--cork] [--nodelay] [--nonblock] filename  
listener_port_number.
It listens endlessly for connections on the specified port.  When it  
gets a connection,
it write(2)s a short HTTP response header and then calls sendfile to  
transmit the
entire contents of the file.  The optional arguments tell it whether  
to set TCP_CORK,
TCP_NODELAY, and/or O_NONBLOCK on the accepted connection; the default
is not to set any of these.

Looking at packet traces, the pattern I see is:

* TCP_NODELAY not set, TCP_CORK not set: the HTTP response header
   arrives in a packet all by itself, followed by the start of the  
file in the next packet.

* TCP_NODELAY not set, TCP_CORK set: the first packet of the response  
contains
   the HTTP response header and the first part of the file.  The  
packet is filled with
   data up to the MSS, unless the total header+file content is  
smaller than the MSS.

* TCP_NODELAY set, TCP_CORK set: the HTTP response header
   arrives in a packet all by itself, followed by the start of the  
file in the next packet.

* TCP_NODELAY set, TCP_CORK not set: the HTTP response header
   arrives in a packet all by itself, followed by the start of the  
file in the next packet.

I tested with both blocking or nonblocking sockets, and both modes  
yielded
these same results.

httpd-2.x always sets TCP_NODELAY, so it makes sense that people are
observing it sending the response header in a separate packet under  
Linux
2.6.  (I'm guessing that TCP_CORK works even in the presence of
TCP_NODELAY under 2.4, but I don't have a 2.4 system to test.)

Rather than automatically setting TCP_NODELAY  in core_pre_connection(),
perhaps we should set it conditionally in core_output_filter(), where  
we have
enough information to tell whether it's needed.

Brian




Mime
View raw message