使用 Azure Cosmos DB Capacity Planner 估算 RU/秒Estimate RU/s using the Azure Cosmos DB capacity planner

针对你的工作负荷为 Azure Cosmos 数据库和容器配置适当数量的预配吞吐量(也称为请求单位(RU/秒))对于优化成本和性能非常重要。Configuring your Azure Cosmos databases and containers with the right amount of provisioned throughput, or Request Units (RU/s), for your workload is essential to optimizing cost and performance. 本文介绍了如何使用 Azure Cosmos DB Capacity Planner 来估算工作负荷所需的吞吐量(RU/秒)。This article describes how to use the Azure Cosmos DB capacity planner to get an estimate of the required RU/s of your workload.

如何使用 Azure Cosmos DB Capacity Planner 估算吞吐量How to estimate throughput with Azure Cosmos DB capacity planner

Capacity Planner 可在两种模式下使用。The capacity planner can be used in two modes.

模式Mode 说明Description
基本Basic 提供快速、大概的 RU/秒估算。Provides a quick, high-level RU/s estimate. 此模式为索引编制策略、一致性和其他参数采用默认的 Azure Cosmos DB 设置。This mode assumes the default Azure Cosmos DB settings for indexing policy, consistency, and other parameters.

当评估要在 Azure Cosmos DB 上运行的潜在工作负荷时,可以使用基本模式进行快速、大概的估算。Use basic mode for a quick, high-level estimate when you are evaluating a potential workload to run on Azure Cosmos DB.
高级Advanced 提供更详细的 RU/秒估算,还可以调整其他设置 - 索引编制策略、一致性级别以及影响成本和吞吐量的其他参数。Provides a more detailed RU/s estimate, with the ability to tune additional settings — indexing policy, consistency level, and other parameters that affect the cost and throughput.

当为新项目估算 RU/秒或需要更详细的估算时,请使用高级模式。Use advanced mode when you are estimating RU/s for a new project or want a more detailed estimate.

使用基本模式估算预配吞吐量Estimate provisioned throughput using basic mode

若要使用基本模式针对你的工作负荷进行快速估算,请导航到 Capacity PlannerTo get a quick estimate for your workload using the basic mode, navigate to the capacity planner. 根据你的工作负荷输入以下参数:Enter in the following parameters based on your workload:

输入Input 说明Description
区域数量Number of regions Azure Cosmos DB 在所有 Azure 中国区域中提供。Azure Cosmos DB is available in all Azure China regions. 选择你的工作负荷所需的区域数目。Select the number of regions required for your workload. 你可以将任意数量的区域与你的 Cosmos 帐户相关联。You can associate any number of regions with your Cosmos account. 有关更多详细信息,请参阅 Azure Cosmos DB 中的多区域分布See multiple-region distribution in Azure Cosmos DB for more details.
多区域写入Multi-region writes 如果你启用多区域写入,则你的应用程序可以在任何 Azure 区域中进行读取和写入。If you enable multi-region writes, your application can read and write to any Azure region. 如果你禁用多区域写入,则你的应用程序可以将数据写入到单个区域。If you disable multi-region writes, your application can write data to a single region.

如果你预计在不同区域中会有需要低延迟写入的主动-主动工作负荷,请启用多区域写入。Enable multi-region writes if you expect to have an active-active workload that requires low latency writes in different regions. 例如,在不同区域中大量向数据库写入数据的 IOT 工作负荷。For example, an IOT workload that writes data to the database at high volumes in different regions.

多区域写入可保证 99.999% 的读取和写入可用性。Multi-region writes guarantees 99.999% read and write availability. 与单一写入区域相比,多区域写入需要更多的吞吐量。Multi-region writes require more throughput when compared to the single write regions. 若要了解详细信息,请参阅单一写入区域与多个写入区域的 RU 有何不同一文。To learn more, see how RUs are different for single and multiple-write regions article.
存储的总数据(每个区域)Total data stored (per region) 单个区域中存储的总估计数据 (GB)。Total estimated data stored in GB in a single region.
项大小Item size 数据项(例如文档)的估计大小,范围为 1 KB 到 2 MB。The estimated size of the data item (e.g. document), ranging from 1 KB to 2 MB.
每个区域的每秒读取数Reads/sec per region 预计的每秒读取次数。Number of reads expected per second.
每个区域的每秒写入数Writes/sec per region 预计的每秒写入次数。Number of writes expected per second.

