From the traffic and workloads that the system receives and sends each day, ASG can “predict” the future traffic and workloads for the upcoming days. This helps ASG respond better by launching or terminating instances accordingly. Typically, Predictive Scaling is used in combination with other types of scaling.
As in the previous section, I will manually scale in with ASG and wait for ASG to terminate all the instances created by this service.
Next, delete the automatic scaling policy to avoid affecting this test.
Then, go to the Activity tab, scroll down to Predictive scaling policies, and click Create predictive policy to create a new one.
In this form, we will configure as follows:
PredictCPUUtilizationAt15Percent
(you can choose any name)Next, in the Metric and target utilization section:
You will add custom metric JSON as follows:
{
"CustomizedLoadMetricSpecification": {
"MetricDataQueries": [
{
"Label": "Total CPU Utilization in ASG",
"Id": "cpu_sum",
"MetricStat": {
"Metric": {
"MetricName": "WSCustomCPUUTILIZATION",
"Namespace": "FCJ Management Custom Metrics",
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": "FCJ-Management-ASG"
}
]
},
"Stat": "Sum"
},
"ReturnData": true
}
]
}
}
{
"CustomizedScalingMetricSpecification": {
"MetricDataQueries": [
{
"Label": "Average CPU Utilization in ASG",
"Id": "cpu_avg",
"MetricStat": {
"Metric": {
"MetricName": "WSCustomCPUUTILIZATION",
"Namespace": "FCJ Management Custom Metrics",
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": "FCJ-Management-ASG"
}
]
},
"Stat": "Average"
},
"ReturnData": true
}
]
}
}
Next, check Add custom capacity metric.
Similarly to the previous two steps, I will add custom metric JSON for Capacity metric.
{
"CustomizedCapacityMetricSpecification": {
"MetricDataQueries": [
{
"Label": "Number of instances in ASG",
"Id": "capacity_avg",
"MetricStat": {
"Metric": {
"MetricName": "WSCustomGroupInstances",
"Namespace": "FCJ Management Custom Metrics",
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": "FCJ-Management-ASG"
}
]
},
"Stat": "Average"
},
"ReturnData": true
}
]
}
}
If you configured 2.6 - Prepare metrics for predictive scaling earlier, after completing the setup, you will see two charts displayed.
In the Pre-launch instances section of Additional scaling settings - optional, set it to 1 minute. Click Create to create the policy.
Similar to Dynamic scaling, this Pre-launch instances setting will affect when the instances will be launched. For example, if ASG predicts a peak at 23:00, it will launch instances at 22:59, according to the configuration.
Check the results.
In that policy, you will see two charts: Load and Capacity. These charts provide data on previous traffic and the number of instances used in previous days, allowing predictions for the upcoming days, represented by the purple line.
The chart is in UTC+0, and we are in UTC+7, so you’ll need to add 7 hours when reading these charts.
First, focus on the chart on the left. At 15:00 UTC (which is 22:00 in Vietnam time), the total load was 164.546.
To understand what this number represents, look at the chart on the right.
We can see that at that time, 13 instances were predicted to be launched, and the load correlates with these instances.
You can check other times as well.
If you wait for the predicted time, go to the ASG’s Activity tab, and you’ll see that ASG launches a new instance at 21:59, one minute before 22:00, as predicted above.
We can combine Predictive Scaling with Dynamic Scaling or other scaling types to increase ASG’s flexibility and the system’s reliability. For systems with consistent load over time, using predictive scaling is also a reasonable approach.