我有一个带有多个节点的集群/服务器来处理来自应用程序的请求。
用户正在运行的应用程序打开 2 个具有以下 URL 的 Web 客户端:
为了支持粘性(我希望 2 个 Web 客户端中的每一个都保持与节点的连接 - 持久性),ConnectionLeaseTimeout保持默认值,这意味着“不要关闭连接”并且因为DefaultPersistentConnectionLimit为 2默认情况下,我将DefaultConnectionLimit设置为 1。
问题:
servicePoint.CurrentConnections 是 2,尽管 servicePoint.ConnectionLimit 是 1。
在服务器中,我看到远程主机端口正在改变,即我看到超过 2 个端口(每个客户端超过 1 个端口)。
我究竟做错了什么?
我的课堂输出:
CommunicationWebClient https://myprocess.myapp.com/api/json/v1
CommunicationWebClient https://myprocess.myapp.com/api/protobuf/v1
SendAsync _uri= https://myprocess.myapp.com/api/json/v1 servicePoint.Address= https://myprocess.myapp.com/api/json/v1 servicePoint.ConnectionLimit=1 servicePoint.CurrentConnections=2
...
SendAsync _uri= https://myprocess.myapp.com/api/protobuf/v1 servicePoint.Address= https://myprocess.myapp.com/api/json/v1 servicePoint.ConnectionLimit=1 servicePoint.CurrentConnections=2
...
public sealed class CommunicationWebClient : IDisposable
{
private HttpClient _httpClient;
private Uri _uri;
public CommunicationWebClient(Uri uri)
{
Logger.Debug($"{nameof(CommunicationWebClient)} {nameof(uri)}={uri}");
_uri = uri;
ServicePointManager.DefaultConnectionLimit = 1;
_httpClient = new HttpClient(new WebRequestHandler())
{
Timeout = 10.Minutes(),
};
}
public void Dispose()
{
_httpClient.Dispose();
}
public async Task SendAsync(
ByteArrayContent content)
{
var servicePoint = ServicePointManager.FindServicePoint(_uri);
Logger.Debug($"{nameof(SendAsync)} " +
$"{nameof(_uri)}={_uri} " +
$"{nameof(servicePoint.Address)}={servicePoint.Address} " +
$"{nameof(servicePoint.ConnectionLimit)}={servicePoint.ConnectionLimit} " +
$"{nameof(servicePoint.CurrentConnections)}={servicePoint.CurrentConnections}");
using (var httpResponseMessage = await _httpClient.PostAsync(_uri, content))
{
...
}
}
}