Azure Table Storage

时间:2015-04-28 07:09:04

标签: php azure azure-table-storage

我正在使用我的PHP应用程序中的Azure表存储,并且看到响应时间非常慢。应用程序每天为每个用户收集报告,并使用分区键$userID . date("dmY")将它们放在分区中。在负载测试期间,由于Azure表存储查询中的1,000个实体限制,在一天中生成了数千个报告,这需要多次往返获取。每次获取1,000个实体的行程最多可能需要2秒钟。


代码:

for($i = 0; $i < $daysToGoBack; $i++)
{
    $filter = "PartitionKey eq '" . $userId . date("dmY", strtotime("-$i days")) . "'";

    $options = new QueryEntitiesOptions();
    $options->addSelectField('created');
    $options->setFilter(Filter::applyQueryString($filter));

    $this->benchmark->mark('main_query');

    $result = $this->tableRestProxy->queryEntities('reports', $filter, $options);

    $this->benchmark->mark('main_query_end');
    echo "Query: " . $this->benchmark->elapsed_time('main_query', 'main_query_end') . "<br/>";

    $entities = array_merge($result->getEntities(), $entities);

    $nextPartitionKey = $result->getNextPartitionKey();
    $nextRowKey = $result->getNextRowKey();

    while(!is_null($nextRowKey) && !is_null($nextPartitionKey)) 
    {
        $options = new QueryEntitiesOptions();
        $options->setNextPartitionKey($nextPartitionKey);
        $options->setNextRowKey($nextRowKey);
        $options->addSelectField('created');
        $options->setFilter(Filter::applyQueryString($filter));

        $this->benchmark->mark('sub_query');

        $newResult = $this->tableRestProxy->queryEntities('reports', $options);

        $this->benchmark->mark('sub_query_end');
        echo "Continuation: " . $this->benchmark->elapsed_time('sub_query', 'sub_query_end') . "<br/>";

        $newEntities = $newResult->getEntities();

        $entities = array_merge($newEntities, $entities);

        $nextPartitionKey = $newResult->getNextPartitionKey();
        $nextRowKey = $newResult->getNextRowKey();
    }


结果:

Query: 1.8183
Continuation: 1.2479
Continuation: 0.2423
Continuation: 0.2619
Continuation: 0.2476
Continuation: 0.2836
Continuation: 0.2345
Continuation: 0.2482
Continuation: 0.2565
Continuation: 0.2187
Continuation: 0.2319
Continuation: 0.2389
Continuation: 0.2221
Query: 0.0320
Query: 0.0338
Query: 0.1038
Query: 0.1263
Query: 0.1841
Query: 0.0547


上面的结果是关于我可以摆脱它的最好结果。第一个查询有近13,000个报告要回退,初始查询也是如此,然后12个回调使用延续令牌。大多数情况下,查询可以在完全相同的数据上花费更长的时间。

Query: 1.8273
Continuation: 1.2592
Continuation: 0.8160
Continuation: 0.8463
Continuation: 0.7474
Continuation: 0.7104
Continuation: 1.3987
Continuation: 1.4321
Continuation: 1.4526
Continuation: 1.3184
Continuation: 0.7390
Continuation: 0.7212
Continuation: 0.2610
Query: 0.0630
Query: 0.1221
Query: 0.0728
Query: 0.1250
Query: 0.1717
Query: 0.0568

这些结果是否可以从Azure中获得,还是有更有效的方法来查询此数据?

1 个答案:

答案 0 :(得分:1)

你签出了Azure Table Storage Design guide吗?这可能有所帮助。