<s>
Nagle	B-Protocol
's	I-Protocol
algorithm	I-Protocol
is	O
a	O
means	O
of	O
improving	O
the	O
efficiency	O
of	O
TCP/IP	B-Protocol
networks	I-Protocol
by	O
reducing	O
the	O
number	O
of	O
packets	O
that	O
need	O
to	O
be	O
sent	O
over	O
the	O
network	O
.	O
</s>
<s>
It	O
was	O
published	O
in	O
1984	O
as	O
a	O
Request	O
for	O
Comments	O
(	O
RFC	O
)	O
with	O
title	O
Congestion	O
Control	O
in	O
IP/TCP	O
Internetworks	O
in	O
.	O
</s>
<s>
The	O
RFC	O
describes	O
what	O
he	O
called	O
the	O
"	O
small-packet	O
problem	O
"	O
,	O
where	O
an	O
application	O
repeatedly	O
emits	O
data	O
in	O
small	O
chunks	O
,	O
frequently	O
only	O
1	O
byte	B-Application
in	O
size	O
.	O
</s>
<s>
Since	O
TCP	B-Protocol
packets	O
have	O
a	O
40-byte	O
header	O
(	O
20	O
bytes	B-Application
for	O
TCP	B-Protocol
,	O
20	O
bytes	B-Application
for	O
IPv4	B-Protocol
)	O
,	O
this	O
results	O
in	O
a	O
41-byte	O
packet	O
for	O
1	O
byte	B-Application
of	O
useful	O
information	O
,	O
a	O
huge	O
overhead	O
.	O
</s>
<s>
This	O
situation	O
often	O
occurs	O
in	O
Telnet	B-Protocol
sessions	O
,	O
where	O
most	O
keypresses	O
generate	O
a	O
single	O
byte	B-Application
of	O
data	O
that	O
is	O
transmitted	O
immediately	O
.	O
</s>
<s>
Nagle	B-Protocol
's	I-Protocol
algorithm	I-Protocol
works	O
by	O
combining	O
a	O
number	O
of	O
small	O
outgoing	O
messages	O
and	O
sending	O
them	O
all	O
at	O
once	O
.	O
</s>
<s>
inhibit	O
the	O
sending	O
of	O
new	O
TCP	B-Protocol
segments	O
when	O
new	O
outgoing	O
data	O
arrives	O
from	O
the	O
user	O
if	O
any	O
previously	O
transmitted	O
data	O
on	O
the	O
connection	O
remains	O
unacknowledged	O
.	O
</s>
<s>
This	O
algorithm	O
interacts	O
badly	O
with	O
TCP	B-Protocol
delayed	I-Protocol
acknowledgments	I-Protocol
(	O
delayed	O
ACK	O
)	O
,	O
a	O
feature	O
introduced	O
into	O
TCP	B-Protocol
at	O
roughly	O
the	O
same	O
time	O
in	O
the	O
early	O
1980s	O
,	O
but	O
by	O
a	O
different	O
group	O
.	O
</s>
<s>
With	O
both	O
algorithms	O
enabled	O
,	O
applications	O
that	O
do	O
two	O
successive	O
writes	O
to	O
a	O
TCP	B-Protocol
connection	O
,	O
followed	O
by	O
a	O
read	O
that	O
will	O
not	O
be	O
fulfilled	O
until	O
after	O
the	O
data	O
from	O
the	O
second	O
write	O
has	O
reached	O
the	O
destination	O
,	O
experience	O
a	O
constant	O
delay	O
of	O
up	O
to	O
500	O
milliseconds	O
,	O
the	O
"	O
ACK	O
delay	O
"	O
.	O
</s>
<s>
So	O
,	O
if	O
you	O
can	O
,	O
buffer	O
up	O
your	O
little	O
writes	O
to	O
TCP	B-Protocol
and	O
send	O
them	O
all	O
at	O
once	O
.	O
</s>
<s>
TCP	B-Protocol
implementations	O
usually	O
provide	O
applications	O
with	O
an	O
interface	O
to	O
disable	O
the	O
Nagle	B-Protocol
algorithm	I-Protocol
.	O
</s>
<s>
TCP_NODELAY	O
is	O
present	O
since	O
the	O
TCP/IP	B-Protocol
stack	I-Protocol
in	O
4.2BSD	O
of	O
1983	O
,	O
a	O
stack	O
with	O
many	O
descendents	O
.	O
</s>
<s>
The	O
Nagle	B-Protocol
algorithm	I-Protocol
applies	O
to	O
data	O
writes	O
of	O
any	O
size	O
.	O
</s>
<s>
If	O
the	O
data	O
in	O
a	O
single	O
write	O
spans	O
2n	O
packets	O
,	O
where	O
there	O
are	O
2n-1	O
full-sized	O
TCP	B-Protocol
segments	O
followed	O
by	O
a	O
partial	O
TCP	B-Protocol
segment	O
,	O
the	O
original	O
Nagle	B-Protocol
algorithm	I-Protocol
would	O
withhold	O
the	O
last	O
packet	O
,	O
waiting	O
for	O
either	O
more	O
data	O
to	O
send	O
(	O
to	O
fill	O
the	O
packet	O
)	O
,	O
or	O
the	O
ACK	O
for	O
the	O
previous	O
packet	O
(	O
indicating	O
that	O
all	O
the	O
previous	O
packets	O
have	O
left	O
the	O
network	O
)	O
.	O
</s>
<s>
A	O
later	O
refinement	O
to	O
Nagle	B-Protocol
’s	I-Protocol
algorithm	I-Protocol
,	O
called	O
Minshall	O
’s	O
Modification	O
,	O
solved	O
this	O
problem	O
with	O
stop-and-wait	O
protocols	O
that	O
send	O
one	O
short	O
message	O
and	O
then	O
wait	O
for	O
an	O
acknowledgement	O
before	O
sending	O
the	O
next	O
,	O
removing	O
the	O
incentive	O
for	O
them	O
to	O
disable	O
Nagle	B-Protocol
’s	I-Protocol
algorithm	I-Protocol
(	O
though	O
such	O
protocols	O
will	O
still	O
be	O
limited	O
by	O
their	O
design	O
to	O
one	O
message	O
exchange	O
per	O
network	O
round-trip	O
time	O
)	O
.	O
</s>
<s>
In	O
general	O
,	O
since	O
Nagle	B-Protocol
's	I-Protocol
algorithm	I-Protocol
is	O
only	O
a	O
defense	O
against	O
careless	O
applications	O
,	O
disabling	O
Nagle	B-Protocol
’s	I-Protocol
algorithm	I-Protocol
will	O
not	O
benefit	O
most	O
carefully	O
written	O
applications	O
that	O
take	O
proper	O
care	O
of	O
buffering	O
.	O
</s>
<s>
Disabling	O
Nagle	B-Protocol
’s	I-Protocol
algorithm	I-Protocol
will	O
enable	O
the	O
application	O
to	O
have	O
many	O
small	O
packets	O
in	O
flight	O
on	O
the	O
network	O
at	O
once	O
,	O
instead	O
of	O
a	O
smaller	O
number	O
of	O
large	O
packets	O
,	O
which	O
may	O
increase	O
load	O
on	O
the	O
network	O
,	O
and	O
may	O
or	O
may	O
not	O
benefit	O
the	O
application	O
performance	O
.	O
</s>
<s>
Applications	O
that	O
expect	O
real-time	O
responses	O
and	O
low	O
latency	O
can	O
react	O
poorly	O
with	O
Nagle	B-Protocol
's	I-Protocol
algorithm	I-Protocol
.	O
</s>
<s>
Another	O
option	O
is	O
to	O
use	O
UDP	B-Protocol
instead	O
.	O
</s>
<s>
Most	O
modern	O
operating	O
systems	O
implement	O
Nagle	B-Protocol
's	I-Protocol
algorithms	I-Protocol
.	O
</s>
