From 852afeb565e2bf9e4e91962b5a97e795d5391fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Endre=20S=C3=A1ndor=20Varga?= Date: Tue, 5 Mar 2013 14:22:21 +0100 Subject: [PATCH 1/2] Set TCPNODELAY as default. --- akka-actor/src/main/scala/akka/io/Tcp.scala | 2 ++ akka-actor/src/main/scala/akka/io/TcpConnection.scala | 2 ++ 2 files changed, 4 insertions(+) diff --git a/akka-actor/src/main/scala/akka/io/Tcp.scala b/akka-actor/src/main/scala/akka/io/Tcp.scala index 989c1e05f1..8c5150cc83 100644 --- a/akka-actor/src/main/scala/akka/io/Tcp.scala +++ b/akka-actor/src/main/scala/akka/io/Tcp.scala @@ -50,6 +50,8 @@ object Tcp extends ExtensionKey[TcpExt] { * [[akka.io.Inet.SocketOption]] to enable or disable TCP_NODELAY * (disable or enable Nagle's algorithm) * + * Please note, that TCP_NODELAY is enabled by default. + * * For more information see [[java.net.Socket.setTcpNoDelay]] */ case class TcpNoDelay(on: Boolean) extends SocketOption { diff --git a/akka-actor/src/main/scala/akka/io/TcpConnection.scala b/akka-actor/src/main/scala/akka/io/TcpConnection.scala index 0af6497668..ec866ae75f 100644 --- a/akka-actor/src/main/scala/akka/io/TcpConnection.scala +++ b/akka-actor/src/main/scala/akka/io/TcpConnection.scala @@ -109,6 +109,8 @@ private[io] abstract class TcpConnection(val channel: SocketChannel, /** used in subclasses to start the common machinery above once a channel is connected */ def completeConnect(commander: ActorRef, options: immutable.Traversable[SocketOption]): Unit = { + // Turn off Nagle's algorithm by default + channel.socket.setTcpNoDelay(true) options.foreach(_.afterConnect(channel.socket)) commander ! Connected( From 7804df7743512876e4df39bee1b393c649b3aad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Endre=20S=C3=A1ndor=20Varga?= Date: Fri, 15 Mar 2013 11:08:42 +0100 Subject: [PATCH 2/2] Updated documentation --- akka-docs/rst/java/io.rst | 5 +++++ akka-docs/rst/scala/io.rst | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/akka-docs/rst/java/io.rst b/akka-docs/rst/java/io.rst index e6984de46d..ac78ee052e 100644 --- a/akka-docs/rst/java/io.rst +++ b/akka-docs/rst/java/io.rst @@ -127,6 +127,11 @@ When connecting, it is also possible to set various socket options or specify a .. includecode:: code/docs/io/IODocTest.java#connect-with-options +.. note:: + The SO_NODELAY (TCP_NODELAY on Windows) socket option defaults to true in Akka, independently of the OS default + settings. This setting disables Nagle's algorithm considerably improving latency for most applications. This setting + could be overridden by passing ``SO.TcpNoDelay(false)`` in the list of socket options of the ``Connect`` message. + After issuing the ``Connect`` command the TCP manager spawns a worker actor to handle commands related to the connection. This worker actor will reveal itself by replying with a ``Connected`` message to the actor who sent the ``Connect`` command. diff --git a/akka-docs/rst/scala/io.rst b/akka-docs/rst/scala/io.rst index 6d9b5f259a..fa91868e81 100644 --- a/akka-docs/rst/scala/io.rst +++ b/akka-docs/rst/scala/io.rst @@ -176,6 +176,11 @@ When connecting, it is also possible to set various socket options or specify a IO(Tcp) ! Connect(remoteSocketAddress, Some(localSocketAddress), List(SO.KeepAlive(true))) +.. note:: + The SO_NODELAY (TCP_NODELAY on Windows) socket option defaults to true in Akka, independently of the OS default + settings. This setting disables Nagle's algorithm considerably improving latency for most applications. This setting + could be overridden by passing ``SO.TcpNoDelay(false)`` in the list of socket options of the ``Connect`` message. + After issuing the ``Connect`` command the TCP manager spawns a worker actor to handle commands related to the connection. This worker actor will reveal itself by replying with a ``Connected`` message to the actor who sent the ``Connect`` command.