Nagle's algorithm (summary)
Imagine I want to send one byte to your server. TPC needs 40 bytes in order to to send the request to the correct server (20bytes TCP and 20bytes for IPv4). I just wanted to send one byte (1) but I must send 41 bytes! (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1) Doesn’t THIS seems as a huge overload? Well, it depends...
Meet Nagle's algorithm.
After reading this wikipedia article, it may sound way too awesome and you should start questioning why every server doesn’t use it but.. all that glitters is not gold. Using such a technique has some drawbacks and I am gonna describe two.
Realtime!
Using Nagel's algorithm with games or other realtime stuff is not what I could recommend. Depends on the app/game/software in general itself as for example a game could be turn based strategy that doesn’t need massive client-server-client interaction unlike FPS games where every millisecond counts. Why?
Nagel's algorithm in its very naive description merges few/many packets (TC/IP packets) and sends them when there's a reasonable amount of them (batch) to send. This sounds rather good but in case you build a low latency app/software you should turn this algorithm off or you should at least take into account all the shortcomings.
Check if your Nginx proxy or server doesn’t use Nagel’s algorithm by default as I found out that most servers do by default :)
Go away, clients!
Do you build an app where you expect high amount of concurrent connections and declining even one is unacceptable? Well, welcome to the world of long-pooling and high concurrent servers. Nagel’s algorithm in this scenario couldn’t be a good choice too and should really be considered if you sacrifice “few” bytes of client’s/server’s connection for tens or even more of new connections (clients). As an example disabling nagel's for long-pool connections could save few (if not many) milliseconds for you!
Not Enough?
To follow up on this topic, please read: Scaling node.js to 100k concurrent connections! which gives you a rough idea why someone could be that stupid or maybe ??smart?? to disable this by most defaulted algorithm.



















