-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Update HttpClient.xml #4330
Update HttpClient.xml #4330
Conversation
The documentation suggests using one HttpClient instance, which is reused in the application. However in multithreaded applications, doing http requests to the same server will quickly exhaust the maximum allowed concurrent connection limit (2 or 10 for web applications), which can degrade performance.
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.
Thanks for contributing to the dotnet/docs repo, @feherzsolt, and for submitting this PR to provide additional information about the HttpClient class. I have a number of suggested changes.
Also, @davidsh, could you review this PR, please?
xml/System.Net.Http/HttpClient.xml
Outdated
@@ -66,6 +66,8 @@ public class GoodController : ApiController | |||
} | |||
|
|||
``` | |||
|
|||
By default <xref:System.Net.ServicePointManager.DefaultConnectionLimit> will define the maximum number of concurrent connections to the same server. |
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.
comma after "default"
after defaultConnectionLimit, ?displayProperty=nameWithType
will define --> defines
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.
Thank you, i have added the changes.
Suggested changes.
I don't understand why adding this line of text about ServicePointManager helps the HttpClient documentation. It seems out of place here since the documentation is all about HttpClient class. Yes, there is a relationship between HttpClient and ServicePointManager. That is an artifact of the history of how the class was introduced since it uses HttpWebRequest underneath for the networking implementation and thus is subject to limits of the "global" settings of ServicePointManager. However, for other platforms like .NET Core, for example, ServicePointManager is not fully implemented, nor supported and the settings on it don't affect HttpClient in the same way (or at all). cc: @karelz @stephentoub |
I think it would makes sense to mention top problems / gotchas related to using single instance of HttpClient in your app near the sample code. We should IMO cover limit of connections per server and Dns refresh problem (incl. guidance to periodically replace HttpClient singleton, or using HttpClientFactory once it is released). |
Thank you for checking out the PR. |
Thanks, @karelz and @davidsh. Your suggestion sounds good, @karelz. Since the issue goes beyond this PR, what I think we should do is open a GitHub issue to address the issues raised by @feherzsolt and @karelz in an implementation-specific way. Once the issue is open, I'll close the PR. Since I'm at an offsite, I'll open it early next week at the latest, unless you'd like to open it earlier, @feherzsolt. |
That sounds good. Please open the issue @rpetrusha when you get back. Thank you all for the help. |
Title
Add additional remark about connection limit
Summary
The documentation suggests using one HttpClient instance, which is reused in the application. However in multithreaded applications, doing http requests to the same server will quickly exhaust the maximum allowed concurrent connection limit (2 or 10 for web applications), which can degrade performance. I think developers following the guidance about one HttpClient in the application would benefit having this piece of information.