您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

创建具有自动缩放吞吐量的 Azure Cosmos 容器和数据库Create Azure Cosmos containers and databases with autoscale throughput

适用于: SQL API Cassandra API Gremlin API 表 API Azure Cosmos DB API for MongoDB

在 Azure Cosmos DB 中,你可以为数据库和容器配置标准 (手动) 或自动缩放预配吞吐量。In Azure Cosmos DB, you can configure either standard (manual) or autoscale provisioned throughput on your databases and containers. Azure Cosmos DB 中的自动缩放预配吞吐量使你能够 自动、即时地自动扩展数据库或容器) (的吞吐量Autoscale provisioned throughput in Azure Cosmos DB allows you to scale the throughput (RU/s) of your database or container automatically and instantly. 吞吐量会根据使用情况进行缩放,而不会影响工作负荷的可用性、延迟、吞吐量或性能。The throughput is scaled based on the usage, without impacting the availability, latency, throughput, or performance of the workload.

自动缩放预配吞吐量非常适合于具有可变或不可预测流量模式,并且在高性能和规模方面需要 SLA 的任务关键型工作负载。Autoscale provisioned throughput is well suited for mission-critical workloads that have variable or unpredictable traffic patterns, and require SLAs on high performance and scale. 本文介绍自动缩放预配吞吐量的好处和用例。This article describes the benefits and use cases of autoscale provisioned throughput.

自动缩放的好处Benefits of autoscale

使用自动缩放预配吞吐量配置的 Azure Cosmos 数据库和容器具有以下好处:Azure Cosmos databases and containers that are configured with autoscale provisioned throughput have the following benefits:

  • Simple:自动缩放消除了通过自定义脚本或手动缩放容量管理 RU/s 的复杂性。Simple: Autoscale removes the complexity of managing RU/s with custom scripting or manually scaling capacity.

  • 可缩放:数据库和容器根据需要自动缩放预配吞吐量。Scalable: Databases and containers automatically scale the provisioned throughput as needed. 客户端连接、应用程序不会中断,对 Azure Cosmos DB SLA 没有影响。There is no disruption to client connections, applications, or impact to Azure Cosmos DB SLAs.

  • 经济高效:自动缩放可通过在不使用时进行缩减来优化 RU/s 使用和成本使用。Cost-effective: Autoscale helps optimize your RU/s usage and cost usage by scaling down when not in use. 你只需按小时为工作负载需要的资源付费。You only pay for the resources that your workloads need on a per-hour basis. 在一个月的所有小时中,如果设置自动缩放最大 RU/s(Tmax),并使用 66% 或更少小时的全额 Tmax,则将通过自动缩放节省开支。Of all hours in a month, if you set autoscale max RU/s(Tmax) and use the full amount Tmax for 66% of the hours or less, you'll save with autoscale. 若要了解详细信息,请参阅如何在标准(手动)和自动缩放预配吞吐量之间进行选择一文。To learn more, see the how to choose between standard (manual) and autoscale provisioned throughput article.

  • 高可用性:使用自动缩放的数据库和容器使用相同的全球分布式、容错、高可用 Azure Cosmos DB 后端,以确保数据持续性和高可用性。Highly available: Databases and containers using autoscale use the same globally distributed, fault-tolerant, highly available Azure Cosmos DB backend to ensure data durability and high availability.

自动缩放的用例Use cases of autoscale

自动缩放的用例包括:The use cases of autoscale include:

  • 可变或不可预测的工作负载:当工作负载的使用具有可变或不可预测的峰值时,自动缩放会基于使用情况自动增加和缩减。Variable or unpredictable workloads: When your workloads have variable or unpredictable spikes in usage, autoscale helps by automatically scaling up and down based on usage. 示例包括根据季节性具有不同流量模式的零售网站;在一天中的不同时间出现峰值的 IOT 工作负载;每月或每年几次出现峰值使用量的业务线应用程序,等等。Examples include retail websites that have different traffic patterns depending on seasonality; IOT workloads that have spikes at various times during the day; line of business applications that see peak usage a few times a month or year, and more. 利用自动缩放,不再需要为峰值或平均容量进行手动预配。With autoscale, you no longer need to manually provision for peak or average capacity.

  • 新应用程序:如果开发新应用程序,但不确定所需的吞吐量 (RU/s),则可以通过自动缩放轻松地开始进行。New applications: If you're developing a new application and not sure about the throughput (RU/s) you need, autoscale makes it easy to get started. 可以从 400 - 4000 RU/s 的自动缩放入口点开始,监视使用情况,并随时间推移确定正确的 RU/s。You can start with the autoscale entry point of 400 - 4000 RU/s, monitor your usage, and determine the right RU/s over time.

  • 不常使用的应用程序:如果你的应用程序每天、每周或每个月仅使用几个小时(例如低容量应用程序/网站/博客站点),则自动缩放可调整容量以处理峰值使用量,并在结束时进行缩减。Infrequently used applications: If you have an application that's only used for a few hours several times a day, week, or month — such as a low-volume application/web/blog site — autoscale adjusts the capacity to handle peak usage and scales down when it's over.

  • 开发和测试工作负载:如果你或你的团队在工作时间内使用 Azure Cosmos 数据库和容器,但在夜间或周末不需要它们,则自动缩放可通过在不使用时缩减到最小值来节省成本。Development and test workloads: If you or your team use Azure Cosmos databases and containers during work hours, but don't need them on nights or weekends, autoscale helps save cost by scaling down to a minimum when not in use.

  • 计划生产工作负载/查询:如果你有一系列要在空闲时间段运行的计划请求、操作或查询,则可以使用自动缩放轻松完成该操作。Scheduled production workloads/queries: If you have a series of scheduled requests, operations, or queries that you want to run during idle periods, you can do that easily with autoscale. 需要运行工作负载时,吞吐量将自动扩展到所需吞吐量,并在以后缩减。When you need to run the workload, the throughput will automatically scale to what's needed and scale down afterward.

构建这些问题的自定义解决方案不仅需要大量时间,还会在应用程序的配置或代码中引入复杂性。Building a custom solution to these problems not only requires an enormous amount of time, but also introduces complexity in your application's configuration or code. 自动缩放可立即实现以上方案,无需进行自定义或手动容量缩放。Autoscale enables the above scenarios out of the box and removes the need for custom or manual scaling of capacity.

自动缩放预配吞吐量的工作方式How autoscale provisioned throughput works

通过自动缩放配置容器和数据库时,需要指定所需的最大吞吐量 TmaxWhen configuring containers and databases with autoscale, you specify the maximum throughput Tmax required. Azure Cosmos DB 会缩放吞吐量 T,如 0.1*Tmax <= T <= TmaxAzure Cosmos DB scales the throughput T such 0.1*Tmax <= T <= Tmax. 例如,如果将最大吞吐量设置为 20,000 RU/s,,则吞吐量将在 2000 到 20,000 RU/s 之间进行缩放。For example, if you set the maximum throughput to 20,000 RU/s, the throughput will scale between 2000 to 20,000 RU/s. 由于缩放是自动且即时的,因此在任何时间点,都可以无延迟地消耗预配 TmaxBecause scaling is automatic and instantaneous, at any point in time, you can consume up to the provisioned Tmax with no delay.

每小时将向你收取系统在该小时内扩展到的最高吞吐量 T 的费用。Each hour, you will be billed for the highest throughput T the system scaled to within the hour.

自动缩放最大吞吐量 Tmax 的入口点从 4000 RU/s 开始,这表示可在 400 - 4000 RU/s 之间进行缩放。The entry point for autoscale maximum throughput Tmax starts at 4000 RU/s, which scales between 400 - 4000 RU/s. 可以按增量 1000 RU/s 设置 Tmax,并随时更改值。You can set Tmax in increments of 1000 RU/s and change the value at any time.

对现有资源启用自动缩放Enable autoscale on existing resources

使用 Azure 门户Azure 资源管理器模板CLIPowerShell 在现有数据库或容器上启用自动缩放。Use the Azure portal, Azure Resource Manager template, CLI or PowerShell to enable autoscale on an existing database or container. 随时可以在自动缩放与标准(手动)预配吞吐量之间切换。You can switch between autoscale and standard (manual) provisioned throughput at any time. 有关详细信息,请参阅此文档See this documentation for more information.

自动缩放的吞吐量和存储限制Throughput and storage limits for autoscale

对于 Tmax 的任何值,数据库或容器均可以存储总计 0.01 * Tmax GBFor any value of Tmax, the database or container can store a total of 0.01 * Tmax GB. 达到此存储量之后,将基于新的存储值自动增加最大 RU/s,而不会影响应用程序。After this amount of storage is reached, the maximum RU/s will be automatically increased based on the new storage value, with no impact to your application.

例如,如果从 50,000 RU/s 的最大 RU/s(在 5000 - 50,000 RU/s 之间缩放)开始,则最多可存储 500 GB 数据。For example, if you start with a maximum RU/s of 50,000 RU/s (scales between 5000 - 50,000 RU/s), you can store up to 500 GB of data. 如果超过 500 GB(例如,存储现在为 600 GB),则新的最大 RU/s 将是 60,000 RU/s(在 6000 - 60,000 RU/s 之间缩放)。If you exceed 500 GB - e.g. storage is now 600 GB, the new maximum RU/s will be 60,000 RU/s (scales between 6000 - 60,000 RU/s).

将数据库级别吞吐量与自动缩放结合使用时,可以让前 25 个容器共享 4000 的自动缩放最大 RU/s(在 400 - 4000 RU/s 之间缩放),只要未超过 40 GB 存储即可。When you use database level throughput with autoscale, you can have the first 25 containers share an autoscale maximum RU/s of 4000 (scales between 400 - 4000 RU/s), as long as you don't exceed 40 GB of storage. 有关详细信息,请参阅此文档See this documentation for more information.

比较 – 使用手动与自动缩放吞吐量配置的容器Comparison – containers configured with manual vs autoscale throughput

有关更多详细信息,请参阅有关如何在标准(手动)与自动缩放吞吐量之间进行选择的此文档For more detail, see this documentation on how to choose between standard (manual) and autoscale throughput.

具有标准(手动)吞吐量的容器Containers with standard (manual) throughput 具有自动缩放吞吐量的容器Containers with autoscale throughput
预配吞吐量 (RU/s)Provisioned throughput (RU/s) 手动预配。Manually provisioned. 基于工作负载使用模式自动并即时缩放。Automatically and instantaneously scaled based on the workload usage patterns.
请求/操作的速率限制 (429)Rate-limiting of requests/operations (429) 如果消耗超出预配容量,则可能会发生。May happen, if consumption exceeds provisioned capacity. 如果在设置的自动缩放吞吐量范围内消耗 RU/s,则不会发生。Will not happen if you consume RU/s within the autoscale throughput range that you've set.
容量规划Capacity planning 必须执行容量规划,并设置所需的确切吞吐量。You have to do capacity planning and provision the exact throughput you need. 系统会自动处理容量规划和容量管理。The system automatically takes care of capacity planning and capacity management.
定价Pricing 使用按小时费率的标准(手动)RU/s,按小时为手动预配 RU/s 付费。You pay for the manually provisioned RU/s per hour, using the standard (manual) RU/s per hour rate. 按小时为系统在该小时内扩展到的最高 RU/s 付费。You pay per hour for the highest RU/s the system scaled up to within the hour.

对于单写入区域帐户,使用按小时费率的自动缩放 RU/s,为每小时使用的 RU/s 付费。For single write region accounts, you pay for the RU/s used on an hourly basis, using the autoscale RU/s per hour rate.

对于具有多个写入区域的帐户,自动缩放不收取额外费用。For accounts with multiple write regions, there is no extra charge for autoscale. 需使用相同的多区域写入 RU/秒小时费率,为每小时使用的吞吐量付费。You pay for the throughput used on hourly basis using the same multi-region write RU/s per hour rate.
最适合工作负载类型Best suited for workload types 可预测和稳定的工作负载Predictable and stable workloads 不可预测和可变的工作负载Unpredictable and variable workloads

后续步骤Next steps