title: How to disable Nagle's algorithm in ServiceStack?
body: <p>We're using ServiceStack 3.9.71.0 and we're currently experiencing unexplained latency issues with clients over a WAN connection.</p>
  
  <p>A reply with a very small payload (&lt;100 bytes) is received after 200ms+. </p>
  
  <p>The round-trip-time (RTT) on the link is about 40ms due to the geographical distance. This has been verified by pinging the other host and using a simple echo service to test the latency of a TCP connection.</p>
  
  <p>Both ping and echo test show latencies which are in line with expectations. Getting a reply from our ServiceStack host takes much longer than expected.</p>
  
  <p>We've verified that:</p>
  
  <ul>
  <li>WAN link is only running at 25% of capacity (no congestion)</li>
  <li>No QOS is employed on the WAN link</li>
  <li>same host gives fast reply to same request from a different host on local network</li>
  <li>delay is not caused by our code processing the request</li>
  </ul>
  
  <p>We've now stumbled across Nagle's algorithm and that it can mean delays for small requests on WAN networks (<a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx</a>).</p>
  
  <p>In .NET it can be disabled by setting <code>TcpClient.NoDelay = true</code> (<a href="https://msdn.microsoft.com/en-us/en-US/library/system.net.sockets.tcpclient.nodelay(v=vs.110).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/en-US/library/system.net.sockets.tcpclient.nodelay(v=vs.110).aspx</a>).</p>
  
  <p>How can this be disabled for ServiceStack's TCP handling?</p>
  
  <p>EDIT: I don't think that this is a duplicate of <a href="https://stackoverflow.com/questions/18465504">HttpWebRequest is slow with chunked data</a>. The mentioned question covers <code>HttpWebRequest</code> which isn't used by ServiceStack. ServiceStack uses <code>HttpListener</code> which also happens to be controlled / managed by the mentioned <code>ServicePointManager</code>. We're going to conduct a test to see whether setting <code>ServicePointManager.UseNagleAlgorithm = false</code> solves the issue.</p>