19

Does HttpClient use the same ServicePoint Connection Limit as HttpWebRequest?

Thanks

1

3 Answers 3

25

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/

1
  • 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 at 15:43
6

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;
        ...
    }
}
5

It uses the same ServicePointManager so the answer is yes.

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

1
  • 1
    In .NET 6, ServicePointManager is flagged as Obsolete. Oct 7, 2021 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.