填写所需的详细信息后,选择“计算”。After filling the required details, select Calculate. “成本预估”选项卡将显示存储和预配吞吐量的总成本。The Cost Estimate tab shows the total cost for storage and provisioned throughput. 可以在此选项卡中展开“显示详细信息”链接,以获取读取和写入请求所需的吞吐量的细目。You can expand the Show Details link in this tab to get the breakdown of the throughput required for read and write requests. 每次更改任何字段的值后,请选择“计算”来重新计算估计的成本。Each time you change the value of any field, select Calculate to re-calculate the estimated cost.

Capacity Planner 基本模式

使用高级模式估算预配吞吐量Estimate provisioned throughput using advanced mode

高级模式允许你提供会影响 RU/秒估计值的更多设置。Advanced mode allows you to provide more settings that impact the RU/s estimate. 若要使用此选项,请导航到 Capacity Planner 并使用你用于 Azure 的帐户登录到该工具。To use this option, navigate to the capacity planner and sign in to the tool with an account you use for Azure. 登录选项位于右侧边角。The sign-in option is available at the right-hand corner.

在登录后,与“基本”模式中的字段相比,你可以看到更多字段。After you sign in, you can see additional fields compared to the fields in basic mode. 根据你的工作负荷输入更多参数。Enter the additional parameters based on your workload.

输入Input 说明Description
APIAPI Azure Cosmos DB 是一项多模型和多 API 服务。Azure Cosmos DB is a multi-model and multi-API service. 对于新工作负荷,请选择“SQL (核心) API”。For new workloads, select SQL (Core) API.
区域数量Number of regions Azure Cosmos DB 在所有 Azure 中国区域中提供。Azure Cosmos DB is available in all Azure China regions. 选择你的工作负荷所需的区域数目。Select the number of regions required for your workload. 你可以将任意数量的区域与你的 Cosmos 帐户相关联。You can associate any number of regions with your Cosmos account. 有关更多详细信息,请参阅 Azure Cosmos DB 中的多区域分布See multiple-region distribution in Azure Cosmos DB for more details.
多区域写入Multi-region writes 如果你启用多区域写入,则你的应用程序可以在任何 Azure 区域中进行读取和写入。If you enable multi-region writes, your application can read and write to any Azure region. 如果你禁用多区域写入,则你的应用程序可以将数据写入到单个区域。If you disable multi-region writes, your application can write data to a single region.

如果你预计在不同区域中会有需要低延迟写入的主动-主动工作负荷,请启用多区域写入。Enable multi-region writes if you expect to have an active-active workload that requires low latency writes in different regions. 例如,在不同区域中大量向数据库写入数据的 IOT 工作负荷。For example, an IOT workload that writes data to the database at high volumes in different regions.

多区域写入可保证 99.999% 的读取和写入可用性。Multi-region writes guarantees 99.999% read and write availability. 与单一写入区域相比,多区域写入需要更多的吞吐量。Multi-region writes require more throughput when compared to the single write regions. 若要了解详细信息,请参阅单一写入区域与多个写入区域的 RU 有何不同一文。To learn more, see how RUs are different for single and multiple-write regions article.
默认一致性Default consistency Azure Cosmos DB 支持 5 种一致性级别,允许开发人员在一致性、可用性和延迟之间进行权衡。Azure Cosmos DB supports 5 consistency levels, to allow developers to balance the tradeoff between consistency, availability, and latency tradeoffs. 若要了解详细信息,请参阅一致性级别一文。To learn more, see the consistency levels article.

默认情况下,Azure Cosmos DB 使用会话一致性,这可以保证能够在会话中读取你自己的写入。By default, Azure Cosmos DB uses session consistency, which guarantees the ability to read your own writes in a session.

与会话一致性、一致前缀一致性和最终一致性相比,选择强一致性或有限过期一致性将会使读取所需的 RU/秒翻倍。Choosing strong or bounded staleness will require double the required RU/s for reads, when compared to session, consistent prefix, and eventual consistency. 多区域写入强一致性不受支持,系统将自动默认选择单区域写入强一致性。Strong consistency with multi-region writes is not supported and will automatically default to single-region writes with strong consistency.
索引策略Indexing policy 默认情况下,Azure Cosmos DB 会为所有项中的所有属性编制索引,以便进行灵活且高效的查询(映射到自动索引编制策略)。By default, Azure Cosmos DB indexes all properties in all items for flexible and efficient queries (maps to the Automatic indexing policy).

如果选择“关”,则不会为任何属性编制索引。If you choose off, none of the properties are indexed. 这将导致最低的写入 RU 开销。This results in the lowest RU charge for writes. 如果你预计仅执行点读取(键值查找)和/或写入而不执行查询,请选择“关”策略。Select off policy if you expect to only do point reads (key value lookups) and/or writes, and no queries.

