thekid/rfc — Issue #66: RFC 0066: TCP_NODELAY server option
Author: thekid
Created: 2011-10-09 14:49:36+00:00
State: closed
Labels: implemented, rfc

Scope of Change
====
A new method called setTcpNoDelay() on the peer.server.*Server classes
will be added.

Rationale
====
Performance.

Functionality
====

Preface
----
The setTcpNoDelay() method does not set non-blocking mode on the
socket. All I/O in Java is always blocking. Instead, as indicated in the
obscure comment in the javadoc, this method turns on or off "Nagle's
algorithm". This is a performance hint to the kernel about whether or not
to wait for a fraction of a second before sending the data out on the
network in case more data is sent in the immediate future. This is to avoid
sending lots of tiny packets on the network when applications do dumb
things like write data to a TCP stream using an unbuffered output stream
and therefore write a single byte at a time over the network. By default,
Nagle's delay algorithm is therefore usually turned on. However, if you
know that you will buffer writes up and then won't send any for awhile such
as with a request/reply protocol like HTTP it can be a significant
performance win to turn of Nagle's algorithm by calling setTcpNoDelay(true)
so that the kernel will send your data on the network immediately without
wasting time waiting for further data to be written.

Internal implementation note
----
A member variable will indicate that socket_setopt() with the option
TCP_NODELAY should be called on the accept()'ed socket.

Example
----

```php
setTcpNoDelay(TRUE);
$server->addListener(new RemoteInvocationListener());
$server->init();
$server->service();
$server->shutdown();
}
?>
```

Security considerations
====
n/a

Speed impact
====
When set to TRUE (non-default for BC reasons), faster.

Dependencies
====
n/a

Related documents
====
- http://xp-framework.net/downloads/rfc0066.diff
Implementing patch

Comments
====
- friebe, Wed Jul 5 17:43:22 CEST 2006
No BC break, so I think we can commit this almost right ahead