在 Microsoft Fabric 中 Cosmos DB 的自动缩放吞吐量

Microsoft Fabric 中的 Cosmos DB 支持自动缩放预配吞吐量。 自动扩展预配的吞吐量非常适合具有可变或不可预知流量模式的关键任务工作负载。 Microsoft Fabric 中的 Cosmos DB 中的自动缩放会根据最活跃的分区缩放工作负荷。 对于具有不同工作负荷模式的非一致性工作负荷,这种缩放可能会导致不必要的纵向扩展。 动态自动缩放是对在整个过程中预配的自动缩放的增强功能,有助于根据每个分区级别的使用情况独立缩放此类非格式工作负荷。 动态缩放可以帮助您在经常遇到热分区时节省成本。

优点

在 Microsoft Fabric 中,配置了自动缩放预配吞吐量的 Cosmos DB 容器具有以下优势:

  • 简单: 自动缩放消除了管理吞吐量或手动缩放容量的复杂性。

  • 可 伸缩: 容器会根据需要自动缩放预配的吞吐量。 客户端应用程序不会中断。

  • 瞬时: 如果需要,容器 会立即 纵向扩展。 突然增加需要额外的吞吐量时,没有预热期。

  • 经济高效:自动缩放可通过在不使用时进行纵向缩减来帮助优化 RU/s 和成本的使用。 你只需按小时为工作负载需要的资源付费。

  • 高可用性: 使用自动缩放的容器使用相同的容错、高度可用的 Azure Cosmos DB 后端来确保数据持久性和高可用性。

用例

Cosmos DB 中的自动扩缩可以在各种工作负荷中发挥巨大作用,尤其是对于可变或不可预测的工作负荷。 当工作负荷的使用量有可变或不可预知的峰值时,自动缩放有助于根据使用情况自动纵向扩展和缩减。 示例包括:

  • 由具有不可预测使用模式的用户使用的 Power BI 报表或笔记本。
  • 开发和测试工作负荷主要在工作时间使用。
  • 计划执行的 Spark 作业,以及要在空闲期间运行的操作或查询。
  • 每月或一年出现几次高峰使用量的业务线应用程序,等等。

构建这些问题的自定义解决方案不仅需要大量时间,还会在应用程序的配置或代码中引入复杂性。 自动缩放可立即实现以上方案,无需进行自定义或手动容量缩放。

在 Microsoft Fabric 的 Cosmos DB 中配置自动缩放吞吐量

在 Fabric 门户中创建时,Cosmos DB 中在 Fabric 里创建的容器将自动预配 5000 RU/秒的自动扩展吞吐量。 可以使用 Cosmos DB SDK 读取和更新自动缩放吞吐量。 最小自动缩放吞吐量可以设置为 1000 RU/秒,最大为 50000 RU/秒。 可以通过提交支持请求来增加此最大值。

使用 Azure SDK 配置自动缩放

使用 Cosmos DB SDK 在 Microsoft Fabric 中的 Cosmos DB 容器上设置读取和更新自动缩放吞吐量。

有关在 Fabric 笔记本中设置 Cosmos DB 吞吐量的完整示例,请参阅 Fabric 中的 Cosmos DB 管理操作

database = client.get_database_client("<database-name>")
container = database.get_container_client("<container-name>")

# Get the current throughput on the container and increase it by 1000 RU/s
throughput_properties = await container.get_throughput()
autoscale_throughput = throughput_properties.auto_scale_max_throughput

print(print(f"Autoscale throughput: {autoscale_throughput}"))

new_throughput = autoscale_throughput + 1000

await container.replace_throughput(ThroughputProperties(auto_scale_max_throughput=new_throughput))

# Verify the updated throughput
updated_throughput_properties = await container.get_throughput()
print(f"Verified updated autoscale throughput: {updated_throughput_properties.auto_scale_max_throughput}")
const database = client.database('<database-name>');
const container = database.container('<container-name>');

// Get the current throughput on the container and increase it by 1000 RU/s
const { resource: throughputProperties } = await container.offer.read();
const autoscaleThroughput = throughputProperties?.autoscaleSettings?.maxThroughput;

console.log(`Autoscale throughput: ${autoscaleThroughput}`);

const newThroughput = autoscaleThroughput + 1000;

await container.offer.replace({
    offerThroughput: undefined,
    autoscaleSettings: {
        maxThroughput: newThroughput
    }
});

// Verify the updated throughput
const { resource: updatedThroughputProperties } = await container.offer.read();
console.log(`Verified updated autoscale throughput: ${updatedThroughputProperties?.autoscaleSettings?.maxThroughput}`);
Container container = client
    .GetDatabase("<database-name>")
    .GetContainer("<container-name>");

// Get the current throughput on the container and increase it by 1000 RU/s
ThroughputResponse throughputResponse = await container.ReadThroughputAsync();
int? autoscaleThroughput = throughputResponse.Resource.AutoscaleMaxThroughput;

Console.WriteLine($"Autoscale throughput: {autoscaleThroughput}");

int newThroughput = autoscaleThroughput.Value + 1000;

await container.ReplaceThroughputAsync(ThroughputProperties.CreateAutoscaleThroughput(newThroughput));

// Verify the updated throughput
ThroughputResponse updatedThroughputResponse = await container.ReadThroughputAsync();
Console.WriteLine($"Verified updated autoscale throughput: {updatedThroughputResponse.Resource.AutoscaleMaxThroughput}");