什么时候创建物理分区?

时间:2018-05-14 11:12:29

标签: azure azure-cosmosdb

我有一个分区集合,它使用5位数的成员资格代码作为其分区键。集合中可能有数千个分区键。

我在其中插入了大约32K文件。使用Partition Stats示例:

Summary:
        partitions: 1
        documentsCount: 32,190
        documentsSize: 0.045 GB

但是只有一个物理分区!如果我使用门户网站指标,我会看到类似的事情:

enter image description here

这是不是意味着我的所有查询都针对单个物理分区? Cosmos何时添加更多物理分区?

我问的原因是因为我看到非常糟糕的性能,当我加载测试时严重恶化。例如,这个简单的计数方法在轻度测试中快速启动,然后在系统受压时需要几秒钟(忽略handler个东西):

    private async Task<int> RetrieveDigitalMembershipRefreshItemsCount(string code, string correlationId)
    {
        var error = "";
        double cost = 0;
        var handler = HandlersFactory.GetProfilerHandler(_loggerService, _settingService);
        handler.Start(LOG_TAG, "RetrieveDigitalMembershipRefreshItemsCount", correlationId);

        try
        {
            if (this._docDbClient == null)
                throw new Exception("No singleton DocDb client!");

            // Check to see if there is a URL
            if (string.IsNullOrEmpty(_docDbDigitalMembershipsCollectionName))
                throw new Exception("No Digital Memberships collection defined!");

            FeedOptions queryOptions = new FeedOptions { MaxItemCount = 1, PartitionKey = new Microsoft.Azure.Documents.PartitionKey(code.ToUpper()) };

            return await _docDbClient.CreateDocumentQuery<DigitalMembershipDeviceRegistrationItem>(
                        UriFactory.CreateDocumentCollectionUri(_docDbDatabaseName, _docDbDigitalMembershipsCollectionName), queryOptions)
                        .Where(e => e.CollectionType == DigitalMembershipCollectionTypes.RefreshItem && e.Code.ToUpper() == code.ToUpper())
                        .CountAsync();
        }
        catch (Exception ex)
        {
            error = ex.Message;
            throw new Exception(error);
        }
        finally
        {
            handler.Stop(error, cost, new
            {
                Code = code
            });
        }
    }

以下是此方法的日志,因为测试按最高持续时间排序。最初它只需要几毫秒:

enter image description here

我尝试了大多数性能提示,即直接模式,相同区域,单例。任何帮助将非常感激。

感谢。

1 个答案:

答案 0 :(得分:0)

分区密钥用于逻辑分区,跨物理分区分发数据。物理分区管理由Azure Cosmos DB管理。

只要初始容器创建的吞吐量至少为1000 RU / s且指定了分区键,就可以实现物理分区的自动拆分。拆分主要将一个物理分区中的逻辑分区分配给不同的物理分区。这个过程对我们来说是透明的。

物理分区的两种情况:

  • 配置吞吐量高于设置值,Azure Cosmos DB会拆分一个或多个物理分区以支持更高的吞吐量。
  • 物理分区",达到其存储限制,Azure Cosmos DB将p无缝拆分为两个新的物理分区。如果p内部只有一个逻辑分区,则拆分不会发生。

因此,如果不满足这些条件,则只有一个物理分区。但是查询是使用分区键对指定的逻辑分区进行的。

有关详细信息,请参阅Azure Cosmos DB partition

相关问题