All Products
Search
Document Center

Auto Scaling:Create a custom target tracking scaling rule

Last Updated:Nov 19, 2024

You can create a custom target tracking scaling rule based on your business requirements. When creating a custom target tracking scaling rule, you can use a formula to combine multiple Hybrid Cloud Monitoring metrics into the rule.

Solution overview

Benefits

  • Support for formula operations. You can use formula operations to combine up to three metrics in a target tracking scaling rule, which allows you to manage scaling operations in a more flexible manner.

  • Support for more metrics. Compared with the built-in target tracking scaling rules, custom target tracking scaling rules are integrated with Hybrid Cloud Monitoring. This allows you to use additional metrics to perform scaling operations. For information about Hybrid Cloud Monitoring, see Overview.

Usage process

The solution described in this topic is developed based on the target tracking scaling rule feature of Auto Scaling and Hybrid Cloud Monitoring. You can refer to the following process to create a custom target tracking scaling rule:

  1. Design a target tracking scaling solution.

    Determine the Hybrid Cloud Monitoring metrics that meet your business requirements, and develop a target tracking scaling solution.

  2. Execute the target tracking scaling solution.

    Prepare the required Hybrid Cloud Monitoring metrics and create a target tracking scaling rule based on the metrics to execute the solution.

  3. Constantly monitor scaling events and adjust the solution based on the monitoring findings.

    Constantly monitor scaling events in your scaling group and track metric changes to improve the scaling solution.

1. Design a target tracking scaling solution

Determine the Hybrid Cloud Monitoring metrics that meet your business requirements, and develop a target tracking scaling solution. When you design your scaling solution, you can refer to the following example:

Appendix 1: Metrics describes all the supported Hybrid Cloud Monitoring metrics. To ensure the response speed of target tracking, we recommend that you select metrics with a minimum statistical period of 60 seconds.
To ensure smooth scaling operations, you must adjust the calculation for metric values based on the number of instances in the scaling group. A scale-out operation occurs when the actual metric values exceed the target metric values. A scale-in operation occurs when the actual metric values fall below the target metric values.

Sample solution

This topic provides a sample solution that is implemented based on the number of active messages in a Simple Message Queue (SMQ) queue, formerly MNS queue, to dynamically adjust the number of instances in a scaling group.

  • Desired effect

    Each instance in the scaling group queues three messages for processing. If the number of messages increases, a scale-out operation is initiated. If the number of messages decreases, a scale-in operation is initiated.

  • Implementation

    To achieve the desired effect, you must prepare the following metrics: ActiveMessages, which specifies the number of active messages in an SMQ queue, and RunningInstanceCount, which specifies the number of instances that are in the In Service state in the scaling group. Then, you can create a custom target tracking scaling rule based on the preceding metrics and set the target value to 3 (Auto Scaling maintains the metric values at 3). In this case, you can use the following formula:.

2. Execute the target tracking scaling solution

2.1 Prepare the required Hybrid Cloud Monitoring metrics

If you already prepared the required Hybrid Cloud Monitoring metrics, you can skip this step.
Before you perform the subsequent operations, make sure that Hybrid Cloud Monitoring is activated. For more information, see Activate Hybrid Cloud Monitoring.

Before you create a target tracking scaling rule, you must create metrics that you want to associate with the rule in the Hybrid Cloud Monitoring console for subsequent use. To create metrics, perform the following steps:

  1. Create a namespace.

    For more information, see Create a namespace.

  2. Add metrics to the namespace.

    You can add metrics to the namespace created in Step 1. For information about how to add metrics to a namespace, see Manage metric import tasks.

    Note

    To ensure the response speed of target tracking, we recommend that you select metrics with a minimum statistical period of 60 seconds.

Sample metrics

Create a namespace named ess-metrics-repo-test and add the following metrics to the namespace:

  • ActiveMessages provided by SMQ (formerly MNS): specifies the number of active messages

    image

  • RunningInstanceCount provided by Auto Scaling: specifies the number of running instances

    image

2.2 Create a target tracking scaling rule

To create a custom target tracking scaling rule in the Auto Scaling console, perform the following steps:

Before you proceed, make sure that a scaling group is created. For information about how to create a scaling group, see Create a scaling group of the ECS type or Create a scaling group of the Elastic Container Instance type.
Important

