<?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 Eliezer Yaacov on Medium]]></title>
        <description><![CDATA[Stories by Eliezer Yaacov on Medium]]></description>
        <link>https://medium.com/@eliezerj8?source=rss-53a99842597b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*RVf6Xae9Q1RSKwmFba240A.jpeg</url>
            <title>Stories by Eliezer Yaacov on Medium</title>
            <link>https://medium.com/@eliezerj8?source=rss-53a99842597b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:40:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eliezerj8/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[How We Migrated 60% of Our Workloads to AWS Graviton with Minimal Effort (and Maximum Cost Savings!)]]></title>
            <link>https://medium.com/@eliezerj8/how-we-migrated-60-of-our-workloads-to-aws-graviton-with-minimal-effort-and-maximum-cost-savings-3d2293694d20?source=rss-53a99842597b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d2293694d20</guid>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[graviton]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Eliezer Yaacov]]></dc:creator>
            <pubDate>Sun, 16 Mar 2025 12:07:59 GMT</pubDate>
            <atom:updated>2025-03-16T12:07:59.963Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJpryqbJQF6KA63X37Z4Lg.jpeg" /></figure><h3>The Story of a Seamless Migration (That Almost Didn’t Require R&amp;D Involvement!)</h3><p>At <strong>Gloat</strong>, we love to optimize, automate, and save costs — especially when it means leveraging the latest AWS and Azure technologies. Managing multiple <strong>EKS clusters</strong> across different <strong>regions, AWS &amp; Azure accounts</strong>, and keeping everything running smoothly is no small feat. And when your awesome R&amp;D teams are churning out new microservices every week — splitting the legacy monolith into elegant, independent services — you quickly realize that compute efficiency is a top priority.</p><h3>The Mission: Migrate from AMD64 to Arm64 (Graviton)</h3><p>Why, you ask? Because <strong>cost savings</strong>, of course! AWS <strong>Graviton</strong> instances are <strong>cheaper and more efficient</strong> than their AMD64 counterparts. And since we weren’t about to rewrite our entire codebase for a simple architecture switch, we aimed to migrate <strong>without touching the application code</strong> — a true DevOps dream.</p><p>Our plan: <strong>Run the same workloads on the same infra but with better performance and lower costs.</strong></p><h3>The Strategy: Think Big, Change Small</h3><p>Instead of diving into complex refactors, we asked ourselves: <strong>How can we get the biggest impact with the least amount of work?</strong></p><h4>Step 1: Make the CI/CD Pipeline Multi-Arch Compatible</h4><p>We <strong>standardized our CI pipeline</strong> to <strong>build Docker images for both AMD64 and Arm64</strong> architectures, making sure every new deployment could run on either. Here’s how we did it in <strong>GitHub Actions</strong>:</p><pre>name: Build Multi-Arch Docker Image<br>on:<br>  push:<br>    branches:<br>      - main<br>    tags:<br>      - &#39;v*&#39;<br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v3<br>      - name: Set up QEMU<br>        uses: docker/setup-qemu-action@v2<br>      - name: Set up Docker Buildx<br>        uses: docker/setup-buildx-action@v2<br>      - name: Login to Amazon ECR<br>        run: |<br>          aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR }}<br>      - name: Build and push multi-arch image<br>        run: |<br>          docker buildx build \<br>            --platform linux/amd64,linux/arm64 \<br>            --tag ${{ secrets.AWS_ECR }}/my-app:${{ github.sha }} \<br>            --tag ${{ secrets.AWS_ECR }}/my-app:latest \<br>            --push .</pre><p>This ensured that every service now had <strong>two versions of its image</strong> in <strong>ECR</strong>, allowing us to deploy flexibly across different architectures.</p><h4>Step 2: Deploy on Graviton with Karpenter &amp; Node Affinity</h4><p>With <strong>Karpenter</strong> managing our <strong>EKS clusters</strong>, we introduced <strong>new node pools</strong> that were <strong>Graviton-only</strong>. These were tagged with <strong>taints</strong>, ensuring that only compatible workloads could be scheduled there.</p><p>Our <strong>Helm chart</strong> and <strong>Kubernetes manifests</strong> now included the following:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: my-app<br>spec:<br>  template:<br>    spec:<br>      nodeSelector:<br>        nodePool: ng-general-graviton-tainted<br>      tolerations:<br>        - key: &quot;graviton&quot;<br>          operator: &quot;Exists&quot;</pre><p>By simply <strong>modifying the nodeSelector and tolerations</strong>, we could gradually shift workloads <strong>without touching application code</strong>.</p><h4>Step 3: Roll Out to DEV First, Then the Big Leagues</h4><p>Like any responsible team, we first <strong>tested</strong> our changes in <strong>DEV clusters</strong>, validating that our Python and Node.js applications ran smoothly on <strong>Graviton</strong>. Since modern versions of both <strong>Python and Node.js already support Arm64</strong>, everything worked almost instantly.</p><p>Once validated, we rolled out the changes to <strong>staging</strong> and finally to <strong>production</strong> environments — with <strong>zero disruption to engineers</strong>!</p><h3>The Results: Big Wins with Minimal Effort</h3><ul><li><strong>60% of our workloads</strong> are now running on <strong>Graviton</strong>, with <strong>just a few changes in CI/CD and Helm</strong>.</li><li>We achieved <strong>massive cost savings</strong>, <strong>without reducing compute resources</strong>.</li><li>The <strong>R&amp;D teams barely noticed the migration</strong> (because we didn’t need their intervention for most cases).</li></ul><h3>The Remaining Challenges (a.k.a. The Hard Stuff)</h3><p>While most services migrated smoothly, <strong>legacy apps</strong> remained a problem:</p><ul><li><strong>Older Python dependencies</strong> made some applications difficult to rebuild.</li><li>Some images required <strong>manual intervention</strong> from R&amp;D teams.</li><li>We <strong>kept some AMD64 nodes</strong> to ensure <strong>flexibility</strong> for edge cases.</li></ul><h3>The Takeaway: 80/20 Rule at Its Finest</h3><p>We followed the <strong>Pareto principle</strong>: <strong>80% of the migration was achieved with 20% of the effort</strong> — just a few CI/CD and Helm tweaks. Now, we can work on the final 40% while reaping <strong>immediate cost savings</strong>.</p><p>The best part? We <strong>kept the migration smooth</strong> and <strong>seamless for R&amp;D</strong>. It was a <strong>purely DevOps-driven</strong> initiative, proving that <strong>big optimizations don’t always require big changes</strong>.</p><h3>Final Thoughts</h3><p><strong>Graviton adoption doesn’t have to be hard.</strong> With the right <strong>CI/CD automation</strong>, smart <strong>node pool strategies</strong>, and a <strong>modular Helm chart</strong>, you can achieve <strong>big efficiency gains with minimal engineering friction</strong>. If you’re looking for a <strong>low-effort, high-impact way to save on cloud costs</strong>, this is it!</p><p>Now, off to convince the last remaining legacy apps to embrace the <strong>Graviton revolution</strong>… one dependency upgrade at a time! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d2293694d20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gloat-ing About Our Multi-Arch EKS Migration: Cutting Costs with Graviton Nodes]]></title>
            <link>https://medium.com/@eliezerj8/title-gloat-ing-about-our-multi-arch-eks-migration-cutting-costs-with-graviton-nodes-1578eea00488?source=rss-53a99842597b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1578eea00488</guid>
            <category><![CDATA[graviton]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[multiarch]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <dc:creator><![CDATA[Eliezer Yaacov]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 13:30:25 GMT</pubDate>
            <atom:updated>2024-08-18T13:40:48.270Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there, fellow cloud adventurers! 🚀 Ever found yourself knee-deep in Kubernetes configurations, wishing for a magic wand to make things work? Well, grab your coffee (or tea, no judgments here), and let me take you through my recent escapade of setting up a multi-architecture Amazon EKS cluster. Buckle up; it’s going to be a fun ride!</p><h3><strong>The Quest Begins: EKS Version 1.29 and Node Pools Galore</strong></h3><h3>First, let me introduce you to Gloat.com. At Gloat, we’re putting people and organizations in motion. We connect talents to opportunities, helping companies and employees grow together. With clients all around the globe, we manage EKS clusters in different regions and environments (Dev, Stg, Prod) to ensure data privacy and optimal performance. Naturally, this means our AWS compute costs can skyrocket.</h3><p>When I started with our EKS cluster running version 1.29, we had Karpenter in place from the get-go to help us manage our diverse and dynamic workloads. Our cluster was equipped with 5–6 different node pools, all of which were amd64 instances. But here’s the twist — I wanted to run both amd64 and arm64 (hello, Graviton!) nodes. Why? Because in the world of cloud computing, diversity is key, and Graviton processors offer cost efficiency and performance gains.</p><p><strong>Multi-Arch Magic: Adding Arm64 Nodes</strong></p><p>With Karpenter already in place, it was time to bring arm64 nodes into the mix. Here’s how we made it happen:</p><p><strong>Defining Node Pools</strong></p><p>We created NodePools for both amd64 and arm64 architectures. NodePools are like blueprints for your nodes, defining things like the instance types and other configurations.</p><p><strong>AMD64 Node Pool</strong></p><pre>apiVersion: v1<br>kind: NodePool<br>metadata:<br> name: amd64-nodepool<br>spec:<br> instanceType: [&quot;r5.large&quot;, &quot;r5.xlarge&quot;]<br> architecture: &quot;amd64&quot;</pre><p><strong>ARM64 (Graviton) Node Pool</strong></p><pre>apiVersion: v1<br>kind: NodePool<br>metadata:<br> name: arm64-nodepool<br>spec:<br> instanceType: [&quot;r6g.large&quot;, &quot;r6g.xlarge&quot;]<br> architecture: &quot;arm64&quot;</pre><h3><strong>Migrating Services: Smooth Sailing to Graviton</strong></h3><p>Now came the fun part — migrating our services to run on the new Graviton nodes. This is where I felt like a true cloud magician.</p><p><strong>Updating Our CI Pipeline</strong></p><p>To support multi-architecture images, we had to update our CI pipeline. We switched from the traditional Docker build command to `buildx`, which allows building images for multiple architectures. Here’s how it went down:</p><p><strong>1. Set up `buildx`:</strong></p><pre>docker buildx create - use</pre><p><strong>2. Build and tag multi-arch images:</strong></p><pre>docker buildx build - platform linux/amd64,linux/arm64 -t my-app:latest - push .</pre><p><strong>3. Push to our internal ECR:</strong></p><pre>aws ecr get-login-password - region &lt;region&gt; | docker login - username AWS - password-stdin &lt;account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com<br> docker buildx build - platform linux/amd64,linux/arm64 -t &lt;account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com/my-app:latest - push .</pre><p><strong>Rebuilding All Images</strong></p><p>We re-built all our images with the same tag, ensuring that they are now compatible with both amd64 and arm64 architectures. This meant that deployments without a `nodeSelector` defined (which, admittedly, is a bad practice but our current state) could run on any node in the cluster without issues, as the same tag now supports both architectures.</p><p><strong>Gradual Migration to Graviton</strong></p><p>To ensure a smooth transition, especially since we have several Python apps using AI and modeling libraries (which can be finicky on arm processors), we decided to migrate apps one by one. We created a node pool containing only Graviton nodes and used a `nodeSelector` block to start changing our apps individually:</p><p><strong>Graviton Node Pool</strong></p><pre>apiVersion: v1<br>kind: NodePool<br>metadata:<br> name: arm64-nodepool<br>spec:<br> instanceType: [&quot;r6g.large&quot;, &quot;r6g.xlarge&quot;]<br> architecture: &quot;arm64&quot;</pre><p><strong>Deployment with Node Selector</strong></p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br> name: my-app<br>spec:<br> template:<br> spec:<br> containers:<br> - name: my-app-container<br> image: &lt;account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com/my-app:latest<br> ports:<br> - containerPort: 80<br> nodeSelector:<br> kubernetes.io/arch: arm64</pre><p><strong>Rolling Out Changes</strong></p><p>With manifests updated, we rolled out the changes. Kubernetes, with its usual grace, handled the deployment seamlessly. Our services were now happily running on Graviton nodes, basking in the glory of arm64 efficiency.</p><h3>Conclusion: The Hero’s Return</h3><p>Migrating to a multi-arch EKS cluster managed with Karpenter was a journey worth taking. Not only did we cut costs by leveraging Graviton processors, but we also optimized our cluster for diverse workloads, all while carefully managing the transition for our more complex applications.</p><p>So, if you’re looking to embark on a similar adventure, take my advice: trust in Karpenter, embrace multi-arch, and remember to have fun along the way. Happy clustering!</p><p>— -</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1578eea00488" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy AWS MWAA (Airflow) environments in scale using Terraform]]></title>
            <link>https://medium.com/similarweb-engineering/how-to-deploy-airflow-environments-in-scale-using-aws-mwaa-9c35606a7a5e?source=rss-53a99842597b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c35606a7a5e</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[similarweb]]></category>
            <category><![CDATA[production-engineering]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Eliezer Yaacov]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 19:46:34 GMT</pubDate>
            <atom:updated>2023-03-29T09:37:06.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmEdGIoGwZFHkd-LCLmSeg.png" /></figure><p>For years now, Airflow become the standard for using a platform for developing and scheduling batch workflows.</p><p>If you ever tried to manage the infrastructure for airflow, you probably had to tailor your solution for creating the MetaStore DB, queue or key-value storage for the scheduler, servers to host the web servers, workers and scheduler components, and maybe other component to create a fully, functional, production-ready Airflow environment.</p><p>While it might sounds complex, we used to run Airflow on a vary infrastructures such as Nomad and Kubernetes and it was good enough. The actual problem started when we wanted to scale up Airflow environments creation. The ability to create environment in a hour, with all its component, gave us the ability to develop, test and deploy changes quickly to production, work on few parallel data sets with separated environments and more.</p><p>If you are looking to create airflow environments in scale, quickly, the following solution worked for us.</p><p><strong>Amazon Managed Workflows for Apache Airflow (MWAA) is a fully managed service that makes it easy to run open-source versions of Apache Airflow on AWS. With AWS MWAA, you can easily build, run, and scale your workflows without having to manage the underlying infrastructure. In this article, we’ll guide you through the steps to create an AWS MWAA environment in Terraform, including an IAM execution role and an S3 bucket.</strong></p><p>The entire infrastructure in Similarweb managed in Terraform code. We created a Terraform module with the following parts:</p><ul><li>MWAA environment</li><li>S3 bucket</li><li>IAM role (execution role)</li><li>IAM user (CI user)</li></ul><p><a href="https://docs.aws.amazon.com/mwaa/latest/userguide/mwaa-s3-bucket.html">The S3 bucket</a> purpose is to contain all code relevant for Airflow env (DAGs, requirements, plugins, etc).</p><p><a href="https://docs.aws.amazon.com/mwaa/latest/userguide/mwaa-create-role.html">The execution role</a> is required by MWAA env to invoke actions on the different services in the environment such as logs and metrics, access to the bucket, etc.</p><p>The IAM user purpose is to provide the full solution with automatic code deployment. Whether managing the code in GitHub, Gitlab or any other version control system, we’ll want a process of code deployment, when the code is verified, and upload it to the S3 bucket. For that, we’ll use awscli with the user, to manage the code sync.</p><p>Baseline for Terraform — All code tested on Terraform 0.14.11 and up, AWS provider 4.9 and up.</p><blockquote>MWAA Environment —</blockquote><pre>resource &quot;aws_mwaa_environment&quot; &quot;managed_airflow&quot; {<br>  airflow_version                = &quot;2.2.2&quot;<br>  airflow_configuration_options  = {<br>    .....<br>    &quot;core.dag_file_processor_timeout&quot;           = 150<br>    &quot;core.dagbag_import_timeout&quot;                = 90<br>    ....<br>  }<br>  dag_s3_path                    = &quot;dags/&quot;<br>  execution_role_arn             = module.execution_role.role_arn<br>  name                           = &quot;airflow-env-name&quot;<br>  environment_class              = &quot;mw1.small&quot;<br><br>  network_configuration {<br>    security_group_ids = [aws_security_group.managed_airflow_sg.id]<br>    subnet_ids         = [&quot;A&quot;, &quot;B&quot;] # 2 subnets required for high availability<br>  }<br><br>  source_bucket_arn               = aws_s3_bucket.managed-airflow-bucket.arn<br>  weekly_maintenance_window_start = &quot;SUN:19:00&quot;<br><br>  logging_configuration {<br>    dag_processing_logs {<br>      enabled   = true<br>      log_level = &quot;WARNING&quot;<br>    }<br><br>    scheduler_logs {<br>      enabled   = true<br>      log_level = &quot;WARNING&quot;<br>    }<br><br>    task_logs {<br>      enabled   = true<br>      log_level = &quot;WARNING&quot;<br>    }<br><br>    webserver_logs {<br>      enabled   = true<br>      log_level = &quot;WARNING&quot;<br>    }<br><br>    worker_logs {<br>      enabled   = true<br>      log_level = &quot;WARNING&quot;<br>    }<br>  }<br><br>  tags = {<br>    name = &quot;airflow-env-name&quot;<br>    .....<br>  }<br><br>  lifecycle {<br>    ignore_changes = [<br>      requirements_s3_object_version,<br>      plugins_s3_object_version,<br>    ]<br>  }<br><br>}<br><br><br>##### Security group<br>resource &quot;aws_security_group&quot; &quot;managed_airflow_sg&quot; {<br>  name        = &quot;managed_airflow-sg&quot;<br>  vpc_id      = &lt;required-vpc-id&gt;<br><br>  tags = {<br>    Name          = &quot;managed-airflow-sg&quot;<br>  }<br>}<br><br>##### Security group rules<br>resource &quot;aws_security_group_rule&quot; &quot;allow_all_out_traffic_managed_airflow&quot; {<br>  type              = &quot;egress&quot;<br>  from_port         = 0<br>  to_port           = 0<br>  protocol          = -1<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>  security_group_id = aws_security_group.managed_airflow_sg.id<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;allow_inbound_internal_traffic&quot; {<br>  type              = &quot;ingress&quot;<br>  from_port         = 443<br>  to_port           = 443<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = data.terraform_remote_state.network_remote_state.outputs.internal_subnet_cidrs<br>  security_group_id = aws_security_group.managed_airflow_sg.id<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;self_reference_sgr&quot; {<br>  type              = &quot;ingress&quot;<br>  from_port         = 0<br>  to_port           = 65535<br>  protocol          = &quot;tcp&quot;<br>  self              = true<br>  security_group_id = aws_security_group.managed_airflow_sg.id<br>}</pre><blockquote>S3 Bucket —</blockquote><pre>resource &quot;aws_s3_bucket&quot; &quot;managed-airflow-bucket&quot; {<br>  bucket        = &quot;airflow-bucket-sw&quot;<br>  force_destroy = &quot;false&quot;<br><br>  tags = {<br>    Name          = &quot;airflow-bucket-sw&quot;<br>    .....<br>  }<br>}<br><br>resource &quot;aws_s3_bucket_versioning&quot; &quot;managed-airflow-bucket-versioning&quot; {<br>  bucket = aws_s3_bucket.managed-airflow-bucket.id<br>  versioning_configuration {<br>    status = &quot;Enabled&quot;<br>  }<br>}</pre><p>Bucket must be defined with versioning as a requirement by MWAA environment. The version of the files helps to manage changes in production environments for requirements, plugins and more.</p><blockquote>IAM execution role and policy —</blockquote><pre>data &quot;aws_iam_policy_document&quot; &quot;execution_role_policy&quot; {<br>  version = &quot;2012-10-17&quot;<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;airflow:PublishMetrics&quot;<br>    ]<br>    resources = [<br>      &quot;arn:aws:airflow:${var.region}:${var.account_id}:environment/${var.name}*&quot;<br>    ]<br>  }<br>  statement {<br>    effect  = &quot;Deny&quot;<br>    actions = [&quot;s3:ListAllMyBuckets&quot;]<br>    resources = [<br>      &quot;arn:aws:s3:::${var.bucket_name}&quot;,<br>      &quot;arn:aws:s3:::${var.bucket_name}/*&quot;<br>    ]<br>  }<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;s3:GetObject*&quot;,<br>      &quot;s3:GetBucket*&quot;,<br>      &quot;s3:List*&quot;<br>    ]<br>    resources = [<br>      &quot;arn:aws:s3:::${var.bucket_name}&quot;,<br>      &quot;arn:aws:s3:::${var.bucket_name}/*&quot;<br>    ]<br>  }<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;s3:GetAccountPublicAccessBlock&quot;<br>    ]<br>    resources = [&quot;*&quot;]<br>  }<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;logs:CreateLogStream&quot;,<br>      &quot;logs:CreateLogGroup&quot;,<br>      &quot;logs:PutLogEvents&quot;,<br>      &quot;logs:GetLogEvents&quot;,<br>      &quot;logs:GetLogRecord&quot;,<br>      &quot;logs:GetLogGroupFields&quot;,<br>      &quot;logs:GetQueryResults&quot;<br>    ]<br>    resources = [<br>      &quot;arn:aws:logs:${var.region}:${var.account_id}:log-group:airflow-${var.name}-*&quot;<br>    ]<br>  }<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;logs:DescribeLogGroups&quot;<br>    ]<br>    resources = [<br>      &quot;*&quot;<br>    ]<br>  }<br>  statement {<br><br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;cloudwatch:PutMetricData&quot;<br>    ]<br>    resources = [<br>      &quot;*&quot;<br>    ]<br>  }<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;sqs:ChangeMessageVisibility&quot;,<br>      &quot;sqs:DeleteMessage&quot;,<br>      &quot;sqs:GetQueueAttributes&quot;,<br>      &quot;sqs:GetQueueUrl&quot;,<br>      &quot;sqs:ReceiveMessage&quot;,<br>      &quot;sqs:SendMessage&quot;<br>    ]<br>    resources = [<br>      &quot;arn:aws:sqs:${var.region}:*:airflow-celery-*&quot;<br>    ]<br>  }<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;kms:Decrypt&quot;,<br>      &quot;kms:DescribeKey&quot;,<br>      &quot;kms:GenerateDataKey*&quot;,<br>      &quot;kms:Encrypt&quot;<br>    ]<br>    resources = var.kms_key_arn != null ? [<br>      var.kms_key_arn<br>    ] : []<br>    not_resources = var.kms_key_arn == null ? [<br>      &quot;arn:aws:kms:*:${var.account_id}:key/*&quot;<br>    ] : []<br>    condition {<br>      test = &quot;StringLike&quot;<br>      values = var.kms_key_arn != null ? [<br>        &quot;sqs.${var.region}.amazonaws.com&quot;,<br>        &quot;s3.${var.region}.amazonaws.com&quot;<br>      ] : [<br>        &quot;sqs.${var.region}.amazonaws.com&quot;<br>      ]<br>      variable = &quot;kms:ViaService&quot;<br>    }<br>  }<br>}<br><br><br>resource &quot;aws_iam_role&quot; &quot;role&quot; {<br>  name                 = &quot;airflow-execution-role&quot;<br>  path                 = &quot;/&quot;<br>  tags                 = local.tag_list<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;role-policy&quot; {<br>  name   = &quot;airflow-execution-role-policy&quot;<br>  role   = aws_iam_role.role.id<br>  policy = data.aws_iam_policy_document.execution_role_policy.json<br>}</pre><p>The execution role has access to KMS for a given key. We can extend this policy of course if we need airflow to access other services, but this is the baseline, recommended by AWS.</p><blockquote>IAM User (CI user) —</blockquote><pre>data &quot;aws_iam_policy_document&quot; &quot;ci_user_policy&quot; {<br>  statement {<br>    effect = &quot;Allow&quot;<br>    actions = [<br>      &quot;s3:GetObject*&quot;,<br>      &quot;s3:GetBucket*&quot;,<br>      &quot;s3:List*&quot;,<br>      &quot;s3:PutObject&quot;,<br>      &quot;s3:DeleteObject&quot;,<br>      &quot;s3:GetEncryptionConfiguration&quot;,<br>    ]<br>    resources = [<br>      &quot;arn:aws:s3:::${var.bucket_name}&quot;,<br>      &quot;arn:aws:s3:::${var.bucket_name}/*&quot;<br>    ]<br>  }<br>}<br>resource &quot;aws_iam_user&quot; &quot;app_user&quot; {<br>  name = &quot;appusr_airflow_ci&quot;<br>  path = &quot;/&quot;<br>  tags = local.tag_list<br>  <br>}<br><br>resource &quot;aws_iam_access_key&quot; &quot;access_key&quot; {<br>  user = aws_iam_user.app_user.name<br>}<br><br>resource &quot;aws_iam_user_policy&quot; &quot;user_policy&quot; {<br>  name   = &quot;airflow_ci_policy&quot;<br>  user   = aws_iam_user.app_user.name<br>  policy = data.aws_iam_policy_document.ci_user_policy.json<br>}<br><br>output &quot;ci_access_key&quot; {<br>  value = aws_iam_access_key.access_key.id<br>}<br><br>output &quot;ci_secret_key&quot; {<br>  value = aws_iam_access_key.access_key.secret<br>}</pre><p>The user will have permissions to sync the source code containing the DAGs, requirements and plugins to an S3 bucket. The user needs permission to add/update and delete files if necessary, and its actions limited to the bucket only. Warning: apply the code like that, will expose the secret key to the output.</p><p>Eventually, the CI user will be used to sync the code to the S3 bucket, as followed:</p><pre>AWS_ACCESS_KEY_ID=&lt;CI-USER-ACCESS-KEY&gt; \<br>AWS_SECRET_ACCESS_KEY=&lt;CI-USER-SECRET-KEY&gt; \<br>aws s3 sync ./ s3://$AWS_S3_BUCKET/ \<br>            --delete \<br>            --exclude &#39;.git/*&#39; \<br>            --exclude &lt;EXTRA-FILES-NEEDED&gt; \</pre><p>Just to emphasize how simple is it to create Airflow env, using the suggested solution here, the following is a call for a Terraform module which contains all the above parts:</p><pre>locals {<br>  airflow_configuration_options = {<br>    ....<br>    &quot;core.dag_file_processor_timeout&quot; = 150<br>    &quot;core.dagbag_import_timeout&quot; = 90<br>    ....<br>  }<br>}<br><br>module &quot;managed_airflow_web_platform&quot; {<br>  source  = &quot;terraform-registry-url/airflow-managed/aws&quot;<br>  version = &quot;~&gt; 2.0&quot;<br><br>  subnet_cidrs                         = [&quot;10.10.X.Y/27&quot;, &quot;10.10.X.Z/27&quot;]<br>  dag_s3_path                          = &quot;dags/&quot;<br>  name                                 = &quot;sw-airflow&quot;<br>  bucket_name                          = &quot;sw-airflow&quot;<br>  cicd_user                            = &quot;sw-airflow-ci-user&quot;<br>  requirements_s3_path                 = &quot;requirements.txt&quot;<br>  plugins_s3_path                      = &quot;plugins.zip&quot;<br>  environment_class                    = &quot;mw1.large&quot;<br>  airflow_configuration_options        = local.airflow_configuration_options<br>  dag_processing_logs_level            = &quot;INFO&quot;<br>}</pre><p>All we have to do now is run Terraform apply on this example state, connect a git repository to it which manages the DAGs and airflow code and we have full Airflow environment setup in no time. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c35606a7a5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/similarweb-engineering/how-to-deploy-airflow-environments-in-scale-using-aws-mwaa-9c35606a7a5e">Deploy AWS MWAA (Airflow) environments in scale using Terraform</a> was originally published in <a href="https://medium.com/similarweb-engineering">Similarweb Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing a Golang service to reduce over 40% CPU]]></title>
            <link>https://medium.com/coralogix-engineering/optimizing-a-golang-service-to-reduce-over-40-cpu-366b67c67ef9?source=rss-53a99842597b------2</link>
            <guid isPermaLink="false">https://medium.com/p/366b67c67ef9</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[coralogix]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Eliezer Yaacov]]></dc:creator>
            <pubDate>Tue, 03 Mar 2020 10:27:03 GMT</pubDate>
            <atom:updated>2020-03-03T10:27:03.887Z</atom:updated>
            <content:encoded><![CDATA[<p>10 years ago, Google was facing a critical bottleneck caused by extremely prolonged C++ compilation times and needed a totally new way to solve it. Google engineers tackled the challenge by creating a new language called Go (aka Golang). The new language of Go borrows the best parts of C++, (most notably it’s performance and security features) and combines it with the speed of Python to enable Go to quickly use multiple cores while being able to implement concurrency.</p><p>Here, at Coralogix, we’re parsing our clients’ logs in order to give them real-time insights, alerts, and meta-data on their logs. In order to do that, the parsing phase, which is very complex and loaded with tons of rules for each log line service, must be extremely quick. That’s one of the reasons we decided to use Go lang.</p><p>The new service is now running full-time in production and while we’re seeing great results, it needs to run on high-performance machines. Over tens of billions of logs are parsed every day by this Go service that runs on an AWS m4.2xlarge instance with 8 CPUs and 36 GB of Memory.</p><p>At this stage, we could have called it a day feeling great that all was running well, but that’s not how we roll here at Coralogix. We wanted more features (performance, etc) using less (AWS instances). In order to improve, we first needed to understand the nature of our bottlenecks and how we can reduce or eliminate them completely.</p><p>We decided to run some profiling on our service and check what exactly caused high CPU consumption to see if we can optimize.</p><p>First, we have upgraded to the latest stable Go version (a key part of the software lifecycle). We were on Go version v1.12.4, and the latest was 1.13.8. The 1.13 release, according to the <a href="https://golang.org/doc/devel/release.html">documentation</a> had major improvements in the runtime library and a few other components which mainly utilized memory usage. Bottom line, working with the latest stable version was helpful and saved us quite some work →</p><p>Thus, memory consumption <strong>improved from about ~800MB to ~180MB</strong>.</p><p>Second, in order to get a better understanding of our process and understand where we’re spending time and resources, we started to profile.</p><p>Profiling different services and programming languages may seem complex and intimidating, but it’s actually pretty easy in Go and can be described in few commands. Go has a dedicated tool called ‘pprof’ that should be enabled in your app by listening to a route (default port — 6060) and use the Go package for managing HTTP connections:</p><pre>import _ &quot;net/http/pprof&quot;</pre><p>Then initialize the following in your main function or under your route package:</p><pre>go func() {<br>	log.Println(http.ListenAndServe(&quot;localhost:6060&quot;, nil))<br>}()</pre><p>Now you can start your service and connect to</p><pre><a href="https://slack-redir.net/link?url=http%3A%2F%2Flocalhost%3A6060%2Fdebug%2Fpprof">http://localhost:6060/debug/pprof</a></pre><p>Full documentation by Go can be found <a href="https://golang.org/pkg/net/http/pprof">here</a>.</p><p>The default profiling for pprof will be a 30 seconds sampling of CPU usage. There are a few different paths that enable sampling for CPU usage, heap usage and more.</p><p>We focused on our CPU usage, so we took a 30-sec profiling in production and discovered what you see in the image below (reminder: this is after upgrading our Go version and decreasing the internal parts of Go to the minimum):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/0*a9L3eu_Ij6UbTpFn.png" /><figcaption>Go profiling — Coralogix</figcaption></figure><p>As you can see, we found lots of runtime package activity, which indicated specifically GC activity → Almost <strong>29%</strong> <strong>of our CPU</strong> (just the top 20 most consumed objects) is used by GC. Since Go GC is quite fast and pretty optimized, the best practice is to not change or modify it and since our memory consumption was very low (compared to our previous Go version) the main suspect was a high object allocation rate.</p><p>If that’s the case, there are two things that we can do:</p><ul><li>Tune Go GC activity to adapt to our service behavior, meaning — delay its trigger in order to activate the GC less frequently. <strong>This will force us to compensate for more memory.</strong></li><li>Find the function, area or line in our code that allocates too many objects.</li></ul><p>Looking at our instance type, it was clear that we had a lot of memory to spare and we are currently bound by the machine CPU. So we just switched that ratio. Golang, since its early days, has a flag that most developers are not aware of, called GOGC. This flag, with a default of 100, simply tells the system when to trigger GC. The default will trigger the GC process whenever the heap reaches 100% of its initial size. Changing that value to a higher number will delay the GC trigger and lowering it will trigger GC sooner. We started benchmarking a few different values and the best performance for our purpose was achieved when using: GOGC=2000.</p><p>This immediately <strong>increased our memory usage from ~200MB to ~2.7GB</strong> (That’s after memory consumption decreased due to our Go version update) and <strong>decreased our CPU usage by ~10%</strong>.<br>The following screenshot demonstrates the benchmark results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/0*ph2lZaEJjG-2tg-k.png" /><figcaption>GOGC =2000 results — Coralogix benchmark</figcaption></figure><p>The top 4 CPU consuming functions are our service’s functions, which makes sense. Total GC usage is now <strong>~13%, less than half of its previous consumption(!)</strong></p><p>We could have stopped there, but decided to uncover where and why we allocate so many objects. Many times, there’s a good reason for that (for example in case of stream processing where we create lots of new objects for each message we get and need to get rid of it because it’s irrelevant for the next message), but there are cases in which there’s an easy way to optimize and dramatically decreasing object creation.</p><p>To start off, let’s run the same command as before with one small change to take the heap dump:</p><pre><a href="https://slack-redir.net/link?url=http%3A%2F%2Flocalhost%3A6060%2Fdebug%2Fpprof%2Fheap">http://localhost:6060/debug/pprof/heap</a></pre><p>In order to query the result file you can run the following command within your code folder in order to analyze the dump:</p><pre>go tool pprof -alloc_objects &lt;HEAP.PROFILE.FILE&gt;</pre><p>our snapshot looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/0*0uxzm-5sDGLoe_JH.png" /></figure><p>All seemed reasonable except for the third row, which is a monitoring function reporting to our Prometheus exporter at the end of each Coralogix rule parsing phase. In order to get deeper, we ran the following command:</p><pre>list &lt;FunctionName&gt;</pre><p>For example:</p><pre>list reportRuleExecution</pre><p>And then we got the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lVGTGdZWeecjPBFl.png" /></figure><p>The 2 calls to WithLabelValues are Prometheus calls for metrics (we left it for Product to decide whether they really need it or not). Also, we saw that the first row is creating a huge amount of objects (10% of the total objects allocated by that function). We took a deeper look and saw it was a conversion from int to string for the customer ID we attached to the reported metric, which is important, but considering the fact that there’s a limited amount of customers in our DB, we shouldn’t adapt to Prometheus’ way of receiving variables as strings. So instead of creating a new string each time and at the end of the function throw it away (wasted allocation and more work for the GC) we defined a map at the initialization of the object, including mapping for all numbers between 1 to 100K and performed a “get” action from that map in that function.</p><p>A new profiling session was run now to verify our thesis and proved that it was correct (you can see that this part doesn’t allocate objects anymore):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pv-_OEq_cm7rZZaB.png" /></figure><p>This wasn’t a dramatic improvement, but overall that saves us another GC activity and to be more specific — about 1% CPU.</p><p>The final status is in the snapshot attached:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*C7GBurb09ZUHHpRb.png" /></figure><h3>Final results:</h3><p><strong>1) Memory usage: ~1.3GB → 2.7GB<br>2) CPU usage: ~2.55 avg and ~5.05 at peaks → ~2.13 avg and ~2.9 at peaks.</strong></p><p>CPU before our Golang optimizations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jz7EcSRDxR5n3MQj.png" /></figure><p>CPU after our Golang optimizations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Akyd0xfQ3FRsMiII.png" /></figure><p>Overall, we see that the major improvement was at peak times when our log processing per second increases. This means that now our infrastructure doesn’t have to be tuned for outliers but is much more stable.</p><h3>Conclusion</h3><p>By profiling our parser Go service we were able to pinpoint the problematic areas, understand our service better, and decide where, if at all, to invest our time in order to improve. A majority of profiling jobs end up in basic tuning of flags or configurations resulting in a better fit for your use case and ultimately better performance.</p><p>It is an exciting time to join Coralogix’s engineering team. If this sounds interesting to you, please take a look at our job page — <a href="https://coralogix.com/careers/">Work at Coralogix</a>. We have lots of improvement to do as well as new features to develop (which cause more latency issues and performance improvement…. it’s a vicious cycle).</p><p>Thanks for reading. Drop me a message if you have questions or want to discuss more optimizing Go or other services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=366b67c67ef9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coralogix-engineering/optimizing-a-golang-service-to-reduce-over-40-cpu-366b67c67ef9">Optimizing a Golang service to reduce over 40% CPU</a> was originally published in <a href="https://medium.com/coralogix-engineering">Coralogix Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing a Golang service to reduce over 40% CPU]]></title>
            <link>https://medium.com/@eliezerj8/optimizing-a-golang-service-to-reduce-over-40-cpu-201296135516?source=rss-53a99842597b------2</link>
            <guid isPermaLink="false">https://medium.com/p/201296135516</guid>
            <category><![CDATA[profiling]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[coralogix]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Eliezer Yaacov]]></dc:creator>
            <pubDate>Tue, 03 Mar 2020 10:14:30 GMT</pubDate>
            <atom:updated>2020-03-03T10:14:30.552Z</atom:updated>
            <content:encoded><![CDATA[<p>10 years ago, Google was facing a critical bottleneck caused by extremely prolonged C++ compilation times and needed a totally new way to solve it. Google engineers tackled the challenge by creating a new language called Go (aka Golang). The new language of Go borrows the best parts of C++, (most notably it’s performance and security features) and combines it with the speed of Python to enable Go to quickly use multiple cores while being able to implement concurrency.</p><p>Here, at Coralogix, we’re parsing our clients’ logs in order to give them real-time insights, alerts, and meta-data on their logs. In order to do that, the parsing phase, which is very complex and loaded with tons of rules for each log line service, must be extremely quick. That’s one of the reasons we decided to use Go lang.</p><p>The new service is now running full-time in production and while we’re seeing great results, it needs to run on high-performance machines. Over tens of billions of logs are parsed every day by this Go service that runs on an AWS m4.2xlarge instance with 8 CPUs and 36 GB of Memory.</p><p>At this stage, we could have called it a day feeling great that all was running well, but that’s not how we roll here at Coralogix. We wanted more features (performance, etc) using less (AWS instances). In order to improve, we first needed to understand the nature of our bottlenecks and how we can reduce or eliminate them completely.</p><p>We decided to run some profiling on our service and check what exactly caused high CPU consumption to see if we can optimize.</p><p>First, we have upgraded to the latest stable Go version (a key part of the software lifecycle). We were on Go version v1.12.4, and the latest was 1.13.8. The 1.13 release, according to the <a href="https://golang.org/doc/devel/release.html">documentation</a> had major improvements in the runtime library and a few other components which mainly utilized memory usage. Bottom line, working with the latest stable version was helpful and saved us quite some work →</p><p>Thus, memory consumption <strong>improved from about ~800MB to ~180MB</strong>.</p><p>Second, in order get a better understanding of our process and understand where we’re spending time and resources, we started to profile.</p><p>Profiling different services and programming languages may seem complex and intimidating, but it’s actually pretty easy in Go and can be described in few commands. Go has a dedicated tool called ‘pprof’ that should be enabled in your app by listening to a route (default port — 6060) and use the Go package for managing http connections:</p><pre>import _ &quot;net/http/pprof&quot;</pre><p>Then initialize the following in your main function or under your route package:</p><pre>go func() {<br>	log.Println(http.ListenAndServe(&quot;localhost:6060&quot;, nil))<br>}()</pre><p>Now you can start your service and connect to</p><pre><a href="https://slack-redir.net/link?url=http%3A%2F%2Flocalhost%3A6060%2Fdebug%2Fpprof">http://localhost:6060/debug/pprof</a></pre><p>Full documentation by Go can be found <a href="https://golang.org/pkg/net/http/pprof">here</a>.</p><p>The default profiling for pprof will be a 30 seconds sampling of CPU usage. There are a few different paths that enable sampling for CPU usage, heap usage and more.</p><p>We focused on our CPU usage, so we took a 30 sec profiling in production and discovered what you see in the image below (reminder: this is after upgrading our Go version and decreasing the internal parts of Go to the minimum):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/0*TLNzfxp08thIAEc6.png" /><figcaption>Go profiling — Coralogix</figcaption></figure><p>As you can see, we found lots of runtime package activity, which indicated specifically GC activity → Almost <strong>29%</strong> <strong>of our CPU</strong> (just the top 20 most consumed objects) is used by GC. Since Go GC is quite fast and pretty optimized, the best practice is to not change or modify it and since our memory consumption was very low (compared to our previous Go version) the main suspect was a high object allocation rate.</p><p>If that’s the case, there are two things that we can do:</p><ul><li>Tune Go GC activity to adapt to our service behavior, meaning — delay its trigger in order to activate the GC less frequently. <strong>This will force us to compensate with more memory.</strong></li><li>Find the function, area or line in our code that allocates too many objects.</li></ul><p>Looking at our instance type, it was clear that we had a lot of memory to spare and we are currently bound by the machine CPU. So we just switched that ratio. Golang, since its early days, has a flag which most developers are not aware of, called GOGC. This flag, with a default of 100, simply tells the system when to trigger GC. The default will trigger the GC process whenever the heap reaches 100% of its initial size. Changing that value to a higher number will delay the GC trigger and lowering it will trigger GC sooner. We started benchmarking a few different values and the best performance for our purpose was achieved when using: GOGC=2000.</p><p>This immediately <strong>increased our memory usage from ~200MB to ~2.7GB</strong> (That’s after memory consumption decreased due our Go version update) and <strong>decreased our CPU usage by ~10%</strong>.<br>The following screenshot demonstrates the benchmark results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/0*5LCkKFJnkCx7Nfz9.png" /><figcaption>GOGC =2000 results — Coralogix benchmark</figcaption></figure><p>The top 4 CPU consuming functions are our service’s functions, which makes sense. Total GC usage is now <strong>~13%, less than half of its previous consumption(!)</strong></p><p>We could have stopped there, but decided to uncover where and why we allocate so many objects. Many times, there’s a good reason for that (for example in case of stream processing where we create lots of new objects for each message we get and need to get rid of it because it’s irrelevant for the next message), but there are cases in which there’s an easy way to optimize and dramatically decreasing object creation.</p><p>To start off, let’s run the same command as before with one small change to take the heap dump:</p><pre><a href="https://slack-redir.net/link?url=http%3A%2F%2Flocalhost%3A6060%2Fdebug%2Fpprof%2Fheap">http://localhost:6060/debug/pprof/heap</a></pre><p>In order to query the result file you can run the following command within your code folder in order to analyze the dump:</p><pre>go tool pprof -alloc_objects &lt;HEAP.PROFILE.FILE&gt;</pre><p>our snapshot looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/0*zGfx4kmuKfCM-hvM.png" /></figure><p>All seemed reasonable except for the third row, which is a monitoring function reporting to our prometheus exporter at the end of each Coralogix rule parsing phase. In order to get deeper, we ran the following command:</p><pre>list &lt;FunctionName&gt;</pre><p>For example:</p><pre>list reportRuleExecution</pre><p>And then we got the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EDXsBA2Ngn5-0iu5.png" /></figure><p>The 2 calls to WithLabelValues are Prometheus calls for metrics (we left it for Product to decide whether they really need it or not). Also, we saw that the first row is creating a huge amount of objects (10% of the total objects allocated by that function). We took a deeper look and saw it was a conversion from int to string for the customer ID we attached to the reported metric, which is important, but considering the fact that there’s a limited amount of customers in our DB, we shouldn’t adapt to Prometheus’ way of receiving variables as strings. So instead of creating a new string each time and at the end of the function throw it away (wasted allocation and more work for the GC) we defined a map at the initialization of the object, including mapping for all numbers between 1 to 100K and performed a “get” action from that map in that function.</p><p>A new profiling session was ran now to verify our thesis and proved that it was correct (you can see that this part doesn’t allocate objects anymore):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RJnxEaWEaLfyMPr3.png" /></figure><p>This wasn’t a dramatic improvement, but overall that saves us another GC activity and to be more specific — about 1% CPU.</p><p>The final status is in the snapshot attached:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*9dRcY63vI9ae_cfN.png" /></figure><h3>Final results:</h3><p><strong>1) Memory usage: ~1.3GB → 2.7GB<br>2) CPU usage: ~2.55 avg and ~5.05 at peaks → ~2.13 avg and ~2.9 at peaks.</strong></p><p>CPU before our Golang optimizations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*83QKlmf7o-7TYeSN.png" /></figure><p>CPU after our Golang optimizations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MaV3j18nkUVSTxKP.png" /></figure><p>Overall, we see that the major improvement was at peak times when our log processing per second increases. This means that now our infrastructure doesn’t have to be tuned for outliers but is much more stable.</p><h3>Conclusion</h3><p>By profiling our parser Go service we were able to pinpoint the problematic areas, understand our service better, and decide where, if at all, to invest our time in order to improve. A majority of profiling jobs end up in basic tuning of flags or configurations resulting in a better fit to your use case and ultimately better performance.</p><p>It is an exciting time to join Coralogix’s engineering team. If this sounds interesting to you, please take a look at our job page — <a href="https://coralogix.com/careers/">Work at Coralogix</a>. We have lots of improvement to do as well as new features to develop (which cause more latency issues and performance improvement…. it’s a vicious cycle).</p><p>Thanks for reading. Drop me a message if you have questions or want to discuss more optimizing Go or other services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=201296135516" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>