-
Notifications
You must be signed in to change notification settings - Fork 696
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
Increase HttpClientHandler.MaxConnectionsPerServer to 64 to improve PM UI performance in Visual Studio #4798
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf5c256
update maxrequestspersource to 64 by default for .NET framework code …
73699da
format
abb7531
change code
f659744
fix bug
27870ca
fix fail tests
e5ebf44
code refactoring
ed3a703
added tests
c1528ca
updated test names
7561404
updated tests
5711e83
made tests async
102af0b
updated package source url
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
test/NuGet.Core.Tests/NuGet.Protocol.Tests/HttpHandlerResourceV3ProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NuGet.Configuration; | ||
using NuGet.Protocol.Core.Types; | ||
using NuGet.Test.Utility; | ||
using Xunit; | ||
|
||
namespace NuGet.Protocol.Tests | ||
{ | ||
public class HttpHandlerResourceV3ProviderTests | ||
{ | ||
private readonly string _testPackageSourceURL = "https://contoso.test/v3/index.json"; | ||
|
||
#if IS_DESKTOP | ||
[PlatformFact(Platform.Windows)] | ||
public async Task DefaultMaxHttpRequestsPerSourceIsForwardedToV3HttpClientHandler_SuccessAsync() | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL); | ||
var sourceRepository = new SourceRepository(packageSource, new List<INuGetResourceProvider>() { new HttpSourceResourceProvider(), new HttpHandlerResourceV3Provider() }); | ||
|
||
// HttpSourceResourceProvider updates PackageSource.MaxHttpRequestsPerSource value for .NET Framework code paths | ||
// HttpSource constructor accepts a delegate that creates HttpHandlerResource and it stores the delegate in a private variable. | ||
// Hence used discard to ignore the return value and fetched HttpHandlerResource from the source repository to verify behavior. | ||
_ = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Act | ||
HttpHandlerResource httpHandlerResource = await sourceRepository.GetResourceAsync<HttpHandlerResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpHandlerResource); | ||
Assert.Equal(64, httpHandlerResource.ClientHandler.MaxConnectionsPerServer); | ||
} | ||
|
||
[PlatformTheory(Platform.Windows)] | ||
[InlineData(128)] | ||
[InlineData(256)] | ||
public async Task PackageSourceMaxHttpRequestsPerSourceIsForwardedToV3HttpClientHandler_SuccessAsync(int maxHttpRequestsPerSource) | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL) { MaxHttpRequestsPerSource = maxHttpRequestsPerSource }; | ||
var sourceRepository = new SourceRepository(packageSource, new List<INuGetResourceProvider>() { new HttpSourceResourceProvider(), new HttpHandlerResourceV3Provider() }); | ||
|
||
// HttpSourceResourceProvider updates PackageSource.MaxHttpRequestsPerSource value for .NET Framework code paths | ||
// HttpSource constructor accepts a delegate that creates HttpHandlerResource and it stores the delegate in a private variable. | ||
// Hence used discard to ignore the return value and fetched HttpHandlerResource from the source repository to verify behavior. | ||
_ = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Act | ||
HttpHandlerResource httpHandlerResource = await sourceRepository.GetResourceAsync<HttpHandlerResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpHandlerResource); | ||
Assert.Equal(maxHttpRequestsPerSource, httpHandlerResource.ClientHandler.MaxConnectionsPerServer); | ||
} | ||
#elif IS_CORECLR | ||
|
||
[Theory] | ||
[InlineData(64)] | ||
[InlineData(128)] | ||
[InlineData(2)] | ||
public async Task PackageSourceMaxHttpRequestsPerSourceIsNotForwardedToV3HttpClientHandler_SuccessAsync(int maxHttpRequestsPerSource) | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL) { MaxHttpRequestsPerSource = maxHttpRequestsPerSource }; | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpHandlerResourceV3Provider() }); | ||
|
||
// HttpSourceResourceProvider updates PackageSource.MaxHttpRequestsPerSource value for .NET Framework code paths | ||
// HttpSource constructor accepts a delegate that creates HttpHandlerResource and it stores the delegate in a private variable. | ||
// Hence used discard to ignore the return value and fetched HttpHandlerResource from the source repository to verify behavior. | ||
_ = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Act | ||
HttpHandlerResource httpHandlerResource = await sourceRepository.GetResourceAsync<HttpHandlerResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpHandlerResource); | ||
Assert.NotEqual(maxHttpRequestsPerSource, httpHandlerResource.ClientHandler.MaxConnectionsPerServer); | ||
} | ||
#endif | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
test/NuGet.Core.Tests/NuGet.Protocol.Tests/HttpSourceResourceProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using NuGet.Configuration; | ||
using NuGet.Protocol.Core.Types; | ||
using NuGet.Test.Utility; | ||
using Xunit; | ||
|
||
namespace NuGet.Protocol.Tests | ||
{ | ||
public class HttpSourceResourceProviderTests | ||
{ | ||
private readonly string _testPackageSourceURL = "https://contoso.test/v3/index.json"; | ||
|
||
#if IS_DESKTOP | ||
[PlatformFact(Platform.Windows)] | ||
public async Task WhenMaxHttpRequestsPerSourceIsNotConfiguredThenItsValueIsSetToDefault_SuccessAsync() | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL); | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpSourceResourceProvider() }); | ||
|
||
// Act | ||
HttpSourceResource httpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpSourceResource); | ||
Assert.Equal(64, sourceRepository.PackageSource.MaxHttpRequestsPerSource); | ||
} | ||
#elif IS_CORECLR | ||
[Fact] | ||
public async Task WhenMaxHttpRequestsPerSourceIsNotConfiguredThenItsValueWillNotBeUpdated_SuccessAsync() | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL); | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpSourceResourceProvider() }); | ||
|
||
// Act | ||
HttpSourceResource httpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpSourceResource); | ||
Assert.Equal(0, sourceRepository.PackageSource.MaxHttpRequestsPerSource); | ||
} | ||
#endif | ||
|
||
[PlatformTheory] | ||
[InlineData(128)] | ||
[InlineData(256)] | ||
public async Task WhenMaxHttpRequestsPerSourceIsConfiguredThenItsValueWillNotBeUpdated_SuccessAsync(int maxHttpRequestsPerSource) | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL) { MaxHttpRequestsPerSource = maxHttpRequestsPerSource }; | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpSourceResourceProvider() }); | ||
|
||
// Act | ||
HttpSourceResource httpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpSourceResource); | ||
Assert.Equal(maxHttpRequestsPerSource, sourceRepository.PackageSource.MaxHttpRequestsPerSource); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people set the MaxHTTPRequestPerSource explicitly we should always respect that.
Doesn't this break that in dotnet.exe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If customers have configured
MaxHttpRequestsPerSource
then throttling requests is controlled by following code in both.NET
and.NET Framework
code paths. we don't change the value to64
(which is new default).NuGet.Client/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpSourceResourceProvider.cs
Lines 46 to 49 in a56c42d
The only difference is, in
.NET Framework
code path if customers configureMaxHttpRequestsPerSource
then above logic controls throttling requests and we also setHttpClientHandler.MaxConnectionsPerServer
toMaxHttpRequestsPerSource
value. The reason is customers may expect NuGet to send that many requests to a source in parallel but at the end because of the defaultMaxConnectionsPerServer
only2
requests are sent. Whereas in.NET
code paths above logic controls throttling requests and we don'tMaxConnectionsPerServer
because its default value isInt32.MaxValue
.