.NET 4.5 - HttpClient似乎不尊重ServicePoint ConnectionLimit

时间:2018-02-12 10:32:46

标签: c# asp.net .net dotnet-httpclient

在.NET 4.5中使用ASP.NET MVC。 有一个单例HttpClient实例,用于与另一个ASP.NET WebAPI应用程序通信。

我注意到WebAPI应用程序使用的端口有大量连接。考虑到我使用单个HTTP客户端实例,这很奇怪。

为了调查此问题,我在创建HTTP客户端之前设置了连接限制,如下所示:

// baseAddress is "http://localhost:1900/api/"
var sp = ServicePointManager.FindServicePoint(new Uri(baseAddress));

// maxConnections = 20
sp.ConnectionLimit = maxConnections;

我创建了另一个返回给定端点的ServicePoint实例的方法。在几百个请求之后,我调用了这个方法来查看发生了什么。结果如下:

{
    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
}

请注意CurrentConnections显着大于ConnectionLimit的方式。 什么给出了任何线索?

0 个答案:

没有答案