2017-09-27 51 views
0

我们使用Azure blob存储来存储来自数据馈送(我们每天接收大约1.5GB数据)的传入消息,然后处理它们,这些消息是通过消息触发的队列(rabbitmq)。下面是设置的样子:Azure Blob存储.Net客户端库和TCP连接随着时间的推移

生产者 - 在Azure中的BLOB>存储XML文件 - >发布BLOB地址排队

消费 - >读队列中的BLOB地址 - >在内存中下载的blob

这里是每个消息执行下载的blob方法:

private string GetBlobText(string containerName, string blobName) 
{ 
    // Parse the connection string and return a reference to the storage account. 
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Settings.Default.DatafeedStorageConnString); 
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 
    CloudBlobContainer container = blobClient.GetContainerReference(containerName); 
    CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName); 
    return blockBlob.DownloadText(Encoding.UTF8); 
} 

这条管道是在一个相当频繁的速度运行,因此我们看到,随着时间的推移(几个星期)的节目开始接收套接字错误。下面是跟踪:

Microsoft.WindowsAzure.Storage.StorageException: Unable to connect to the remote server ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 40.68.232.24:443 
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) 
    --- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.GetResponse() 
    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 695 
    --- End of inner exception stack trace --- 
    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 604 
    at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.DownloadRangeToStream(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlob.cs:line 675 
    at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.DownloadToStream(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlob.cs:line 234 
    at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadText(Encoding encoding, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 1279 

这似乎像没有有效地处理连接的问题,我们曾试图重用blobClient,但是这并没有帮助我们。我们还需要进一步解决这个问题呢?

回答

1

Microsoft.WindowsAzure.Storage.StorageException:无法连接到远程服务器---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:不能因为系统缺乏足够的缓冲空间或执行套接字上的操作,因为队列已满40.68.232.24:443(blob.am5prdstr02a.store.core.windows.net)

按我的理解,它可能是TCP/IP端口耗尽。我假设您可以使用Netstat来查询您的网络连接状态和您正在使用的端口。有关更多详细信息,请参阅here以获取解释和解决此问题的方法。

如果您的客户端计算机发生端口耗尽,我认为您可以增加用于客户端TCP/IP套接字连接的短暂端口的上限范围,并减少客户端TCP/IP套接字连接超时,有关更多详细信息,请参阅here。此外,您可以将客户端应用程序扩展到不同计算机之间的多个实例。

+0

通过在不同计算机上拆分实例来扩展规模肯定会有所帮助。但是我们面临的问题是,在此期间,与TIME_WAIT的TCP连接加起来耗尽了端口。 – maulik13