并行查询Azure存储 [英] Parallel Querying Azure Storage

查看:138
本文介绍了并行查询Azure存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个queury沿的线条看起来:

I currently have a queury which looks along the lines of:

TableQuery<CloudTableEntity> query = new TableQuery<CloudTableEntity().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, PK));

foreach (CloudTableEntity entity in table.ExecuteQuery(query))
{
    //Logic
}

我一直在研究有关的相似之处,但是,我找不到如何使用它的任何好的code的例子。我希望能够查询数千分区键像

I been researching about parallels, however, I cannot find any good code examples on how to use it. I want to be able to query thousands of partition keys like

CloudTableEntity()。其中​​(PartitionKey ==11|| PartitionKey ==22)

我在哪里可以有40000左右分区键。有没有做到这一点的好办法?

Where I can have around 40000 Partition keys. Is there a good way to do this?

推荐答案

下面的示例code会发出多个并行的分区键查询:

The following sample code will issue multiple partition key queries in parallel:

     CloudTable table = tableClient.GetTableReference("xyztable");
     List<string> pkList = new List<string>(); // Partition keys to query
     pkList.Add("1");
     pkList.Add("2");
     pkList.Add("3");
     Parallel.ForEach(
        pkList,
        //new ParallelOptions { MaxDegreeOfParallelism = 128 }, // optional: limit threads
        pk => { ProcessQuery(table, pk); }
     );

其中ProcessQuery定义为:

Where ProcessQuery is defined as:

  static void ProcessQuery(CloudTable table, string pk)
  {
     string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, pk);
     TableQuery<TableEntity> query = new TableQuery<TableEntity>().Where(pkFilter);
     var list = table.ExecuteQuery(query).ToList();
     foreach (TableEntity entity in list)
     {
        // Process Entities
     }
  }

请注意,在同一查询或运算两片分键,你上面列出的将导致全表扫描。为了避免全表扫描,执行各个查询,每个查询的一个分区键上面的例子code演示。

Note that ORing two partition keys in the same query as you listed above will result in a full table scan. To avoid a full table scan, execute individual queries with one partition key per query as the sample code above demonstrates.

有关查询构造的更多详细信息,请参阅<一个href=\"http://blogs.msdn.com/b/windowsazurestorage/archive/2010/11/06/how-to-get-most-out-of-windows-azure-tables.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/windowsazurestorage/archive/2010/11/06/how-to-get-most-out-of-windows-azure-tables.aspx

For more details on query construction please see http://blogs.msdn.com/b/windowsazurestorage/archive/2010/11/06/how-to-get-most-out-of-windows-azure-tables.aspx

这篇关于并行查询Azure存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