The last step proved that ECS and Fargate are now serving your website and it is running as a container.
However, what happens during peak hours? Scaling up/down - would it be a great solution for your workload?
Auto Scaling is a solution to adjust capacity on the fly by adding and removing tasks based on your load.
It scales in and out, preventing you from paying unnecessary resources. In addition, it adjusts your tasks to absorb the current workload.
artillery is a powerful solution for load testing.
The steps below will use this tool to emulate 100 new users per second for 600 seconds.
Click here to learn more about Artillery.
Let’s flood our application with hundreds of calls.
Cloud9 Terminal, install the artillery tool.
npm install -g artillery
Ensure that your terminal is pointing to the right folder.
Paste the configuration below and substitute the
YOUR_ALB_URL with the address of your application.
config: target: 'http://YOUR_ALB_URL' phases: - duration: 600 arrivalRate: 100 http: pool: 10 scenarios: - flow: - get: url: "/"
Save the file by pressing
1. CONTROL + X 2. Y 3. Enter
Run the command
artillery run ecs-load.yml
Warning: High CPU usage warning is an expected error.
The output from the command above should be similar to the lines below.
Started phase 0, duration: 300s @ 12:25:16(+0000) 2020-02-18 Report @ 12:25:26(+0000) 2020-02-18 Elapsed time: 10 seconds Scenarios launched: 4994 Scenarios completed: 2030 Requests completed: 2030 RPS sent: 502.31 Request latency: min: 4 max: 5854.9 median: 2483.9 p95: 5572 p99: 5844.4 Codes: 200: 2030
Leave the terminal running the
artillery and open the Amazon ECS console.
Cluster and then click on
Open the service
Metrics and open the Cloudwatch link for the metric
1 minute and setup the graph to display the last
As highlighted in yellow below, the CPU utilization of your single task is increasing significantly due to the heavy load.
Go back to your
Cloud9 Terminal and stop the artillery tool by pressing
CONTROL + C.
Open the cluster
awsbuilders-cluster and then click on your service.
Once again, click on
Configure Service Auto Scaling to adjust your service’s desired count and then insert the values below:
Create new role
The create new role may not be available if your account is new.
If that is your case, you don’t need to select the
Create new role.
The settings above configure auto scaling to keep at least two tasks running, with a maximum of 10 tasks running at the same time.
Click here to learn more about ECS and Auto Scaling.
Add scaling policy.
Target Tracking and insert the values below:
The auto scaling policy will keep your metric as close as possible to the target value of 5%. Also, it won’t scale in/out within 2 seconds from the last scaling activity.
Click here to learn more about Target Tracking Scaling Policies.
Click here to learn more about Step Scaling Policies
Update the service by click on
Wait for the changes to apply.
Your service is now provisioning the extra task as per the previous change.
Wait until the second task change the
Desired status to
Run the artillery command again.
artillery run ecs-load.yml
Watch the cloudwatch metric
CPUUtilization for 10 minutes and you should see a similar graph as per the below image.
Basically, auto scaling adds more tasks to reduce the cpu utilization as the workload increases. It also removes the unnecessary tasks once the load is reduced.
Check the running tasks in the
Tasks pane of your service.