Automatically scale using cloud formation according to the number of queries

We use cloud formation to automatically scale in accordance with the RequestCount metric of load balancing. We are currently increasing the instance if the request grows to 1,500 in 1 minute (each instance can process 1,500 requests per minute). The problem is that the auto-scaling group constantly checks the RequestCount and adds a new instance if the number of requests exceeds 1500 in 1 minute. But this is not required, as I now have 2 instances that can handle 3000 requests. per minute. Are there any tools for creating matrices? that is, if a new instance is added, then the scaling policy will change to 3000 req.

Example script:

  • Initially, there is 1 ELB, 1 tomcat instance attached to the ELB (can process 1,500 req. Per minute).
  • 1 cloud chat with zoom action ploicy if req. ELB account is increased to 1500 for a minimum period.
  • Currently, the load on the ELB is 1500 for 1 min. now req. load increases to 1700 min. so he will attach a new cat instance on the ELB. So I have 2 instances that can handle 3000 req. for min
  • But now the cloud issue is still checking req. count on ELB, and if req. load is 1700 min. he will add another new cat which is not required.

How can I proceed from this problem?

+6
source share
3 answers

What you want to do is use the average to balance the load. You may have different types of metrics. Amount, Average, Minimum, Maximum and Sample. If you select Average, this will give you the average for all instances under the bootloader. Thus, it starts the launch of a new instance only when all the servers in your group are 1500 requests per minute.

Type brief description:

  • Medium - Medium for load balancing
  • Amount - total number of requests (example: 3000)
  • Maximum - the maximum number of requests on any server (because it may not be balanced)
  • Minimum - the minimum number of requests to any server (because it may not be balanced)
  • Example. The number of servers used to calculate the average (mainly the number of servers on load balancing).

You can create your own custom metrics, but you need to create an application that tells amazon what values. Using the api cloud clock, you can easily create your own. Take a look here http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/Welcome.html?r=1540

+4
source

As dsummersl said, RequestCount cannot be used right away with averages.

I found a couple of workarounds here . Basically, they tell you to define a custom CloudWatch metric so that you can get your instances to emit the number of requests they receive.

To do this, you will need to collect the number of requests from each instance and send it to cloudwatch using put-metric-data or create an ebextension so that EBS does it for you (I think this is the easiest way).

You can then set auto scaling to scale up / down based on this custom metric.

Hope this helps.

+1
source

I did a scaling based on the operation of RequestCount , applying the Scaling Policy using Cloudwatch Alarms , which cause the evacuation of the policy. Below you will find the cloudformation template that I used in the ElasticBeanstalk application:

  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" 
+1
source

Source: https://habr.com/ru/post/912729/


All Articles