【问题标题】:windows azure table storage, how do I enable keep alivewindows azure 表存储,如何启用保持活动状态
【发布时间】:2017-10-02 20:18:22
【问题描述】:

目前我像这样放入 azure 表存储:

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);
}

我做了很多推杆,但速度很慢。当我打开 fidller 时,它们变得快 40 倍。在检查了为什么 fiddler 使用 connection: keep-alive 标头重用连接之后。有没有办法使用表存储api来做到这一点?

【问题讨论】:

    标签: azure azure-table-storage


    【解决方案1】:

    : 将此添加到应用程序的启动代码中:

            ServicePointManager.DefaultConnectionLimit = 100; // Default 2
            ServicePointManager.UseNagleAlgorithm = false; // Default true
    

    说明

    您不必添加任何 Keep-Alive 标头,它们已经存在。看看HttpWebRequestFactory(第 86 行):

    #if WINDOWS_DESKTOP && !WINDOWS_PHONE
                request.KeepAlive = true;
    
                // Disable the Expect 100-Continue
                request.ServicePoint.Expect100Continue = false;
    #endif
    
                return request;
            }
    

    除此之外,HttpWebRequest 默认使用 HTTP 1.1,makes connection persistent by default

    您可以使用TcpView 来查看该连接正在被重用。

    Fiddler 之所以如此之快,主要是因为它在重用连接、批处理和缓冲请求方面非常聪明,尤其是当您的应用程序发出大量并行请求时。

    默认情况下ServicePointManager.DefaultConnectionLimit 是 2,这意味着您只能同时有 2 个待处理的请求。想象一下,你有 8 个线程试图发出请求,其中 2 个可以同时处于活动状态,其余的正在等待。提高限制会大大提高并发请求数。

    另一个问题是ServicePointManager.UseNagleAlgorithm 默认启用。由于大多数 Azure Table 请求都比较小(HTTP 消息大小 at Microsoft Azure Storage Team Blog (Nagle’s Algorithm is Not Friendly towards Small Requests)的解释

    【讨论】:

      猜你喜欢
      • 2010-11-19
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多