Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up deployments on AWS Fargate?

After migrating from EC2 cluster instances to AWS Fargate, I realized that deployments take a lot longer. Before they would take 1-2 minutes, now some deplyoments take up to 5 minutes. This post claims that their deployments on Fargate even take up to 10 minutes.

Does anybody know of a way to speed them up? I can't find any documentation on this topic.

like image 361
EagleBeak Avatar asked Jul 31 '18 16:07

EagleBeak


People also ask

How can I speed up ECS deploy?

You can speed up the deployment by setting the minimumHealthyPercent value to 50%. Use the following values for the ECS service configuration options when your tasks are idle for some time and don't have a high utilization rate.

How quickly does fargate scale?

When using the Amazon ECS service scheduler for running web and other long-running applications, you will be able to launch up to 500 tasks in under a minute per service, 16X faster than last year. Previously you would have waited for nearly 15 minutes to scale an application to 500 tasks at steady state.

How long does it take to start a fargate task?

AWS Fargate container startup time typically takes from 60 to 90 seconds. AWS Lambda initial cold start can take up to 5 seconds. Following that first startup, the same containerized function has negligible startup time.

Does fargate automatically scale?

Fargate supports auto-scaling, you can enable this within your configuration. You will need to set it to scale against a specific metric (such as average CPU or average network in).


2 Answers

Through further googling I found this Reddit thread. An AWS employee wrote:

With regard to time to provision and start a container it is definitely longer when using Fargate. We may reduce the length of the provisioning state in the future, but Fargate is doing much more under the hood than ECS on your own self managed hosts. When you self manage hosts they are already up and running, and may even already have your docker image downloaded and cached locally, so ECS is able to launch the container very quickly. That's not the case with Fargate.

So shrinking the image should help a little. But in general I guess I'll have to live with it and hope for optimizations on AWS' side.

like image 149
EagleBeak Avatar answered Oct 31 '22 09:10

EagleBeak


Here's the breakdown of tasks and possible improvements that I've found while researching options to improve my deployment times with ECS Fargate:

Fargate Deployment Overview

Here's a breakdown of what's going on behind the scenes that attribute to the deployment duration:

  • Provision the Fargate worker instance
  • Provision/attach the ENI
  • Download the Docker image
    • Here you have opportunities for improvement:
      • reduce the size of your Docker image
      • Networking throughput is based on the CPU allocations to the Fargate Task - if you allocate more CPU then you get more networking and the image will download faster
  • Application Startup time
    • Becomes a factor if your application requires a health check grace period, again effected by CPU allocation

If your task is associated with a load balancer the deployment will also need to pass health checks, and you'll need to account for:

  • Load balancer deregistration delay
  • Pass health checks: (Health Check Interval * Threshold)

How to deploy Fargate Task updates faster

  • Over allocate the CPU
  • Reduce the deregistration delay
  • Set the health check threshold to 2 and interval to 5 seconds
    • don't forget to account for a health check grace period if your app needs it

My Results

During my testing, I was able to deploy my application that typically takes about 8 minutes w/1024 CPU (1vCPU) in under 4 minutes w/4096 CPU (4vCPU)

Disclaimer

Likely your tasks typically require considerably less CPU and you don't want to be always paying for over-allocating the CPU. So, run your deployment with overallocated resources and then run another deployment right after with the original CPU allocation.

Probably not a solution you want to use for every deployment, but could be a solution for hotfix deployments.

like image 44
cynicaljoy Avatar answered Oct 31 '22 10:10

cynicaljoy