Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Adds an optimization to disable Nagle Algorithm for HttpRequest on NetFx #2249

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}