143 points · by dirtyaura · 11y ago · 29 comments
Sigh. If you're doing bulk file transfers, you never hit that problem. If you're sending enough data to fill up outgoing buffers, there's no delay. If you send all the data and close the TCP connection, there's no delay after the last packet. If you do send, reply, send, reply, there's no delay. If you do bulk sends, there's no delay. If you do send, send, reply, there's a delay.
The real problem is ACK delays. The 200ms "ACK delay" timer is a bad idea that someone at Berkeley stuck into BSD around 1985 because they didn't really understand the problem. A delayed ACK is a bet that there will be a reply from the application level within 200ms. TCP continues to use delayed ACKs even if it's losing that bet every time.
If I'd still been working on networking at the time, that never would have happened. But I was off doing stuff for a startup called Autodesk.
John Nagle
Do you have any links specifically discussing the issue?
Google for 'virtualbox sendfile' and there's a lot of discussion.
Worth noting, and this bit me recently, Go's http file handler also uses sendfile beneath the covers.
I then found out that it is actually mentioned in the Vagrant docs also: https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
nodelay and cork are different, indeed, but opposites? They both try to achieve the same effect, put more data in before sending a packet.
> [...] This mechanism is ensured by Nagle’s algorithm, and 200ms [...]
Absolutely not. Nagle's algorithm does not have any delay or timer build in. It simply holds back non-full packets, when there is data in flight (not acked). The second half of the problem is delayed acks, but this is not mentioned in the article, instead it goes on saying
> [...] but Nagle is not relevant to the modern Internet [...]
which is indeed popular belief, but a very superficial analysis that holds no water if you study it further.
The feeling I always get from articles like this is they border on "technical religion". It sounds correct, it is technical, it isn't even false, but it doesn't paint a clear picture, instead it mystifies things further.
The problems nginx had:
1. nagle and http keepalive don't play nice together, the last bit of data might be artificially delayed, especially when delayed acks come into play. nodelay seems needed here. (It is not though, see that Minshall bit.)
2. how to send headers and use sendfile for the body, and fill the first packet with more then just the headers? nopush (tcp_cork) is a solution.
Igor said in a talk I went to that Nginx 1.x was written for FreeBSD first, while 2.0 will be written for Linux first so perhaps some of these things may change (hence "nopush" in the config file, the freebsd term).
sendfile on;
tcp_nopush on;
tcp_nodelay off;
With tcp_nodelay off. Is the author suggesting we turn it on?As the latter part of article describes "tcp_nodelay on" is at the odds with "tcp_nopush on" as they are mutually exclusive, but nginx has special behavior that if you have "sendfile on", it uses "tcp nopush" for everything but the last package and then turns nopush off and enables nodelay to avoid 0.2 sec delay.
That said, it equates to a single kernel-to-kernel copy instead of a kernel-to-userspace plus a userspace-to-kernel copy as in the read/write case.