19

Does HttpClient use the same ServicePoint Connection Limit as HttpWebRequest?

Thanks

user836101
  • 205
  • 1
  • 2
  • 6

3 Answers3

24

The answer is not complete. It depends on implementation. In .net core ServicePointManager.DefaultConnectionLimit setting is not used, HttpClientHandler.MaxConnectionsPerServer should be used instead.

https://blogs.msdn.microsoft.com/timomta/2017/10/23/controlling-the-number-of-outgoing-connections-from-httpclient-net-core-or-full-framework/

  • When using DI, this is configured with: `services.AddHttpClient(clientName).ConfigurePrimaryHttpMessageHandler(sp => new HttpClientHandler() { MaxConnectionsPerServer = 2 });` Also note that `SocketsHttpHandler` is the newer implementation of `HttpMessageHandler` compared to `HttpClientHandler`, but you can still use `HttpClientHandler` as it seems to be more flexible and just forwards through to `SocketsHttpHandler` anyway. – Jez Aug 25 '23 at 15:43
5

It uses the same ServicePointManager so the answer is yes.

You can change the limit programmatically though if you want, see this

Alexander Balabin
  • 2,055
  • 11
  • 13
4

Since I couldn't find an official answer anywhere in the docs, decompiling the code for .NET 6 yields a default value of int.MaxValue for HttpClientHandler.MaxConnectionsPerServer.

This should also be true for any version of .NET Core.

namespace System.Net.Http
{
    internal static partial class HttpHandlerDefaults
    {
        public const int DefaultMaxConnectionsPerServer = int.MaxValue;
        ...
    }
}
Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44