You can execute a target tracking scaling rule to decrease the number of instances in a scaling group to 0. Before you create a target tracking scaling rule, configure the Minimum Number of Instances and Maximum Number of Instances parameters based on your business requirements. To prevent service downtime or excessive spending caused by the solution, carefully control the scaling boundaries.

  1. Go to the Create Scaling Rule dialog box.

    image

    Specific steps

    1. Log on to the Auto Scaling console.

    2. In the left-side navigation pane, click Scaling Groups.

    3. In the top navigation bar, select a region.

    4. Find the scaling group in which you want to create a custom target tracking scaling rule and click Details in the Actions column.

    5. In the upper part of the page that appears, click the Scaling Rules and Event-triggered Tasks tab.

    6. On the Scaling Rules tab, click Create Scaling Rule. Then, the Create Scaling Rule dialog box appears.

  2. Configure the parameters displayed in the Create Scaling Rule dialog box based on your business requirements.

    Parameter

    Description

    Rule Type

    The type of the scaling rule that you want to create. In this example, Target Tracking Scaling Rule is selected.

    Metric Type

    Hybrid Cloud Monitoring

    Monitor Namespace

    The namespace of the metrics that you want to specify in the scaling rule. In this example, the namespace created in Step 2.1 is selected.

    Metric Description

    The metrics that you want to specify in the scaling rule and the monitored resources. In this example, the metrics prepared in Step 2.1 are selected.

    Metric Calculation Expression

    The formula based on which the metric values are calculated. You can specify + - * / and () in each formula.

    Important
    • You can specify up to three metrics in each formula.

    • To ensure smooth scaling operations, you must adjust the calculation for metric values based on the number of instances in the scaling group. A scale-out operation occurs when the actual metric values exceed the target metric values. A scale-in operation occurs when the actual metric values fall below the target metric values.

    Target Value

    The target value of the metrics. Auto Scaling ensures that the values of the specified metrics remain close to the target value.

    Instance Warmup Time

    The period of time during which instances are in the Warmup state. Unit: seconds. Auto Scaling adds instances in the Warmup state to a scaling group, but does not report the monitoring data of the instances to Hybrid Cloud Monitoring. When Auto Scaling calculates the number of instances to scale based on the monitoring findings, Auto Scaling does not include instances in the Warmup state in the count of existing instances in the scaling group. This helps prevent metric values from fluctuating until the warmup period ends.

    Threshold for Scale-out Alerts

    After a target tracking scaling rule is created, an event-triggered task is automatically created. This parameter specifies the number of consecutive times that the alert condition must be met before a scale-out operation is initiated by the event-triggered task.

    Threshold for Scale-in Alerts

    After a target tracking scaling rule is created, an event-triggered task is automatically created. This parameter specifies the number of consecutive times that the alert condition must be met before a scale-in operation is initiated by the event-triggered task.

    Disable Scale-in

    Specifies whether to disable scale-in operations. This feature affects the number of event-triggered tasks that are automatically created.

    • If you enable the Disable Scale-in feature, Auto Scaling creates only one event-triggered task for the scale-out operation. In this case, Auto Scaling does not remove instances from the scaling group.

    • If you disable the Disable Scale-in feature, Auto Scaling creates one event-triggered task for the scale-out and scale-in operations, respectively.

    Sample configurations

    Parameter

    Sample configuration

    Metric Type

    Hybrid Cloud Monitoring

    Monitor Namespace

    ess-metrics-repo-test

    Metric Description

    For Metric a:

    • Metric name: AliyunEss_RunningInstanceCount

    • Monitoring resource: current scaling group

    For Metric b:

    • Metric name: AliyunMnsnew_ActiveMessages

    • Monitoring resource: the SMQ queue that you want to monitor.

    Metric Calculation Expression

    b/a. The preceding formula specifies the average number of messages that must be processed on each instance.

    Target Value

    3. A value of 3 specifies that each instance has an average of three messages in queue.

  3. After you complete the configuration, click OK.

3. Constantly monitor scaling events and adjust the solution based on the monitoring findings

After you create the target tracking scaling rule, you must regularly monitor the scaling group to ensure the desired result is achieved. To assess the success of the scaling group, you can analyze metric calculations, scaling activities, and monitoring findings.

Related operations

  • View the target tracking scaling rule

    Choose Scaling Rules and Event-triggered Tasks > Scaling Rules. On the page that appears, find the target tracking scaling rule you want to view. Then, click the corresponding ID to go to the rule details page. You can also click the event-triggered task associated with the rule to view the monitoring information about the task.

    image

  • View metric calculations

    After you create a target tracking scaling rule, two event-triggered tasks are automatically created. Choose Scaling Rules and Event-triggered Tasks > Event-triggered Tasks > Event-triggered Task (Hybrid Cloud Monitoring). On the page that appears, find the desired event-triggered task and click the ID to go to the task details page. Then, view the metric calculations.

    image

    image

  • View scaling activities

    On the Scaling Activities tab of the scaling group details page, view the logs of scaling activities that occurred in the scaling group.

    image