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

limit http request number per source through NuGet.Config #2382

Merged
merged 1 commit into from
Aug 14, 2018

Conversation

zhili1208
Copy link
Contributor

@zhili1208 zhili1208 commented Aug 8, 2018

use maxHttpRequest from nuget.config to throttle http resource
NuGet/Home#4538

@@ -35,5 +35,10 @@ public static SemaphoreSlimThrottle CreateBinarySemaphore()
{
return new SemaphoreSlimThrottle(new SemaphoreSlim(1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can use CreateSemaphoreThrottle(initialCount: 1)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

@@ -2813,6 +2821,75 @@ public void LoadPackageSources_DoesNotLoadClearedSource()
}
}

[Fact]
public void LoadPackageSources_SetMaxHttpRequest()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a functional test against Mock server that actually verifies the expected behavior?

@@ -19,6 +19,7 @@ public static class SettingsUtility
private const string HttpCacheEnvironmentKey = "NUGET_HTTP_CACHE_PATH";
private const string PluginsCacheEnvironmentKey = "NUGET_PLUGINS_CACHE_PATH";
private const string RepositoryPathKey = "repositoryPath";
private const string MaxHttpRequest = "maxHttpRequest";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a little ambiguous... could this somehow reflect concurrency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this not really impact concurrency, we still have same operation level concurrency, but limit the http request number per source, NPM is using "maxSockets" for this feature, so I think "maxHttpRequest" may be more accurate for this flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't give the right picture, since this config is per source so I'd expect the name reflect that meaning. It should clearly state that this is max http requests per source

Copy link
Member

@joelverhagen joelverhagen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but don't block on me.

@joelverhagen
Copy link
Member

Is there a corresponding work item for documentation update?

var throttle = Throttle ?? NullThrottle.Instance;
if (Throttle != null)
{
throttle = Throttle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our docs should clearly says that --disable-parallel takes precedent over MaxHttpRequests

{
throttle = Throttle;
}
else if (source.PackageSource.MaxHttpRequest > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can move it under IsHttp check

await Task.WhenAll(tasks);

// Assert
Assert.True(tc.MessageHandler.MaxConcurrencyRequest <= 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following this test, by this line, all tasks have been awaited so wouldn't it always be 0?

Ideally you should check for MaxConcurrencyRequest before await Task.WhenAll(tasks);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, we never decrement MaxConcurrencyRequest so once it reaches 4 it stays as is. So it should be good.

@zhili1208
Copy link
Contributor Author

NuGet/Home#7190 for doc change

return result;
}

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the default be 1 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, if this not set, we will not set throttle, unlimited is the default.

Copy link
Contributor

@rohit21agrawal rohit21agrawal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, with minor comment about 0 being returned in case the value isn't parsed correctly.

@zhili1208 zhili1208 force-pushed the dev-zhi-maxrequest branch 2 times, most recently from 6bc0ee6 to 6e384e0 Compare August 13, 2018 21:32
@nkolev92
Copy link
Member

I think this merge with only 1 approval was a bit premature because of how tricky this topic is.

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great.

@ulrichb
Copy link

ulrichb commented May 15, 2020

With which version has this been released?

I tried to add ...

  <config>
      <add key='maxHttpRequestsPerSource' value='2' />
  </config>

... to my user NuGet.config and have still hundreds of connections during dotnet restore (2.1 SDK).

@rrelyea
Copy link
Contributor

rrelyea commented May 15, 2020

looks like these 2 commits are interesting. The tags on those commits say that they were in nuget 5.0 and later.
ec2b543
0a956cd

Release Notes for NuGet 5.0 seem to indicate that sdk 2.1.602 and later should have this change.

@ulrichb
Copy link

ulrichb commented May 15, 2020

@rrelyea Many thanks for your reply!

I have the VS 2017 version of the 2.1 SDK (2.1.514) which seems to bind NuGet 4.9.x :(

Any chance to get this backported to NuGet 4.9?

@rrelyea
Copy link
Contributor

rrelyea commented May 15, 2020

We have not backported any non security fixes to 4.9. So it is unlikely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants