The delays caused by Nagle’s algorithm can be quite dramatic (up to 300ms - destroys any request-response performance) and I see no way to finetune that. Disabling it [socket().setTcpNoDelay(false)] will cause lots of tiny packets to be sent over the line. Back in the old days we had OutputStreams that we could flush, allowing to combine the advantages of Nagle’s algorithm and controlling when the socket just had to send its data, regardless of the contents of the socket-buffers and the time elapsed after the last write.
To get the same behaviour in NIO, we have to setTcpNoDelay(true) and start combining our own packets, before we call channel.write(ByteBuffer[]). Not that it is so difficult to do our own combining, but why can’t we use a convenient flush() that makes us have the best of both worlds?
The FileChannel has force() to explicitly tell the OS to physicly the apply operation, so why doesn’t SocketChannel expose a similair feature?