自定义索引编制策略允许你在索引中包含或排除特定属性,以降低写入吞吐量和存储。Custom indexing policy allows you to include or exclude specific properties from the index for lower write throughput and storage. 若要了解详细信息,请参阅索引编制策略示例索引编制策略这两篇文章。To learn more, see indexing policy and sample indexing policies articles.
存储的总数据(每个区域)Total data stored (per region) 单个区域中存储的总估计数据 (GB)。Total estimated data stored in GB in a single region.
工作负荷模式Workload mode 如果工作负荷量固定,请选择“稳定”。Select Steady if your workload volume is constant.

如果工作负荷量随时间推移而变化,请选择“可变”。Select Variable if your workload volume changes over time. 例如,在特定的一天或一个月内变化。For example, during a specific day or a month.

如果选择了可变工作负荷选项,则下列设置可用:The following settings are available if you choose the variable workload option:
  • 高峰时间百分比:一个月内工作负荷需要峰值(最高)吞吐量的时间百分比。Percentage of time at peak: Percentage of time in a month where your workload requires peak (highest) throughput.

    例如,如果你的工作负荷在工作日的上午 9 点到下午 6 点的工作时间内有大量活动,则高峰时间的百分比为:45 个高峰小时 / 730 小时 / 月 = ~6%。For example, if you have a workload that has high activity during 9am - 6pm weekday business hours, then the percentage of time at peak is: 45 hours at peak / 730 hours / month = ~6%.

  • 高峰时每个区域的每秒读取次数 - 预计的高峰时每秒读取次数。Reads/sec per region at peak - Number of reads expected per second at peak.
  • 高峰时每个区域的每秒写入次数 - 预计的高峰时每秒写入次数。Writes/sec per region at peak - Number of writes expected per second at peak.
  • 非高峰时每个区域的每秒读取次数 - 预计的非高峰时每秒读取次数。Reads/sec per region off peak - Number of reads expected per second during off peak.
  • 非高峰时每个区域的每秒写入次数 - 预计的非高峰时每秒写入次数。Writes/sec per region off peak - Number of writes expected per second during off peak.
使用高峰和非高峰时间间隔,你能够相应地以编程方式缩放预配吞吐量,从而优化成本。With peak and off-peak intervals, you can optimize your cost by programmatically scaling your provisioned throughput up and down accordingly.
项大小Item size 数据项(例如文档)的大小,范围为 1 KB 到 2 MB。The size of the data item (e.g. document), ranging from 1 KB to 2 MB.

你还可以上传示例 (JSON) 文档以获得更准确的估计。You can also Upload sample (JSON) document for a more accurate estimate.

如果你的工作负荷在同一容器中有多个类型的项(包含不同的 JSON 内容),则可以上传多个 JSON 文档并获得估计值。If your workload has multiple types of items (with different JSON content) in the same container, you can upload multiple JSON documents and get the estimate. 可以使用“添加新项”按钮添加多个示例 JSON 文档。Use the Add new item button to add multiple sample JSON documents.

还可以使用“保存估计值”按钮下载包含当前估计值的 CSV 文件。You can also use the Save Estimate button to download a CSV file containing the current estimate.

Capacity Planner 高级模式

若要按区域查看所有费率,请参阅 Azure Cosmos DB 定价页Refer to the Azure Cosmos DB pricing page to see all rates by region.

估计查询所需的吞吐量Estimating throughput for queries

Azure Cosmos 容量计算器对工作负荷采取点读取(按 ID 和分区键值读取单个项,例如文档)和点写入的方式。The Azure Cosmos capacity calculator assumes point reads (a read of a single item, e.g. document, by ID and partition key value) and writes for the workload. 若要估计查询所需的吞吐量,请对 Cosmos 容器中的代表性数据集运行查询并获取 RU 开销To estimate the throughput needed for queries, run your query on a representative data set in a Cosmos container and obtain the RU charge. 将 RU 开销乘以你预计每秒运行的查询数,以获得所需的 RU/秒总数。Multiply the RU charge by the number of queries that you anticipate to run per second to get the total RU/s required.

例如,如果你的工作负荷需要一个查询 (SELECT * FROM c WHERE c.id = 'Alice'),该查询每秒运行 100 次,该查询的 RU 开销为 10 RU,则你总共需要 1000 RU/秒(100 查询/秒 * 10 RU/查询)来为这些请求提供服务。For example, if your workload requires a query, SELECT * FROM c WHERE c.id = 'Alice' that is run 100 times per second, and the RU charge of the query is 10 RUs, you will need 100 query / sec * 10 RU / query = 1000 RU/s in total to serve these requests. 将这些 RU/秒与工作负荷中发生的任何读取或写入操作所需的 RU/秒相加。Add these RU/s to the RU/s required for any reads or writes happening in your workload.

后续步骤Next steps