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

Fix: HttpClientFactory: resolving a typed client is significantly slower that resolving a named client. #2063

Merged
merged 3 commits into from
Jul 19, 2019

Conversation

rynowak
Copy link
Member

@rynowak rynowak commented Jul 19, 2019

See commits for details.

BenchmarkDotNet=v0.10.13, OS=Windows 10.0.18362
Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R), 1 CPU, 8 logical cores and 4 physical cores
.NET Core SDK=3.0.100-preview6-012264
  [Host]     : .NET Core 3.0.0-preview8-27919-01 (CoreCLR 4.700.19.36901, CoreFX 4.700.19.36803), 64bit RyuJIT
  Job-PYIOAJ : .NET Core 3.0.0-preview8-27919-01 (CoreCLR 4.700.19.36901, CoreFX 4.700.19.36803), 64bit RyuJIT

Runtime=Core  Server=True  Toolchain=.NET Core 3.0  
RunStrategy=Throughput  

Before:

Method Mean Error StdDev Median Op/s Scaled ScaledSD Gen 0 Allocated
'use IHttpClientFactory with named client' 13.87 us 0.2708 us 0.3521 us 13.84 us 72,116.5 1.23 0.08 7.8125 3.18 KB
'use IHttpClientFactory with typed client' 500.04 us 17.8916 us 52.1905 us 515.59 us 1,999.9 44.26 5.34 - 8.63 KB
'new HttpClient' 11.34 us 0.2386 us 0.6922 us 11.28 us 88,183.9 1.00 0.00 7.8125 2.66 KB

After:

Method Mean Error StdDev Op/s Scaled ScaledSD Gen 0 Allocated
'use IHttpClientFactory with named client' 11.065 us 0.2203 us 0.4549 us 90,376.9 1.88 0.09 7.8125 3.17 KB
'use IHttpClientFactory with typed client' 13.362 us 0.2660 us 0.6059 us 74,839.8 2.27 0.11 7.8125 3.28 KB
'new HttpClient' 5.877 us 0.1116 us 0.1194 us 170,146.8 1.00 0.00 6.8359 2.67 KB

@rynowak
Copy link
Member Author

rynowak commented Jul 19, 2019

/cc @damianh

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

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

From my limited knowledge, this looks good.

Ryan Nowak added 3 commits July 19, 2019 15:27
Fixes: #2060

The DefaultTypedClientFactory.Cache type was intended to be a singleton.
It turns out transient caches don't work well.
@rynowak rynowak merged commit 627bf65 into master Jul 19, 2019
@ghost ghost deleted the rynowak/fix-2060 branch July 19, 2019 23:36
@ghost ghost locked as resolved and limited conversation to collaborators May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants