How to speed up deployments on AWS Fargate?

后端 未结 3 1077
暖寄归人
暖寄归人 2021-02-13 07:03

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 m

3条回答
  •  -上瘾入骨i
    2021-02-13 07:15

    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.

提交回复
热议问题