c# - Microsoft.Azure.Cosmos.Table 和 Microsoft.WindowsAzure.Storage 之间的 ExecuteQuerySegmentedAsync 性能显着下降
问题描述
我一直在研究从存储帐户表存储迁移到 CosmosDB 表存储。目前我正在使用 WindowsAzure.Storage (9.3.3) 库来查询 .net core 3.1 应用程序中的数据。作为此迁移的一部分,我已切换到 Microsoft.Azure.Cosmos.Table 1.0.7 库。我在下面编写了 LinqPad 基准测试来比较两者在进行全表扫描时的性能。
async Task Main()
{
var timer = Stopwatch.StartNew();
await QueryCosmosDb().ConfigureAwait(false);
timer.Stop();
var cosmosExecutionTime = timer.Elapsed;
timer = Stopwatch.StartNew();
await QueryTableStorage().ConfigureAwait(false);
timer.Stop();
var tableExecutionTime = timer.Elapsed;
cosmosExecutionTime.Dump();
tableExecutionTime.Dump();
}
public async Task QueryCosmosDb()
{
var cosmosTableEndpoint = new Uri($"https://***.table.cosmos.azure.com:443/");
var storageAccount = new Microsoft.Azure.Cosmos.Table.CloudStorageAccount(new Microsoft.Azure.Cosmos.Table.StorageCredentials("***", "****"), cosmosTableEndpoint);
var client = storageAccount.CreateCloudTableClient();
var table = client.GetTableReference("tablename");
var query = new Microsoft.Azure.Cosmos.Table.TableQuery();
Microsoft.Azure.Cosmos.Table.TableContinuationToken token = null;
do
{
var segment = await table.ExecuteQuerySegmentedAsync(query, token).ConfigureAwait(false);
token = segment.ContinuationToken.Dump();
}
while (token != null);
}
public async Task QueryTableStorage()
{
var storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("***", "****"), true);
var client = storageAccount.CreateCloudTableClient();
var table = client.GetTableReference("tablename");
var query = new Microsoft.WindowsAzure.Storage.Table.TableQuery();
Microsoft.WindowsAzure.Storage.Table.TableContinuationToken token = null;
do
{
var segment = await table.ExecuteQuerySegmentedAsync(query, token).ConfigureAwait(false);
token = segment.ContinuationToken;
}
while (token != null);
}
存储帐户表和 CosmosDb 表具有大约 200k 个实体的相同数据集。
Cosmos 表帐户的共享供应吞吐量为 2200 RU。
将 Cosmos Executor 与 Microsoft.Azure.Cosmos.Table 库一起使用时,执行时间约为 3 小时。带有 Microsoft.WindowsAzure.Storage 库的存储帐户表大约需要 2 分钟。如果我将 Microsoft.Azure.Cosmos.Table 库切换为使用 Cloud Table Client 中的其余执行程序,我会得到约 3 分钟的执行时间。
有没有人遇到过类似的行为或意识到空表查询的问题?
解决方案
它是导致时差的 ExecuteQuery 方法的内部实现,因此除非 Microsoft 在即将发布的版本中注意到并修复该问题,否则我们不可能解决该问题,无论如何,既然他们已经弃用并使用Microsoft.Azure.Cosmos
它必须使用的公共库解决了问题,希望对你有帮助
推荐阅读
- python - 子字符串中的字符串
- node.js - 带有 Firebase (FCM) 推送通知的 Node js
- amazon-web-services - 无法在 AWS 安全组入站规则中添加 141.160.25.36/28、141.160.4.51/29
- android - 使用firebase保存项目移动时recyclerview的位置
- java - 将 maven 与第三方的 DLL 一起使用并管理 DLL 的名称
- php - php jquery mysql-更好的方式来加载更多
- css - Normalize.css 不工作 Angular 4/5
- go - 在 Golang 中重新排序地图
- csv - Golang 写新的 CSV 列
- mongodb - MongoDB,如何合并 2 个集合和搜索合并数据(不是简单的合并)