windows azure表存储,如何启用保持活动状态
目前,我将以下内容放入azure表存储:windows azure表存储,如何启用保持活动状态,azure,azure-table-storage,Azure,Azure Table Storage,目前,我将以下内容放入azure表存储: public static void AzurePut(string Key, byte[] Value) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); var ke
public static void AzurePut(string Key, byte[] Value)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
var keyhash = MyTable.CalculateMD5Hash(Key);
var tc = MyTable.GetBinFromHash(keyhash, AzureTables.TableCount);
CloudTable table = tableClient.GetTableReference("table" + tc);
var entity = new AzureEntity();
entity.Key = keyhash;
entity.SetValue(Value);
TableOperation insertOperation = TableOperation.InsertOrReplace(entity);
table.Execute(insertOperation);
}
我做了很多推杆,而且速度很慢。当我打开Fidler时,它们会快40倍。在检查了fiddler使用connection:keep-alive标头重用连接的原因之后。使用表存储api有什么方法可以做到这一点吗?Short:
将以下内容添加到应用程序的启动代码中:
ServicePointManager.DefaultConnectionLimit = 100; // Default 2
ServicePointManager.UseNagleAlgorithm = false; // Default true
解释
您不必添加任何保持活动的标题,它们已经存在了。请看(第86行):
除此之外,默认情况下使用HTTP 1.1
您可以使用查看连接是否被重用
Fiddler之所以如此之快,主要是因为它在重用连接、批处理和缓冲请求方面非常聪明,尤其是当应用程序发出大量并行请求时
默认情况下,ServicePointManager.DefaultConnectionLimit
为2,这意味着您在同一时间只能有2个挂起的请求。假设您有8个线程试图发出请求,其中2个线程可以同时处于活动状态,其余线程正在等待。提高限制可以极大地改进并发请求
另一个问题是默认情况下启用了ServicePointManager.UseNagleAlgorithm
。由于大多数Azure表请求相对较小(HTTP消息大小<1460字节),因此它们不需要缓冲。请参阅更详细的解释
#if WINDOWS_DESKTOP && !WINDOWS_PHONE
request.KeepAlive = true;
// Disable the Expect 100-Continue
request.ServicePoint.Expect100Continue = false;
#endif
return request;
}