tags:

views:

76

answers:

2

Hi,

I understood that both of them disable Nagle's algorithm.

When should/ shouldn't I use each one of them?

Thank you.

+2  A: 

Here is a great article describes how each one of them works. Worth reading.

rursw1
Thank you, got it.
NewB
+1  A: 

It's an optimisation, so like any optimisation:

  1. Do not use it
  2. Wait until performance becomes a problem, then having determined that socket latency is definitely the cause of it, and testing proves that this will definitely fix it, AND this is the easiest way of fixing it, do it.

Basically the aim is to avoid having to send out several frames where a single frame can be used, with sendfile() and its friends.

So for example, in a web server, you send the headers followed by the file contents, the headers will be assembled in-memory, the file will then be sent directly by the kernel. TCP_CORK allows you to have the headers and the beginning of the file sent in a single frame, even with TCP_NODELAY, which would otherwise cause the first chunk to be sent out immediately.

MarkR
Nagle itself is an optimisation, so by your logic you should turn it off and only put it on if needed :-)
camh
Nagle is enabled by default and you don't need to write any code to enable it, so it will happen anyway. And no, if you were writing your own TCP stack, if you didn't need to implement Nagle, you wouldn't do so.
MarkR