2

I want to consume a rest api from my code. Now, for this, I can use WebClient or HttpClient.

However, HttpClient has connection pooling support, as mentioned in the documentation.

every HttpClient instance uses its own connection pool, isolating its requests from requests executed by other HttpClient instances

So, does WebClient has connection pooling support?

as I will be calling this api many a times, hence it do not want "creating new connections for every call" be a overhead for performance during api calls.

So which one should I be using, for better performance?

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
RohitWagh
  • 1,999
  • 3
  • 22
  • 43

1 Answers1

0

I was searching around this to. And found some updated information HttpClient does have connection pools.

TLDR:

var socketHandler = new SocketsHttpHandler()
{
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
    PooledConnectionLifetime = TimeSpan.FromMinutes(10),
    PooledConnectionIdleTimeout = TimeSpan.FromMinutes(5),
    MaxConnectionsPerServer = 10
};

var httpClient = new HttpClient(socketHandler);

You can read more here: https://www.stevejgordon.co.uk/httpclient-connection-pooling-in-dotnet-core

EKS
  • 5,543
  • 6
  • 44
  • 60