Skip to content

Commit

Permalink
Performance: Adds an optimization to disable Nagle Algorithm for Http…
Browse files Browse the repository at this point in the history
…Request on NetFx (#2249)

Disable Nagle for HTTP gateway mode requests;
this improves latency/throughput for Gatewaymode customers on .net Framework.
This is already the default on .net core so they should be no-op for those customers.
  • Loading branch information
j82w authored Feb 23, 2021
1 parent df040f3 commit 816cc5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Microsoft.Azure.Cosmos/src/Util/ServicePointAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class ServicePointAccessor
private ServicePointAccessor(ServicePoint servicePoint)
{
this.servicePoint = servicePoint ?? throw new ArgumentNullException(nameof(servicePoint));
this.TryDisableUseNagleAlgorithm();
}

internal static ServicePointAccessor FindServicePoint(Uri endpoint)
Expand All @@ -35,6 +36,22 @@ public int ConnectionLimit
set => this.TrySetConnectionLimit(value);
}

/// <summary>
/// Disable Nagle for HTTP requests.
/// This improves latency/throughput for Gateway operations on.net Framework
/// </summary>
private void TryDisableUseNagleAlgorithm()
{
try
{
this.servicePoint.UseNagleAlgorithm = false;
}
catch (PlatformNotSupportedException)
{
DefaultTrace.TraceWarning("ServicePoint.set_UseNagleAlgorithm - Platform does not support feature.");
}
}

private void TrySetConnectionLimit(int connectionLimit)
{
if (ServicePointAccessor.IsBrowser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ public void ServicePointAccessor_SetConnectionLimit()
ServicePoint servicePoint = ServicePointManager.FindServicePoint(ServicePointAccessorTests.uri);
Assert.AreEqual(limit, servicePoint.ConnectionLimit);
}

[TestMethod]
public void ServicePointAccessor_DisableNagle()
{
ServicePointAccessor accessor = ServicePointAccessor.FindServicePoint(ServicePointAccessorTests.uri);
Assert.IsNotNull(accessor);
ServicePoint servicePoint = ServicePointManager.FindServicePoint(ServicePointAccessorTests.uri);
Assert.IsFalse(servicePoint.UseNagleAlgorithm);
}
}
}

0 comments on commit 816cc5a

Please sign in to comment.