In this article, AWS Auto scaling is demonstrated with a web service implementation on Amazon ECS (Elastic Container Service) that uses NGinx web server. To accommodate large number to simultaneous requests, AWS Auto scaling is planned and implemented. Thereafter, load testing is carried out, which triggers an alarm in AWS and the ECS containers start to scale up to become 4 similar tasks running in parallel. When the load on web server is removed, the ECS containers gradually decrement back to the original state.
1. Containers Auto Scaling on AWS
Contents
Containers Auto Scaling on AWS .................................................................................................. 1
Introduction to Auto Scaling....................................................................................................... 1
Distributed Load Testing Using AWS Fargate........................................................................... 1
Installation and Configuration .................................................................................................... 2
Run the Load testing using Docker container............................................................................. 2
Taurus uses JMeter in the background........................................................................................ 3
Load Testing with ApacheBench.............................................................................................. 10
Summary................................................................................................................................... 11
References................................................................................................................................. 11
Introduction to Auto Scaling
AWS Auto Scaling monitors your applications and automatically adjusts capacity to maintain
steady, predictable performance at the lowest possible cost. Auto Scaling is a broad topic and a
lot of documentation is available on Amazon. This article covers the essential concepts, different
types and methods of applying Auto Scaling on Amazon Web Services, and most of all
implementing containers Auto Scaling on AWS.
AWS Auto Scaling has been a historical feature of Amazon Web Services. Following two types
of Auto Scaling have been most common as of now.
EC2 - Amazon EC2 Auto Scaling
ECS - Service Auto Scaling
There are also broader types of Auto Scaling in AWS, like Amazon ECS cluster auto scaling
where a larger scope of a project’s infrastructure can be applied.
Distributed Load Testing Using AWS Fargate
There was a need to perform load testing on web services implemented for a project. The tests
were conducted for a Web service running on Amazon ECS with a solution that runs Distributed
Load Tests using AWS Fargate and Taurus, which in turn uses JMeter in the background. We
can use it to test our services under high stress scenarios and understand its behavior and
scalability.
2. Following are the links where this has been explained in detail.
https://aws.amazon.com/solutions/implementations/distributed-load-testing-on-aws
https://github.com/aws-samples/distributed-load-testing-using-aws-fargate
https://www.youtube.com/watch?v=Uv7I75pLmb4
Installation and Configuration
Steps to install and configure Taurus Load testing environment.
$ git clone https://github.com/aws-samples/distributed-load-testing-using-
aws-fargate
$ cd distributed-load-testing-using-aws-fargate/
$ docker build -t load-tests-using-fargate .
Edit the taurus.yml file to include the website URL.
$ vi examples/http/taurus.yml
Modify the last line as per your requirement.
execution:
- concurrency: 10
ramp-up: 5m
hold-for: 25m
scenario: aws-website-test
scenarios:
aws-website-test:
requests:
- http://test.example.com/
The DNS domain example.com has been taken in this article, as the implementation was carried
out on a real DNS domain name that has been replaced to maintain confidentiality.
Run the Load testing using Docker container
[root@linux-host]# docker run -it load-tests-using-fargate taurus.yml
07:59:58 INFO: Taurus CLI Tool v1.15.3
07:59:58 INFO: Starting with configs: ['taurus.yml']
07:59:58 INFO: Configuring...
07:59:58 INFO: Artifacts dir: /tmp/artifacts
07:59:58 INFO: Preparing...
07:59:59 WARNING: Failed to check for updates
08:00:02 INFO: Starting...
08:00:02 INFO: Waiting for results...
08:00:02 INFO: Waiting for finish...
08:00:22 INFO: Changed data analysis delay to 5s
08:00:42 INFO: Changed data analysis delay to 3s
08:05:07 INFO: Changed data analysis delay to 4s
08:30:06 WARNING: Please wait for graceful shutdown...
08:30:06 INFO: Shutting down...
08:30:06 INFO: Post-processing...
08:30:07 INFO: Test duration: 0:30:04
3. Taurus uses JMeter in the background
As the Taurus script is now in the running state, the load on web server started on the URL
http://test.example.com and as per the scaling policy, the tasks on ECS start to scale out to 4 as
shown in the next section.
Figure: Taurus running as Docker container
Figure: Service getting into Alarm State
4. Figure: Time window when web requests were high due to Load Testing
Figure: Alarm Details
5. Figure: Alarm Trigger Action
Figure: Cluster service with 4 scaled out AWS Fargate tasks
6. Figure: Tasks reach their maximum limit, showing Task IDs and other details
Figure: Taurus at 89% just before finishing the Load Testing
7. After the load testing script stopped, we now see that tasks are being decremented to 3, as shown
in the image below.
Figure: Events showing container tasks decrementing
Figure: Running Task count is now at 3 as per desired count
8. Figure: Desired task count is now 2
Figure: Running Task count is now at 2 as per desired count
9. Figure: Desired task count is now 1
Figure: Load at its minimum. Running Task count is now 1
10. Load Testing with ApacheBench
Another Load Testing tool called Apache Bench was brought into use, which has the syntax
given as follows.
[root@linux-host ~]# ab -n 100000 -c 1000 http://test.example.com/
This will execute 100000 HTTP GET requests, processing up to 1000 requests concurrently, to
the specified URL http://test.example.com/ and output the results on the command line as given
below. Multiple such commands were run in batch, one after the other for a continued load on
the given URL.
[root@linux-host ~]# ab -n 100000 -c 1000 http://test.example.com/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking test.example.com (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests
Server Software: nginx/1.16.0
Server Hostname: test.example.com
Server Port: 80
Document Path: /
Document Length: 3032 bytes
Concurrency Level: 1000
Time taken for tests: 25.826 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 326600000 bytes
HTML transferred: 303200000 bytes
Requests per second: 3872.01 [#/sec] (mean)
Time per request: 258.264 [ms] (mean)
Time per request: 0.258 [ms] (mean, across all concurrent requests)
Transfer rate: 12349.60 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 97 123 146.2 101 2136
Processing: 98 126 111.5 102 2899
Waiting: 97 107 56.1 102 2797
Total: 195 248 190.5 204 4020
11. Percentage of the requests served within a certain time (ms)
50% 204
66% 206
75% 208
80% 209
90% 214
95% 615
98% 1208
99% 1309
100% 4020 (longest request)
Summary
In this article, we saw a web service that was implemented on Amazon ECS (Elastic Container
Service) that uses NGinx web server. To accommodate large number to simultaneous requests,
AWS Auto scaling was planned and implemented. Thereafter, to test the web service, load
testing was performed using Taurus that sent 1000’s of web requests simultaneously. This
triggered an alarm in AWS and our ECS containers started to scale up to become 4 similar tasks
running in parallel. When the load on web server was removed by stopping the scripts, the ECS
containers gradually cool down and decrement back to the original state.
References
https://docs.aws.amazon.com/AmazonECS/latest/userguide/service-autoscaling-
targettracking.html
https://medium.com/@kgekkula.at/aws-fargate-scaling-with-target-tracking-policy-
4c79149cb3dc
Document version 2
Dated: 30th April 2022