6

根據負載均衡器RequestCount度量標準,我們使用雲形成進行自動縮放。目前,如果請求在1500分鐘內增加1分鐘(每個實例每分鐘可以處理1500個請求),我們會擴展一個實例。問題是,因爲自動調節組不斷檢查RequestCount並在請求數大於1500的情況下添加一個新的實例1分鐘。但它不是必需的,因爲我現在有2個可以處理3000個請求的實例。每分鐘。是否有任何設施可以製作矩陣定製?即如果添加了新實例,則放大策略將變爲3000請求。根據請求計數使用雲形成自動縮放

示例方案:

  1. 最初有1 ELB,附接到ELB 1個Tomcat實例(可 手柄1500 REQ每分鐘)。
  2. 1雲手表如果需要的話,可以擴展ploicy。 ELB計數增加到1500分鐘。
  3. 目前ELB上的請求負載爲1500分鐘。現在需要。最小負載增加到1700。所以它會在ELB上附加一個新的tomcat 實例。所以我有2個實例可以處理3000個請求。爲 分鐘。
  4. 但現在雲手表還在檢查req是什麼問題。依靠ELB,如果需要的話。最小負載爲1700。它會添加一個不需要的新的tomcat 實例。

我怎麼能從這個問題來?

回答

4

你想要做的是使用負載平衡器的平均值。您可以有不同類型的指標。總和,平均值,最小值,最大值和樣本。如果您選擇平均值,它將爲您提供負載均衡下的所有實例的平均值。因此,只有當組中的所有服務器的請求數爲每分鐘1500個請求時,纔會觸發新的實例啓動。

的類型的簡單描述:

  • 平均 - 平均爲負載平衡器
  • 薩姆 - 的請求的總數(例如:3000)
  • 最高 - 請求的任何服務器的最大數量有(因爲它可能不完全平衡)
  • 最小 - 任何服務器的最小請求數(因爲它可能不完全平衡)
  • 示例 - 用於計算的服務器數(實際上負載平衡器上有多少個服務器)

您也可以創建自己的自定義指標,但您需要創建一個應用程序,告訴亞馬什麼這些值。使用雲觀察API您可以輕鬆創建自己的。看看這裏http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/Welcome.html?r=1540

+2

只是注意的是,RequestCount只能求和或採樣,並使用RequestCount的時候,做的最好的事情是規模再上'期望容量'而不是增量/減量(見https://forums.aws.amazon.com/thread.jspa?threadID=86073)。 – dsummersl 2013-04-08 19:16:43

+0

好點,你必須這樣做,因爲RequestCount沒有平均值。我忘了那個謝謝。 – bwight 2013-04-10 16:15:49

+0

是的,在這種情況下這不是一個有效的答案。 – 2015-10-10 09:52:03

1

正如dsummersl說,RequestCount不能直接使用平均指標。

我發現了幾個解決方法here。基本上,他們告訴您定義一個自定義的CloudWatch指標,以便您可以測試您的實例以發出它們正在接收的請求的數量。

爲此,您需要從每個實例收集請求計數,並使用put-metric-data或將它發送到ebextension,以便EBS爲您完成(我認爲這是最簡單的方法)。

然後,您可以將Auto Scaling設置爲根據該自定義指標向上/向下縮放。

希望它有幫助。

0

我已經根據RequestCount工作,通過應用Scaling Policy和相關的Cloudwatch alarms來觸發政策規避。下面你會發現,我已經在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" 
相關問題