Azure表存储:查询多个PK-RK对的有效方法

时间:2017-05-16 19:21:02

标签: azure azure-table-storage

我正在使用此过滤器进行查询:   (PartitionKey eq' A'或PartionKey eq' B'或...)和RowKey eq' RK'

我意识到这种20到100个PK的查询需要3到5秒。桌子上的物品总量不多(大约100万)

我认为正在进行部分扫描查询。我认为它会做几个puntual查询,但似乎并非如此。

我的另一个选择是执行独立的并行查询,然后合并结果。

  • 这是100件物品的好选择吗?
  • 我不会遇到网络连接问题? (我使用ServicePointManager.DefaultConnectionLimit增加它们)

注意:并非所有PK / RK对都会检索记录。

1 个答案:

答案 0 :(得分:0)

  

我的另一个选择是执行独立的并行查询,然后合并结果。

它将在Azure存储上保存查询时间,但会在查询请求和结果响应上花费更多时间。我有一个160K实体的表。我编写了两个示例代码来测试从一个查询和多个查询中查询实体的总时间。这是我的测试结果。

enter image description here

以下是我的示例代码。

从一个查询中查询实体。

    do{
            let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : Any]

            if let main = json["LIBRARY"] as? [[String : Any]]{

                for data in main {
                    var info = Modal()
                    info.name = data["NAME"] as? String
                    info.id = data["ID"] as? String
                    info.ImageViewURL = data["PICTURE"] as! String
                    print(info.id)

                    if let filesArray = data["FILES"] as? [[String : Any]] {
                        for file in filesArray {
                            var info = Modal()
                            info.name = file["NAME"] as? String
                            info.audioUrl = file["SRC"] as? String

                            print(info.name! as Any)
                            print(info.audioUrl! as Any, "\n")

                            self.modals.append(info)
                        }

                    }

                    print(info.name)

                    self.modals.append(info)

                }
            }

        } catch let error {
            print(error)
        }

从并行多查询中查询实体。

int entitesCount = 20;
TableQuery<CustomerEntity> customerQuery = new TableQuery<CustomerEntity>();
string filter = "(";
for (int i = 0; i < entitesCount; i++)
{
    filter = filter + "PartitionKey eq '" + i + "'";
    if (i < entitesCount - 1)
    {
        filter = filter + " or ";
    }
}
filter = filter + ") and RowKey eq '42'";
customerQuery.FilterString = filter;

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();

var customers = table.ExecuteQuery(customerQuery);
Console.WriteLine(customers.Count().ToString());

stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Console.WriteLine(ts.ToString());
  

Azure表存储:查询多个PK-RK对的有效方法

我建议你测试一下,确定哪一种方式很好。