简体   繁体   English

如何根据自动调整的dynamodb表管理全局二级索引的写入容量?

[英]How can you manage write capacity for a global secondary index based on an autoscaled dynamodb table?

Global secondary indexes have capacity provisioned separately from the tables where they are applied. 全局二级索引的容量与应用它们的表分开配置。 If insufficient write capacity is allocated for the GSI, then writes to the table are throttled . 如果为GSI分配的写入容量不足, 则会限制对表的写入 Therefore, if autoscaling for writes to the table is triggered, then one should expect that the write capacity of the GSI would need to be managed in response. 因此,如果触发了对表的写入的自动调节,那么应该期望GSI的写入容量需要作为响应来管理。

Autoscaling for table reads/writes can be configured through the AWS Management Console, via the CLI or using CloudFormation. 可以通过AWS管理控制台,CLI或使用CloudFormation配置表读/写的自动调节。 The documentation posts sample JSON/YAML to accomplish this for table provisioning. 文档发布了JSON / YAML示例,以完成表配置。 However, when I attempt to create a new GSI on an autoscaled table, I see no options to mirror the table's settings. 但是,当我尝试在自动缩放的表上创建新的GSI时,我看不到镜像表设置的选项。 Nor can I find CLI or CloudFormation examples in the documentation on how to explicitly deal with indexes and auto-scaling. 我也无法在文档中找到有关如何显式处理索引和自动缩放的CLI或CloudFormation示例。

So how do you manage write capacity for a GSI? 那么如何管理GSI的写入容量? Is my understanding of how things should work correct? 我对事情如何运作的理解是正确的吗? Or does AWS "do the right thing" (in their opinion, anyway) and autoscale the GSI in parallel with the underlying table? 或者AWS“做正确的事”(在他们看来,无论如何)并且与基础表并行地自动调整GSI?

You can apply the same autoscaling settings for you global secondary indexes. 您可以为全局二级索引应用相同的自动缩放设置。 According to AWS docs : 根据AWS文档

If you enable DynamoDB auto scaling for a table that has one or more global secondary indexes, we highly recommend that you also apply auto scaling uniformly to those indexes. 如果为具有一个或多个全局二级索引的表启用DynamoDB自动缩放,我们强烈建议您还将自动缩放统一应用于这些索引。 You can do this by choosing Apply same settings to global secondary indexes in the AWS Management Console. 您可以通过在AWS管理控制台中选择“将相同设置应用于全局二级索引”来执行此操作。

It is now possible to define the secondary index as an autoscaling target. 现在可以将辅助索引定义为自动缩放目标。 It's nearly the same compared to the normal table. 与普通表相比,它几乎相同。 You just have to change the resourceId and ScalableDimension of the AWS::ApplicationAutoScaling::ScalableTarget . 你只需要改变resourceIdScalableDimension的的AWS::ApplicationAutoScaling::ScalableTarget

  SecIndexWriteCapacity:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MaxCapacity: 1000
      MinCapacity: 15
      ResourceId: !Sub "table/${MY_MAIN_TABLE}/index/${MY_SECONDARY_INDEX_NAME}"
      RoleARN: !GetAtt ScalingRole.Arn
      ScalableDimension: dynamodb:index:WriteCapacityUnits
      ServiceNamespace: dynamodb
  SecIndexReadCapacity:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MaxCapacity: 1000
      MinCapacity: 15
      ResourceId: !Sub "table/${MY_MAIN_TABLE}/index/MY_SECONDARY_INDEX_NAME"
      RoleARN: !GetAtt ScalingRole.Arn
      ScalableDimension: dynamodb:index:ReadCapacityUnits
      ServiceNamespace: dynamodb
  SecIndexWriteScalingPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: SecIndexWriteScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref SecIndexWriteCapacity
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 50.0
        ScaleInCooldown: 30
        ScaleOutCooldown: 1
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBWriteCapacityUtilization
  SecIndexReadScalingPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: SecIndexReadScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref SecIndexReadCapacity
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 50.0
        ScaleInCooldown: 30
        ScaleOutCooldown: 0
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBReadCapacityUtilization

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM