Skip to content

Commit e6ef06c

Browse files
nakulpathak3rtyler
authored andcommitted
Minor cleanups
1 parent 918b649 commit e6ef06c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

_posts/2021-03-18-faster-fargate-deploys.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ Scribd moved its monolith to AWS in April 2020 and as part of the migration, we
1616
Our starting implementation involved a few steps:
1717
- Deploying assets via [Capistrano](https://capistranorb.com/) to our asset-hosting servers *(2.5 minutes)*
1818
- Executing a Fargate task to run any database migrations *(3 minutes)*
19-
- Calling AWS CLI to trigger force-updates to all of our ~500 production tasks and waiting *(32-35 minutes)*
20-
21-
19+
- Restarting and waiting on ~500 Fargate tasks via the AWS CLI *(32-35 minutes)*
2220

2321
### Improvements
2422

2523
#### Fargate Service Updates
26-
By far, the slowest part of our deployment was triggering and waiting for service updates. We used the default rolling deployment which stops and starts tasks to trigger Fargate to re-pull the freshly-uploaded [ECR](https://aws.amazon.com/ecr/) image. We were able to reduce this time to 16-18 minutes with the following -
24+
By far, the slowest part of our deployment was waiting for ECS services to finish updating. We use the default rolling deployment which stops and starts tasks to force re-pulling of the freshly-uploaded [ECR](https://aws.amazon.com/ecr/) image. We were able to reduce this time to 16-18 minutes with the following -
2725

28-
* **Docker Image Size Reduction** - The first thing everyone thinks of when considering ECS Fargate speedups is how to reduce the image pull time since Fargate (unlike EC2) [has no image caching](https://github.com/aws/containers-roadmap/issues/696). However, unless you can take your image from 1Gb to 100Mb, this will not lead to significant time reductions. We reduced our compressed image size from ~900Mb to ~700Mb and it led to **little to no improvement**. It did lead to a cleaner image but that wasn't our initial goal.
26+
* **Docker Image Size Reduction** - The first thing everyone thinks of when considering ECS Fargate speedups is how to reduce the image pull time since Fargate (unlike EC2) [has no image caching](https://github.com/aws/containers-roadmap/issues/696). However, unless you can drastically reduce your image size (think 1Gb to 100Mb), this will not lead to significant time reductions. We reduced our compressed image size from ~900Mb to ~700Mb and it led to **little to no improvement**. It did lead to a cleaner image but that wasn't our initial goal.
2927

3028
* [**Deregistration Delay**](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html#deregistration-delay) - This is a property on your load balancer's target group that dictates how long a task stays in *Draining* state after it stops receiving requests. We looked in Datadog APM for the p99 latencies of our longest-running requests and changed the value from the **default 300 seconds** to 17s. This reduced service refreshes to ~22 minutes.
3129

@@ -34,14 +32,14 @@ By far, the slowest part of our deployment was triggering and waiting for servic
3432
- *"service production-web operations are being throttled. Will try again later."*
3533
Due to Scribd's high Fargate task volume, the number of requests we were making during rolling deploys to start and stop tasks was too high for AWS' default limits. We opened support tickets with the ELB and Fargate teams and were able to get those limits improved/removed. This further reduced service deploy time to 16-18 minutes.
3634

37-
* **Network Load Balancer Health Checks** - From testing in staging, we noticed that reducing our network load balancer's health-check intervals and thresholds helped reduce staging deploy time from ~9 to ~6 minutes. However, it only translated to 1-2 minutes saved in production with a much higher number of ECS tasks. You do want to be careful with the value to avoid false-positive health checks and keep in mind that updating these values requires re-creation of the ECS service it points to.
35+
* **Network Load Balancer Health Checks** - From testing in staging, we noticed that reducing our network load balancer's [health-check intervals and thresholds](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-health-checks.html) helped reduce staging deploy time from ~9 to ~6 minutes. However, it only translated to 1-2 minutes saved in production with much higher number of ECS tasks. You do want to be careful with the value to avoid false-positive health checks and keep in mind that updating these values requires re-creation of the ECS service it points to.
3836

3937
#### Asset Deployment Improvements
40-
Our asset deployments were run using Capistrano. The job ssh-ed onto our asset servers, ran a series of tasks to download, unzip, and correctly place assets. There were some issues with this approach -
38+
Our asset deployments were run using Capistrano. The job `ssh`-ed onto our asset servers, ran a series of tasks to download, unzip, and correctly place assets. There were some issues with this approach -
4139
* Dependency on Capistrano gem forced us to use the monolith Docker image as the job's base image
4240
* Our ECS service refresh job runs `docker push/pull` tasks to upload the latest image to ECR. Since we wanted to avoid Docker-in-Docker due to further bloating of the monolith image for this one case, we had separate jobs for asset and container deployment. This forced us to waste valuable Gitlab job startup and shutdown time.
4341

44-
To resolve these issues, we decided to remove Capistrano as a dependency and wrote Ruby and Bash code that performed the exact same tasks. This was added to our service deployment job and brough asset deploy time from 2.5 minutes to 30s.
42+
To resolve these issues, we decided to remove Capistrano as a dependency and wrote Ruby and Bash code that performed the exact same tasks. This was added to our service deployment job and brought asset deploy time from 2.5 minutes to 30s.
4543

4644
#### Database Migration
4745
In our case, running a database migration task in Fargate involved starting a new task instance of our `database_migration` task family. Due to Fargate startup slowness, this task would take 3 minutes to run a simple `bundle exec rails db:migrate`.

0 commit comments

Comments
 (0)