azure - windows azure 表存储,如何启用保持事件状态

标签 azure azure-table-storage

目前我将像这样放入 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);
}

我做了很多看跌期权,但它们很慢。当我打开 fiddler 时,它们的速度快了 40 倍。检查原因后发现,fiddler 重用了带有 connection: keep-alive header 的连接。有没有办法使用表存储 API 来做到这一点?

最佳答案

简短: 将其添加到应用程序的启动代码中:

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

说明

您不必添加任何 Keep-Alive header ,它们已经存在。看看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 表请求都相对较小(HTTP 消息大小 < 1460 字节),因此不需要对它们进行缓冲。查看对此的更长解释 at Microsoft Azure Storage Team Blog (Nagle’s Algorithm is Not Friendly towards Small Requests)

关于azure - windows azure 表存储,如何启用保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26946893/

相关文章:

Azure 应用程序网关与 Let 加密

Azure 表存储 - 删除列

python - 通过python API获取Windows Azure存储表名称

c# - 动态查询 azure 表

azure - 使用在 Azure 常规区域中创建的应用程序连接到 Azure 中国的 Azure 订阅会出现 "AADSTS70001"错误

azure - 使用用户名和密码写入 Azure Blob

azure - 无法在 DevOps 步骤中设置 powershell 输出变量

php - Azure 表存储响应时间慢

Azure 存储资源管理器 : Properties of type '' are not supported error

azure - 禁用整个 Azure 存储帐户