1

since Http Client should be instantiated once to reuse across application life time, it definitely maintains a connection pool, right? Whats the size of this connection pool?

The HttpClient class instance acts as a session to send HTTP requests. An HttpClient instance is a collection of settings applied to all requests executed by that instance. In addition, every HttpClient instance uses its own connection pool, isolating its requests from requests executed by other HttpClient instances.

HttpClient is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads. This will result in SocketException errors. https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?redirectedfrom=MSDN&view=netframework-4.8#remarks.

Sana.91
  • 1,999
  • 4
  • 33
  • 52
  • I am not sure if there is a specific size. Have a read at this, I assume you are using .NET Core. https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests – Richard Feb 19 '20 at 07:32
  • no i am using .NET framework. @Richard – Sana.91 Feb 19 '20 at 07:53
  • the fact that i am using single instance of HttpClient and am able to achieve around 270 TPS means connections are being re used efficiently from within pool. – Sana.91 Feb 19 '20 at 07:55
  • I may be wrong but I believe its based on the system hardware, specifically CPU cores and RAM. – Kieran Devlin Feb 19 '20 at 08:40

0 Answers0