<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dickson Armijos on Medium]]></title>
        <description><![CDATA[Stories by Dickson Armijos on Medium]]></description>
        <link>https://medium.com/@dicksonarmijos?source=rss-ae81336e639d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Tsc12L2o_8Z7yOvd</url>
            <title>Stories by Dickson Armijos on Medium</title>
            <link>https://medium.com/@dicksonarmijos?source=rss-ae81336e639d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:09:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dicksonarmijos/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optimizing costs with GitHub Actions and AWS Fargate Spot.]]></title>
            <link>https://medium.com/building-la-haus/optimizing-costs-with-github-actions-and-aws-fargate-spot-3a7690b4d199?source=rss-ae81336e639d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a7690b4d199</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[fargate]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Dickson Armijos]]></dc:creator>
            <pubDate>Tue, 19 Dec 2023 16:57:18 GMT</pubDate>
            <atom:updated>2023-12-29T20:12:52.419Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimizing costs with GitHub Actions and AWS Fargate Spot</h3><p>The La Haus Platform team embarked on a substantial project to enhance the efficiency of CI (Continuous Integration) workflows, with a particular emphasis on reducing the time that automated unit tests take to run which we considered to be very long. This article explores specific unit testing workflows, highlighting a remarkable 60% improvement in time efficiency, resulting in a highly beneficial optimization, including an impressive reduction of more than 90% in our monthly costs.</p><p>AWS Fargate plays a pivotal role in our solution. This serverless service, managed by AWS, enables container execution without the need to manage the underlying infrastructure. Similar to EC2 instances with different purchasing options (On-Demand, Spot, etc.) Fargate offers Spot instances, a cost-effective solution providing up to a 70% discount on the standard Fargate price for Amazon Elastic Container Service (Amazon ECS) tasks tolerant to interruptions. While tasks in Fargate Spot may face interruptions, AWS provides a two-minute notice when claiming capacity. This service is ideal for fault-tolerant workloads, offering significant cost optimization.</p><p>There are various tools for creating CI/CD workflows, and in our case, we use GitHub Actions, a service provided by GitHub that enables the automation of custom workflows for tasks such as running tests and deploying applications. A crucial component of GitHub Actions is the self-hosted runners. Unlike GitHub’s cloud-hosted runners, which are virtual machines managed by GitHub, self-hosted runners are machines that you own and manage locally or in the cloud. They can be physical machines, virtual machines, or containers, providing flexibility to customize the execution environment according to the specific needs of your workflows.</p><h3>Context</h3><p>One of the crucial challenges was the prolonged execution times in unit testing workflows. This situation created a significant bottleneck for developers creating Pull Requests (PRs), preventing their merge into the main branch until all unit tests ran successfully. As a result, the service workflow experienced delays and efficiency issues, impacting the smooth integration of code changes through PRs.</p><p>In the worst-case scenario, the workflow took up to 25 minutes to execute, while in the best-case scenario, it was 15 minutes. However, this variability affected development efficiency. To assess the impact, let’s delve into some metrics at our disposal. Our Platform team has diligently worked to expose this information, including DORA metrics (DevOps Research and Assessment), aiding us in quantifying the problem.</p><p>In image 1, we observe a total of 5.63 PR commits per day. This value needs to be multiplied by the number of open PRs in the month of April, as unit tests are triggered with each push event from a PR. This results in a total of 309 executions of our unit tests in April.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DwWBePGgnxDnAKeq" /><figcaption><strong>Image 1:</strong> Dashboard with GitHub repository metrics to analyze pain points.</figcaption></figure><p>Considering the best-case scenario, where the workflow takes only 15 minutes, and factoring in the monthly execution count (309) of our unit tests, developers would invest a total of 77.25 hours per month in running these tests, this provides a clear perspective on the monthly time burden developers might face when bringing their changes into production environments.</p><h3>Solution</h3><p>The La Haus Platform team dedicated itself to developing a comprehensive solution to address challenges impacting agility in the development and implementation of new functionalities in the system. This solution evolved over time, but we can break it down into three fundamental stages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zppeVLfY9OzS5oh3NYMVmQ.png" /><figcaption><strong>Image 2:</strong> Cost diagram for the execution of unit testing workflows.</figcaption></figure><p>In the <strong>first stage</strong>, we migrated our workflows, which ran tests sequentially to parallel execution using matrices. This approach resulted in a drastic reduction in execution times, significantly improving process efficiency.</p><p>The <strong>second stage</strong> marked a move towards experimenting with Fargate Spot instances on AWS. This initiative not only allowed us to cut costs but also complemented the time reduction achieved in the first stage.</p><p>In the <strong>final stage</strong>, we implemented a solution leveraging Fargate Spot instances to keep costs low without compromising the execution times of unit tests. This approach provided us with an optimal balance between operational efficiency and cost-effectiveness.</p><h3>Optimization with the SemaphoreCI Matrix (May 2022 — August 2022)</h3><p>In this initial stage of our quest for efficiency, we faced the challenge of drastically reducing the execution times of our unit testing workflows. The migration of our workflows from sequential to parallel execution using SemaphoreCI’s <a href="https://docs.semaphoreci.com/essentials/build-matrix/">matrix functionality</a> marked a significant milestone. We managed to reduce the execution times from 15–25 minutes to 6–8 minutes, achieving a 60% improvement.</p><p>We can use the month of May as an example to get an idea of what we were paying monthly on SemaphoreCI for the execution of our unit tests. This setup involved running tests sequentially, resulting in extended execution times. While this approach worked well, challenges with execution time and inefficiency became apparent as the development scale increased.</p><p>In June 2022, we decided to explore SemaphoreCI’s job matrix to address the challenge of prolonged execution times. This change brought a significant improvement in execution times, reducing them to a range of 6 to 8 minutes. However, this efficiency benefit came with an expected increase in monthly costs, with these initial tests reaching $327 and being further incremented in the months of July and August. The transition to executing our unit tests in a matrix increased the number of jobs, moving from one job per pipeline to 30 jobs per pipeline for each unit test execution. This resulted in higher resource consumption as 30 standard-sized instances ran simultaneously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YK_4o2T0LYof0J4K1Bzq8Q.png" /><figcaption><strong>Image 3:</strong> Migration diagram from the execution of sequential workflows to a workflow in a job matrix.</figcaption></figure><p>While this approach was efficient in terms of execution times, it logically incurred increased costs due to the quantity of parallel jobs. This highlights the economic and operational challenges we faced in attempting to enhance our CI/CD workflows. Optimization required not only reducing execution times but also finding an efficient balance between costs and resources.</p><h3>Initial Integration of Fargate and GitHub Actions (September 2022 — December 2022)</h3><p>In the next stage of our quest for workflow efficiency, we decided to implement a solution that involved running our workflows on Fargate Spot instances. The core functionality is based on a reusable workflow that creates GitHub Actions runners to be used by other workflows. As depicted in image 4, the reusable workflow utilizes Terraform to create the necessary resources in the ECS cluster. We chose this solution for its flexibility and ease of implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9nzv6m25hBiRxz8aJuFxA.png" /><figcaption><strong>Image 4:</strong> Diagram of the first solution implemented with Fargate Spot.</figcaption></figure><p>However, as the demand for runners increased exponentially, reaching up to 100–150 workflows running in parallel, scalability and performance challenges began to emerge. Image 5 reflects these challenges and represents a crucial point in our ongoing assessment of solutions aimed at enhancing operational efficiency in high-intensity execution environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YRhvHJ1LtjynNpFO" /><figcaption><strong>Image 5:</strong> Scalability errors presented in GitHub Actions workflows.</figcaption></figure><p>An essential aspect of this solution is how we manage to create GitHub Actions runners of different sizes and images. Fargate instances have specific resource compatibility, and based on this, we’ve established the following instance groups.</p><ul><li>nano: 0.5 vCPU, 1GB RAM</li><li>micro: 1 vCPU, 2GB RAM</li><li>small: 1 vCPU, 4GB RAM</li><li>medium: 2 vCPU, 4GB RAM</li><li>large: 4 vCPU, 8GB RAM</li><li>xlarge: 4 vCPU, 12GB RAM</li></ul><p>This instance group can have an n:n relationship with our images stored in AWS ECR. This enables us to customize our runners by equipping them with various pre-installed tools/services, resulting in reduced time in our workflows. There&#39;s no need to create steps to install heavyweight tools, which can take a long time, or specific versions that we need to test. At this point, you can let your imagination soar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpyW8W-Ie_AkNCUe3F1RFQ.png" /><figcaption><strong>Image 6:</strong> Structure of the Docker images used in Fargate instances.</figcaption></figure><p>As depicted in image 6, we have a base image containing our fundamental tools, including the GitHub Actions agent. From this base image, we can create customized images for different teams. This achievement in the process is crucial, as many of the elements implemented here will be utilized in our subsequent phase.</p><h3>Adoption of Fargate Spot Instances (January 2023 — Present)</h3><p>In this phase, it became evident that continuing to leverage Fargate Spot instances was the right path, although the implemented solution (referring to the stage 2 implementation) posed occasional challenges. Meanwhile, we had been testing an alternative solution for other workloads, which was proving highly effective. The key distinction was that this alternative utilized EC2 Spot instances instead of Fargate Spot.</p><p>The Terraform module <a href="https://github.com/philips-labs/terraform-aws-github-runner">philips-labs/terraform-aws-github-runner</a> is a project that performs quite well. We use this project for several of our workflows, and it functions seamlessly. This module simplifies the creation of all the necessary infrastructure for leveraging EC2 Spot instances. It operates by establishing an application on GitHub that directs all workflow-related events to an AWS Lambda. This Lambda processes specific events, queues them and dispatches them, ultimately creating an EC2 Spot instance. Having comprehended the functionality of this solution, we opted to fork and modify the module to tailor it to our requirements, successfully deploying Fargate Spot instances with the same agility demonstrated with EC2 instances.</p><blockquote><em>📝 Note</em></blockquote><blockquote>You may need to refer to the Terraform module <a href="https://github.com/philips-labs/terraform-aws-github-runner/blob/main/docs/component-overview.svg">architecture diagram</a> for more context.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z8JOwYI17KF6gehZ_T6W-A.png" /><figcaption><strong>Image 7:</strong> Diagram of the solution implemented by refactoring the Terraform module.</figcaption></figure><p>This implementation provided us with the ability to create custom runners for our teams with different images and sizes (see image 7). This aspect is crucial, as it directly contributes to cost reduction. By configuring custom instances, we can opt for smaller resources in workflows that do not require extensive capabilities. In our case, we recognized that running unit tests did not required 2 CPUs and 7GB, which is the <a href="https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#cloud-hosts-used-by-github-hosted-runners">standard GitHub Actions instance</a>. Therefore, we decided to create smaller instances that wouldn’t impact workflow performance while keeping costs low.</p><p>At this point, it’s crucial to mention an additional key factor in maintaining low costs in this implementation. These runners typically need to download many packages (pip install, npm install, bundle install, etc.) from the Internet, incurring internet-facing costs that should not be overlooked. This means that if we deploy all our runners within private subnets, we must factor in the cost of transferring data through our NAT Gateway resource. A straightforward alternative is deploying the runners within public subnets. While this incurs a cost, it is comparatively lower than the expense associated with a NAT Gateway, which is particularly beneficial when dealing with substantial data transfers. It’s important to emphasize that, for security reasons and to avoid triggering alerts with security team, we need to include a security group that blocks all incoming traffic to the Fargate instances since there is no need for other services to reach them.</p><p>This solution brought significant economic benefits. To provide an overview, we can compare the average costs of the months of June and July (the months when the job matrix was implemented) from the first stage against the months of the third stage (see image 2), resulting in a savings of 97.49%. As we have observed the stability of the solution, we have been migrating new workflows to this solution, so this percentage may even be slightly higher.</p><blockquote><em>⚠️ Warning</em></blockquote><blockquote>While this solution brings many benefits, there is a crucial consideration to keep in mind. Fargate instances do not support running containers with Docker-in-Docker (DinD) capability. This implies that commands such as docker build cannot be executed, and as a result, any workflow involving image construction will not be compatible with this solution.</blockquote><h3>Results</h3><h3>Cost Analysis</h3><p>To better understand financial efficiency, we compared the estimated costs of running the same scenario on SemaphoreCI, GitHub Actions (in their cloud), and Fargate Spot instances. Let’s take the previous example and attempt to analyze the costs, considering an average of 5.65 PR commits per day and a total of 55 PRs created throughout the month of May. In the implemented solution, we have an average of 30 jobs running in parallel to execute all our unit tests, and we need to use this value for our calculations.</p><p>It’s important to note that the cost of Fargate Spot constantly changes; in this case, we are using values taken at the time of writing this article ($0.014577 per vCPU per hour, $0.00160066 per GB per hour), while for <a href="https://github.com/pricing/calculator">GitHub Actions</a> and <a href="https://docs.semaphoreci.com/account-management/billing-overview/#price-per-machine-type">SemaphoreCI</a>, we will use the values found in their documentation up to today. For an estimation of the cost difference, we can employ the following Python script</p><blockquote><em>⚠️ Warning</em></blockquote><blockquote>The following calculations assume that we will use 100 GB of internet-facing; you may have to update the GB transferred depending on your case.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c106a50197b8bdd87c48331aa367ed3/href">https://medium.com/media/4c106a50197b8bdd87c48331aa367ed3/href</a></iframe><p>Output:</p><pre>| Platform                    | Monthly Cost   |   Nro. of Executions | Total Time per Execution   | Resources Used   |<br>|-----------------------------|----------------|----------------------|----------------------------|------------------|<br>| GitHub Actions (Standard)   | $372.88 USD    |                 9322 | 5 min                      | 2 vCPU, 7 GB RAM |<br>| SemaphoreCI (e1-standard-2) | $349.57 USD    |                 9322 | 5 min                      | 2 vCPU, 4 GB RAM |<br>| Fargate Spot (Custom)       | $40.35 USD     |                 9322 | 5 min                      | 2 vCPU, 7 GB RAM |</pre><p>The total monthly cost of Fargate Spot is $40.35 USD, representing a significant reduction of 89.1% compared to GitHub Actions (Standard Instance) with a total cost of $372.88 USD, and an 88.5% reduction compared to SemaphoreCI (e1-standard-2 Instance) with a total cost of $349.57 USD. It&#39;s important to note that the actual cost of Fargate Spot may vary depending on internet-facing requirements. The provided percentage is based on using a Fargate instance size comparable to the standard instances of GitHub and SemaphoreCI. However, opting for smaller Fargate instances could potentially increase the percentage of savings even further.</p><h3>Time Savings</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B13MF8leD2Otm7ef" /><figcaption><strong>Image 8</strong>: GitHub repository metrics dashboard to analyze implementation benefits.</figcaption></figure><p>Let’s take a comprehensive look at the results gained over time (May 2022 — October 2023). The PR Cycle Time by Day graph illustrates the evolution of the time it takes to merge PRs into the main branch over time. There is a noticeable trend of decreasing cycle time, indicating an improvement in process efficiency.</p><p>A significant decrease is evident in June and July 2022, followed by sporadic peaks. However, starting in September 2022, continuous improvement will be observed. It is crucial to consider external factors that may influence merge times. Some days exhibit exceptionally long cycles, which could indicate potential areas for improvement.</p><p>Reducing the PR Cycle Time by Day not only signifies improved process efficiency but also translates into quantifiable benefits. This includes an increased number of deployments and faster deployment speeds, fostering agility and minimizing waiting periods for developers. These enhancements not only boost overall productivity, but also have the potential to contribute to cost savings through efficient resource utilization.</p><p>Recently, we have been implementing further optimizations to reduce the execution time of our tests. If you’re interested, you may want to take a look at <a href="https://medium.com/p/1d75229cb5b3">this article</a>.</p><p><a href="https://medium.com/building-la-haus/implement-seekable-oci-for-our-github-actions-workloads-1d75229cb5b3">Implement Seekable OCI for our GitHub Actions workloads</a></p><h3>Conclusions</h3><ul><li>The transition from sequential to parallel workflow execution using SemaphoreCI matrices resulted in a significant 60% improvement in execution times. This optimization substantially enhanced operational efficiency, ensuring a faster integration of code changes through PRs. The same solution could be translated to GitHub Actions while maintaining low execution times.</li><li>The implementation of Fargate Spot instances, coupled with meticulous optimization, resulted in a remarkable cost reduction, plummeting from an average of $1,500 per month to less than $50 (around a 97.4% reduction). This achievement was realized by optimizing Fargate Spot resources and customizing instances according to workflow needs. This substantial cost-saving measure aligns with the overarching goal of achieving maximum efficiency with minimal expenditure, prompting the migration of more workflows to this solution.</li><li>The adoption of Fargate Spot instances, combined with GitHub Actions, introduced a new level of flexibility. Custom runners with different sizes and images were implemented, allowing teams to precisely adapt their environments. This not only optimized resource usage but also ensured that workflows aligned seamlessly with team-specific requirements, contributing to cost reduction by establishing fewer resources than some workflows actually require.</li><li>Visualizing the reduction in PR Cycle Time provides a clear and measurable representation of the impact on development speed. A consistent decrease suggests that the implemented solution yields positive results, indicating increased efficiency. This not only accelerates the delivery of new functionalities but also contributes to a more agile and streamlined development process.</li><li>The final adopted architecture leverages the open-source project terraform-aws-github-runner, which was adapted to generate GitHub Actions runners on-demand in Fargate Spot tasks but has certain limitations when running workflows that require DinD.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a7690b4d199" width="1" height="1" alt=""><hr><p><a href="https://medium.com/building-la-haus/optimizing-costs-with-github-actions-and-aws-fargate-spot-3a7690b4d199">Optimizing costs with GitHub Actions and AWS Fargate Spot.</a> was originally published in <a href="https://medium.com/building-la-haus">Building La Haus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement Seekable OCI for our GitHub Actions workloads]]></title>
            <link>https://medium.com/building-la-haus/implement-seekable-oci-for-our-github-actions-workloads-1d75229cb5b3?source=rss-ae81336e639d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d75229cb5b3</guid>
            <category><![CDATA[fargate]]></category>
            <category><![CDATA[aws-ecs]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[soci]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Dickson Armijos]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 15:07:09 GMT</pubDate>
            <atom:updated>2023-12-29T20:13:56.526Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of container-based deployments, optimizing startup times is crucial to ensure efficiency and agility in application deployment. In our case, we’ve significantly improved task startup times in our Amazon Elastic Container Service (ECS) cluster by implementing <strong>Seekable OCI</strong> (SOCI), an Amazon Web Services (AWS) technology that allows for deferred loading of container images. The impact that SOCI had on both speed and costs far exceeded our initial expectations, achieving accelerations of up to 3 times in the launch of containers in addition to reducing costs by more than 24%.</p><p>SOCI is a technology developed by the AWS team that allows applications to scale faster by allowing them to run without needing to download the entire container image. Rather than pulling the full image to start a container, SOCI allows extracting only the specific metadata needed. By selectively seeking the required image metadata, SOCI avoids transferring unnecessary data. This “lazy loading” approach provides significant time savings in container startup times (<a href="https://aws.amazon.com/about-aws/whats-new/2022/09/introducing-seekable-oci-lazy-loading-container-images/">see more</a>).</p><h4>Context</h4><p>From the Platform team at La Haus, we have created an ECS cluster that is designed to create Fargate Spot tasks that deploys GitHub <a href="https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners">self-hosted runner</a> instances. This configuration suits a variety of use cases, including private database backup tasks, resource-intensive tests, or tasks that require communication with services on private networks. The flexibility of the ECS cluster and Fargate Spot capabilities enables secure, customizable runtime environments for different teams and their specific needs. With custom container images, our solution seamlessly integrates GitHub Actions into workflows, ensuring optimal performance for tasks ranging from resource-intensive testing to runtime environments with pre-installed tools.</p><p>It’s important to note that the Docker images we use vary in size, with the smallest being around 1.7 GB and the largest reaching approximately 2.9 GB. This variability in image sizes can impact task start and deployment times in the ECS cluster.</p><h4>SOCI Dependencies</h4><p>It’s important to highlight that for SOCI to function correctly, certain dependencies are required, including nerdctl.</p><p>This choice is due to the fact that Docker does not store the compressed image on disk (<a href="https://github.com/awslabs/soci-snapshotter/issues/805">open issue</a>), but rather compresses it during the push process. This means we don’t have access to the compressed layers to build the SOCI index until after the push. By using nerdctl, a tool compatible with SOCI, we can overcome this limitation and make the most of SOCI&#39;s capabilities.</p><p>Here is an example of how we can build the SOCI index of an image, assuming that you have all the necessary dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/075948f780f17f487fcc3b0ad832ebc0/href">https://medium.com/media/075948f780f17f487fcc3b0ad832ebc0/href</a></iframe><p>To create an index of your images, you can update your CI workflows by adding the commands shown above or implementing <a href="https://aws-ia.github.io/cfn-ecr-aws-soci-index-builder/">this solution</a> created by the AWS team that generates image indices with Lambda functions. This way, you can avoid modifying all your workflows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e456f73bc1cba29709784cb65800095/href">https://medium.com/media/8e456f73bc1cba29709784cb65800095/href</a></iframe><p>In our case, we have a GitHub Actions workflow that builds all our images, so we are going to update our workflows by adding the steps shown above.</p><h4>Data Analysis</h4><p>In order to analyze these, we need the following Python script that collects data on the creation time and execution start time of the ECS tasks and then stores these results in an SQLite database. The purpose of this is so that we can collect data before and after the implementation of SOCI in order to analyze the results obtained from the startup times.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/872cc6d281afb9950521cefe1fb2066f/href">https://medium.com/media/872cc6d281afb9950521cefe1fb2066f/href</a></iframe><p>The following script uses two datasets to compare the implementation without SOCI (ecs_data_v1.sqlite) and with SOCI (ecs_data_v2.sqlite), taking into account the family of tasks that we have in our cluster. Now we are ready to analyze our implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85178038252e3ed4ffc35c0e5d00a3e2/href">https://medium.com/media/85178038252e3ed4ffc35c0e5d00a3e2/href</a></iframe><h4>Comparison of Results</h4><p>All the tasks we run on our ECS cluster have different Task Definitions assigned, which allows us to create different shapes and flavors for our GitHub Actions workloads, the names of the Task Definitions are formed as follows:</p><p>sh-runner-&lt;INSTANCE_TYPE&gt;-&lt;IMAGE_NAME&gt;</p><p>Where:</p><ul><li>&lt;INSTANCE_TYPE&gt; indicates the size of the Fargate instance (nano, micro, small, etc)</li><li>&lt;IMAGE_NAME&gt; is the name of the used Docker image (base, teamS-ruby, etc).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFkrpukG1p1lx2HxUCD6yA.png" /><figcaption><strong>Image 1.</strong> List of how the Task Definitions that we use in the ECS cluster are made up, each task definition has its own size and image.</figcaption></figure><p>For example, for sh-runner-small-teamS-ruby we can see that it uses a small instance of Fargate with the teamS-ruby image.</p><p>We have defined a standard for the size of the Fargate instances that we will use in our tasks:</p><ul><li>nano: 0.5 vCPU, 1GB RAM</li><li>micro: 1 vCPU, 2GB RAM</li><li>small: 1 vCPU, 4GB RAM</li><li>medium: 2 vCPU, 4GB RAM</li><li>large: 2 vCPU, 6GB RAM</li></ul><p>Likewise, our tasks use different types of Docker images:</p><ul><li>base: base Linux image of 1.5GB</li><li>teamS-ruby: Ruby image of 2.9GB</li><li>teamS-nodejs: NodeJS image of 1.8GB</li></ul><p>This nomenclature allows us to quickly identify the resources and types of images assigned to each Task Definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hiy2rITCvkQoO0B26YaVhg.png" /><figcaption><strong>Image 2.</strong> Analysis of the results of the task startup times in the ECS cluster before using SOCI and after using SOCI.</figcaption></figure><p>The image above was generated with our Python script (show_metrics.py) to visualize the implementation results, now the results analysis for each:</p><p>For <strong>sh-runner-micro-base</strong> we see that it uses a micro instance of Fargate (1 vCPU and 2GB RAM) with a base image of 1.5GB. The 64% optimization in startup time demonstrates how quickly SOCI can extract only the necessary metadata even from medium-sized images on small instances.</p><p>In <strong>sh-runner-nano-base</strong> we have an even smaller nano instance (0.5 vCPU and 1GB RAM) but with the same base image. Despite having fewer resources, SOCI achieved a 61% reduction in startup time.</p><p>For <strong>sh-runner-small-base</strong>, a slightly more powerful small instance was used (1 vCPU and 4GB RAM), but with the same base image. The benefit of SOCI was similar to the &quot;micro&quot; case, with a 66% improvement.</p><p>In <strong>sh-runner-small-teamS-nodejs</strong> we see the impact of SOCI on a small instance with a heavier image of 1.8GB. Still, an acceleration of 67% was obtained.</p><p>Finally, in <strong>sh-runner-small-teamS-ruby</strong> we have the combination of a small instance with the heaviest image of 2.9GB. Despite this, SOCI produced the greatest optimization, reducing the average time by 72%.</p><h4>Performance 📈</h4><p>On average, SOCI produced an acceleration of approximately 3 times in task startup times, with improvement percentages ranging from 61% to 72% for the different evaluated Task Definitions. We have to emphasize that for small layers of our images, it is possible that there is not a big difference in the execution times. If this is the case, we can follow <a href="https://github.com/awslabs/soci-snapshotter/blob/main/docs/getting-started.md#about-the-soci-index">SOCI’s suggestion</a>:</p><blockquote>We skip building ztocs for smaller layers (controlled by --soci-min-layer-size in nerdctl push) because small layers don’t benefit much from lazy loading.</blockquote><p>This demonstrates the benefits that deferred loading of container images offers through techniques like Seekable OCI for serverless computing environments like Fargate Spot. The ability to extract and load only the necessary metadata to start a container, rather than downloading the entire image, results in much faster starts and a more efficient use of computational resources.</p><h4>Costs 🤑</h4><p>Well, it’s time to talk about 💰. Although it is somewhat complicated to define how much we are going to save with this implementation due to the unpredictable nature of our workloads, the variety of instance types we are using, and the implicit savings from avoiding the developer having to wait for that period of time, we can conduct a quick analysis by selecting a specific GitHub Actions workflow and analyzing it.</p><p>We can start with the definition shown on the AWS website:</p><blockquote>AWS Fargate pricing is calculated based on the vCPU, memory, Operating Systems, CPU Architecture, and storage resources used from the time you <a href="https://aws.amazon.com/fargate/pricing/">start to download your container image</a> until the Amazon ECS Task</blockquote><p>which means that if we have a task that is very heavy and takes around 5 minutes to pull an image, we will have to pay for those 5 minutes, and this is where SOCI can help us reduce costs.</p><p>Let’s do a quick exercise based on an average of the number of executions we have in one of our workflows that uses the Task Definitions called sh-runner-small-teamS-ruby. This workflow runs about 150 times a month, running a matrix of 30 jobs/tasks in parallel that take approximately 4 minutes each, plus an additional 2 minutes for task start (see image 2).</p><p>Considering that the Fargate small instance has 1 vCPU and 4GB of RAM, and using AWS rates of <a href="https://aws.amazon.com/fargate/pricing/">$0.04048 per vCPU hour and $0.004445 per GB-hour (Linux/X86)</a>, the cost per hour for this configuration is $0.05824.</p><p>Writing a lot of numbers seems to be a bit tedious to read, so let’s write some Python code to make it easier to understand, and it can also be useful if you have a case similar to ours and want to have an idea of what you could save with this implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce678eccd920d0ee21dbbaa59e917245/href">https://medium.com/media/ce678eccd920d0ee21dbbaa59e917245/href</a></iframe><p>Output:</p><pre>Total monthly cost without SOCI: $26.22<br>Total monthly cost with SOCI: $19.93<br>Estimated monthly savings: $6.29</pre><p>In these results, we assume that we are working with the price of Fargate on-demand instances, but our actual workload uses Spot Instances, so real-world savings may vary. However, this is a reasonable estimate of potential cost optimizations with SOCI.</p><h3>Conclusion</h3><ul><li>As demonstrated in the analysis, the implementation of Seekable OCI in our ECS cluster resulted in significant improvements in task startup times, with <strong>reductions ranging from 61% to 72%</strong> for the different evaluated definitions. While we are not currently leveraging horizontal scaling in our ECS cluster, these optimizations in startup times could facilitate faster horizontal scaling events for services running on ECS.</li><li>Regarding the impact on costs, it is worth mentioning that performing an accurate analysis is complex in our case since our Fargate Spot workloads run on demand and task volumes can fluctuate significantly from day to day, but we managed to demonstrate that a simple workflow that executes around 4500 tasks/jobs per month where the monthly cost is around $29, with the new implementation the approximate cost is $19, which means a saving of <strong>24% of only a GitHub Actions workflow</strong>. Now imagine it for all the workloads you are running on your cluster 😉</li><li>Currently, we are analyzing carrying out this same implementation for all our workloads that run in our EKS clusters in order to speed up the automatic scaling of our services, we will probably have to deal with custom AMIs.</li></ul><p>We will continue to explore ways to further improve our CI/CD processes by leveraging innovative technologies. However, these results demonstrate that achieving much more agile and cost-effective deployments in Fargate Spot with the use of SOCI is already possible.</p><p><em>In an upcoming article, we will analyze in detail how we have configured GitHub Self-Hosted Runners on Fargate Spot instances as part of our strategy to effectively run CI at lower costs.</em></p><p><a href="https://medium.com/building-la-haus/optimizing-costs-with-github-actions-and-aws-fargate-spot-3a7690b4d199">Optimizing costs with GitHub Actions and AWS Fargate Spot.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d75229cb5b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/building-la-haus/implement-seekable-oci-for-our-github-actions-workloads-1d75229cb5b3">Implement Seekable OCI for our GitHub Actions workloads</a> was originally published in <a href="https://medium.com/building-la-haus">Building La Haus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>