根据请求计数使用云形成自动扩展
Posted
技术标签:
【中文标题】根据请求计数使用云形成自动扩展【英文标题】:Auto scaling using cloud formation according to Request count 【发布时间】:2012-04-21 14:26:24 【问题描述】:我们正在根据负载均衡器 RequestCount 指标使用云形成进行自动扩展。目前,如果请求增加到 1500 1 分钟,我们会扩展一个实例(每个实例每分钟可以处理 1500 个请求)。问题是,因为自动缩放组不断检查 RequestCount 并在请求计数大于 1500 1 分钟时添加一个新实例。但这不是必需的,因为我现在有 2 个可以处理 3000 个请求的实例。每分钟。是否有任何工具可以定制矩阵?即,如果添加新实例,则扩展策略将更改为 3000 req。
示例场景:
-
最初有1个ELB,1个tomcat实例附加到ELB(可以
处理 1500 个请求。每分钟)。
1 个云手表,如果需要,则具有扩大策略的作用。 ELB 的计数增加到 1500 分钟。
当前,ELB 上的请求负载为 1500,持续 1 分钟。现在要求。负载增加到 1700 分钟。所以它会附加一个新的tomcat
ELB 上的实例。所以我有 2 个实例可以处理 3000 个请求。为了
分钟。
但是现在云手表有什么问题仍然检查req。依靠 ELB,如果需要。最小负载为 1700。它将添加一个新的 tomcat
不需要的实例。
我该如何摆脱这个问题?
【问题讨论】:
【参考方案1】:我通过应用Scaling Policy 和触发策略评估的关联Cloudwatch alarms,使基于RequestCount
的扩展工作。下面是我在 ElasticBeanstalk 应用程序中使用的 cloudformation 模板:
RequestCountScalingAlarmLt2000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions:
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when Request Count < 2000"
AlarmName: "Fn::Join": ["-", ["Scale when Request Count < 2000", "Ref":"AWSEBEnvironmentName" ]]
ComparisonOperator: LessThanThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 2000
RequestCountScalingAlarmGt2000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions:
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when 2000 < Request Count < 20000"
AlarmName: "Scale when Request 2000 < Count < 20000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 2000
RequestCountScalingAlarmGt20000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions:
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when 20000 < Request Count < 30000"
AlarmName: "Scale when 20000 < Request Count < 30000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 20000
RequestCountScalingAlarmGt30000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions:
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when 30000 < Request Count < 40000"
AlarmName: "Scale when 30000 < Request Count < 40000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 30000
RequestCountScalingAlarmGt40000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions::
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when 40000 < Request Count < 50000"
AlarmName: "Scale when 40000 < Request Count < 50000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 40000
RequestCountScalingAlarmGt50000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions:
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when 50000 < Request Count < 60000"
AlarmName: "Scale when 50000 < Request Count < 60000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 50000
RequestCountScalingAlarmGt60000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions::
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when 60000 < Request Count < 70000"
AlarmName: "Scale when 60000 < Request Count < 70000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 60000
RequestCountScalingAlarmGt70000:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: true
AlarmActions:
- Ref: RequestCountScalingPolicy
OKActions:
- Ref: RequestCountScalingPolicy
AlarmDescription: "Scale when Request Count >= 70000"
AlarmName: "Scale when Request Count >= 70000"
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: LoadBalancerName
Value:
Ref: AWSEBLoadBalancer
EvaluationPeriods: "1"
MetricName: RequestCount
Namespace: AWS/ELB
Period: "300"
Statistic: Sum
Threshold: 70000
RequestCountScalingPolicy:
Type: "AWS::AutoScaling::ScalingPolicy"
Properties:
AutoScalingGroupName:
Ref: "AWSEBAutoScalingGroup"
AdjustmentType: "ExactCapacity"
PolicyType: "StepScaling"
EstimatedInstanceWarmup: 120
StepAdjustments:
-
MetricIntervalLowerBound: "0"
MetricIntervalUpperBound: "2000"
ScalingAdjustment: "1"
-
MetricIntervalLowerBound: "2000"
MetricIntervalUpperBound: "20000"
ScalingAdjustment: "2"
-
MetricIntervalLowerBound: "20000"
MetricIntervalUpperBound: "30000"
ScalingAdjustment: "3"
-
MetricIntervalLowerBound: "30000"
MetricIntervalUpperBound: "40000"
ScalingAdjustment: "4"
-
MetricIntervalLowerBound: "40000"
MetricIntervalUpperBound: "50000"
ScalingAdjustment: "5"
-
MetricIntervalLowerBound: "50000"
MetricIntervalUpperBound: "60000"
ScalingAdjustment: "6"
-
MetricIntervalLowerBound: "60000"
MetricIntervalUpperBound: "70000"
ScalingAdjustment: "7"
-
MetricIntervalLowerBound: "70000"
ScalingAdjustment: "8"
【讨论】:
【参考方案2】:正如 dsummersl 所说,RequestCount 不能直接用于平均指标。
我找到了几个解决方法here。基本上,它们会告诉您定义一个自定义 CloudWatch 指标,以便您可以检测您的实例以发出它们正在接收的请求数量。
为此,您需要收集来自每个实例的请求计数,并使用 put-metric-data 将其发送到 cloudwatch,或者创建一个 ebextension,以便 EBS 为您完成(我认为这是最简单的方法)。
然后您可以将 Auto Scaling 设置为根据该自定义指标向上/向下扩展。
希望对你有帮助。
【讨论】:
【参考方案3】:您想要做的是使用负载均衡器的平均值。您可以有不同类型的指标。总和、平均值、最小值、最大值和样本。如果您选择平均,它将为您提供负载均衡器下所有实例的平均值。因此,只有当您组中的所有服务器都达到每分钟 1500 个请求时,它才会触发新的实例启动。
类型的简要说明:
平均值 - 负载平衡器的平均值 Sum - 请求总数(例如:3000) 最大值 - 任何服务器的最大请求数(因为它可能不完全平衡) Minimum - 任何服务器的最小请求数(因为它可能不完全平衡) 示例 - 用于计算平均值的服务器数量(基本上是负载平衡器上的服务器数量)您也可以创建自己的自定义指标,但您需要创建一个应用程序来告诉亚马逊这些值是什么。使用 cloud watch api,您可以轻松创建自己的。看这里http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/Welcome.html?r=1540
【讨论】:
请注意,RequestCount 只能求和或采样,使用 RequestCount 时,最好的办法是缩放到“所需容量”而不是递增/递减(请参阅forums.aws.amazon.com/thread.jspa?threadID=86073 )。 好点,你必须这样做,因为 RequestCount 没有平均值。我忘记了,谢谢。 是的,在这种情况下这不是一个有效的答案。以上是关于根据请求计数使用云形成自动扩展的主要内容,如果未能解决你的问题,请参考以下文章
MIGS VPC 集成 E5000:无法使用两个商家的秘密之一根据商家的请求形成匹配的安全哈希