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( 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 e6fd0d1456..f4041be50d 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.