Using ASP.NET MVC with NET 4.5. There is a singleton HttpClient instance which is used to communicate with another ASP.NET WebAPI application.
I have noticed a large number of connections towards the port used by the WebAPI app. It was weird, considering I use a single HTTP client instance.
To investigate the issue, I set the connection limit prior to creating the HTTP client like this:
// baseAddress is "http://localhost:1900/api/"
var sp = ServicePointManager.FindServicePoint(new Uri(baseAddress));
// maxConnections = 20
sp.ConnectionLimit = maxConnections;
I created another method which returns the ServicePoint instance for the given endpoint. And after some hundred requests, I invoked this method to see what's going on. Here is the result:
{
BindIPEndPointDelegate: null,
ConnectionLeaseTimeout: 60000,
Address: "http://localhost:1900/api/",
MaxIdleTime: 100000,
UseNagleAlgorithm: true,
ReceiveBufferSize: -1,
Expect100Continue: true,
IdleSince: "/Date(1518431339114)/",
ProtocolVersion: {
Major: 1,
Minor: 1,
Build: -1,
Revision: -1,
MajorRevision: -1,
MinorRevision: -1
},
ConnectionName: "http",
ConnectionLimit: 20,
CurrentConnections: 560,
Certificate: null,
ClientCertificate: null,
SupportsPipelining: true
}
Note how CurrentConnections
is significantly larger than ConnectionLimit
.
What gives, any clue?