Skip to content

Corrects memozation of HttpHandlers. - #3881

Merged
forki merged 1 commit into
fsprojects:masterfrom
ChrSteinert:master
Jul 23, 2020
Merged

forki merged 1 commit into
fsprojects:masterfrom
ChrSteinert:master

Conversation

@ChrSteinert

Copy link
Copy Markdown
Contributor

This is in response to #3850 .
One HttpHandler instance has a connection pool, that is reused for different requests.
Currently, part of the key for the Handler memoization is the request's URL. But the URL is different for basically any request. So in this PR I am truncating the URL for the memoization key to just the host part.

I could not test it, but I assume, that things like the NTLM auth do not break by this. The docs give an example where they also only provide the host part of an URL to the NetworkCredentials.

In my tests for a paket.depedencies file which results in 75 unique packages, not downloaded, only resolved, all from NuGet.org, the current implementation opened 78 TCP connection. The implementation of this PR for the same setup only four. This is the expected amount, as per the supplied configs in https://github.com/fsprojects/Paket/blob/master/src/Paket.Core/Common/NetUtils.fs#L360

@forki

forki commented Jul 22, 2020

Copy link
Copy Markdown
Member

Wow. Cool stuff.
@matthid what do you think?

@matthid

matthid commented Jul 22, 2020

Copy link
Copy Markdown
Member

I'd suggest using System.Uri instead of substringing, other than that there might be a small issue when a single host has multiple feeds and multiple different credentials are used (GitHub NuGet feed for example)? I guess that use-case is quite rare but still.

Question is why the url string actually differs each time, maybe we should always use the raw feed URL here somehow and propagate it through?

@matthid

matthid commented Jul 22, 2020

Copy link
Copy Markdown
Member

You can also release this and see if someone complains...

@ChrSteinert

Copy link
Copy Markdown
Contributor Author

I'd suggest using System.Uri instead of substringing, other than that there might be a small issue when a single host has multiple feeds and multiple different credentials are used (GitHub NuGet feed for example)? I guess that use-case is quite rare but still.

Question is why the url string actually differs each time, maybe we should always use the raw feed URL here somehow and propagate it through?

Using System.Uri might not be the worst idea. I chose to not do it, as it would involve creating an Uri instance every time. But this is not the hottest of paths. I can try and do some measurements, if you want me to.

The issue with multiple credentials does not arise, as this will create a different key for the memoization anyway.

@matthid

matthid commented Jul 22, 2020

Copy link
Copy Markdown
Member

Ah you are right as auth is part of the key as well. Overlooked that, nice.

@forki
forki merged commit cc4ed9e into fsprojects:master Jul 23, 2020
@blair55

blair55 commented Jul 24, 2020 •

Copy link
Copy Markdown

Noticing a problem with this version (5.248.1) on mono 5.4.

The restoration process freezes with output like

Possible Performance degradation, blacklist '1_https://www.nuget.org/api/v2/Packages(Id='argu',Version='3.7')'
Possible Performance degradation, blacklist '1_https://www.nuget.org/api/v2/Packages(Id='servicestack.redis',Version='4.5.4')'
Possible Performance degradation, blacklist '1_https://www.nuget.org/api/v2/Packages(Id='nbuilder',Version='4.0')'
Something went wrong while downloading dbup 3.3.5
Message: Could not download dbup 3.3.5 from https://www.nuget.org/api/v2/package/dbup/3.3.5.
  ==> Trying again
Something went wrong while downloading Microsoft.AspNet.Cors 5.2.3

The problem goes away when pinning Paket to a previous version or using mono 6.

@ChrSteinert

Copy link
Copy Markdown
Contributor Author

Oh noes :(

Maybe mono's implementation of the HttpHandlers are somehow different?

Can we know in the code, which mono version we are running on and the fall back to the old implementation?

@ChrSteinert

Copy link
Copy Markdown
Contributor Author

@blair55 Can you please show us the output of paket with the --verbose switch?

@blair55

blair55 commented Jul 24, 2020

Copy link
Copy Markdown

@ChrSteinert

Copy link
Copy Markdown
Contributor Author

Huh – It got some response from the API in the first place, but then just … failed?!
Can you try to use v3 of the NuGet API as a source? source https://api.nuget.org/v3/index.json @blair55

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.

4 participants