How do I optimize TCP stack for HTTP server?

I have a HTTP server that serves only two kinds of page: about 10 KB and about 16 KB (both compressed, other files are from CDN). As the latency is quite high (ping takes more than 300 ms), I want to optimize the TCP stack so that client receives the whole page ASAP.

Thus, I have a double question:

  • Which parameter do I have to change (which value of TCP window)?
  • How to change in (a Debian box, and FYI, there is a Varnish before the HTTP server).

Solution 1:

If you are stuck with this high latency, I guess one thing you would like to do is avoid TCP Slow Start. By default, the TCP stack will wait for a ACK after sending the first 3 packets, in your case this means a delay of 600 ms because of round trip time. It has already been disused here. According to this, you cannot change this number easily in Linux, except moving to kernel version 2.6.33.

Maybe you could recompile your kernel with a larger value for the correct parameter, or move to an OS that allows you to use a larger value on this parameter (I think Solaris can be tuned here).

On the application side, make sure to enable HTTP Keep-Alive to avoid Slow Start at each HTTP request.