Dynamic scaling is based on the metrics provided by CloudWatch. Depending on how we configure it, ASG will either launch or terminate instances. We can configure ASG to launch a new instance when the CPU resources of an instance or instances exceed 90%, or if the network traffic is high, or if the number of packets sent to each instance is large.
Depending on the system and requirements, we will configure it differently. In this example, we will configure it based on the “number of packets sent to each instance.”
Before testing, we will manually scale in by terminating one instance. Then, go to the Activity tab and check again.
After deleting, we will now configure dynamic scaling. Go to the Automatic scaling tab.
In this form, fill in the following details:
Request Over 500 per target
.The Instance warmup parameter affects the time an instance starts receiving external traffic. Specifically, when an instance is created and in the InService state (ready to operate), you can adjust the time it takes for an instance to begin receiving and processing requests. This time is called instance warmup. Adjusting this parameter allows more time for the instance to become fully stable, as the application may need to update and install dependencies or connect to other services to function properly.
Result:
Start the test program.
Go to the EC2 Console to see how many requests are being sent to EC2.
Wait a moment for the metrics to update. You’ll notice that the graphs are trending upwards or stabilizing.
Return to the Activity tab of ASG. You will see 3 instances have been launched. Since the request volume is high, ASG calculates that it needs to create the maximum desired number of instances.
Go back to the EC2 Console, select all the newly created instances, and observe the charts.
You will notice that the green line is gradually going down, and other lines are starting to appear.
As mentioned before, metrics update every 15 minutes, so you will need to wait a bit to see the results.
Now, we will stop the test program.
Go to the ASG Activity tab and wait for ASG to terminate the unnecessary instances. This process may take a while.
When ASG detects that the system is becoming overloaded based on certain metrics, it will launch additional instances to bring the system back to a stable state. However, dynamic scaling is not very fast, as mentioned earlier. When scaling policies are created, they impact the core metrics, and ASG will “look” at them to decide whether to scale up or down.
As a result, the number of instances is calculated and updated at a slower pace. To address this, we can use Predictive Scaling, which allows ASG to react more quickly.