By default HttpClient only uses 2 concurrent connections per host. According to docs I can change that. I don't want to change it on a global level, I just want to change it for the service I'm using. Therefore I wrote the following code:
// Increase connection limit in order to have more concurrent requests to MyService
ServicePointManager.FindServicePoint(myServiceUrl, null).ConnectionLimit = 20;
Unfortunately, this doesn't work. The service (called via HttpClient) still uses only 2 concurrent connections. If I change the code to:
ServicePointManager.DefaultConnectionLimit = 20;
At the same code location, it works. However, I don't want to globally change this setting. How to change it locally only?
Edit: I realized that something is setting the connection limit back to 2. Is there any operation (e.g., instantiating a new WebRequestHandler, instantiating a new HttpClient, ...?) which resets the connection limit?
HttpClient does not use ServicePointManager service points.
ServicePointManager is a static class that manages the creation and destruction of ServicePoint instances. The ServicePointManager creates a ServicePoint when the application requests an Internet resource that is not in the collection of existing ServicePoint instances.
I found the problem, we ran into the following .NET bug:
https://github.com/Microsoft/dotnet/blob/master/releases/net471/KnownIssues/534719-Networking.ServicePoint.ConnectionLimit%20default%20behavior%20changed.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With