How I Reduced Our CI/CD Costs by Optimizing CircleCI Machine Sizes

Gili Yaniv
3 min readMay 22, 2024

--

In the world of continuous integration and continuous deployment (CI/CD), efficiency and cost management are crucial. Over time, our team noticed that our CI/CD expenses were ballooning, primarily due to our usage of CircleCI. Upon closer inspection, it became evident that we were not optimizing our CircleCI machine sizes to fit our actual needs. Here’s how I tackled the issue and managed to significantly reduce our CI/CD costs.

Identifying the Problem

Our first step was to understand where our CI/CD pipeline was incurring the highest costs. We realized that our CircleCI configuration was over-provisioned. We were using larger and more expensive machine sizes than necessary for many of our jobs. This prompted a deeper dive into our job requirements and machine utilization.

Analyzing Job Requirements

I began by analyzing the requirements of our CI/CD jobs. This involved:
- Evaluating Resource Utilization: We monitored the CPU and memory usage of our jobs to determine the actual resources they consumed.
- Job Runtime Analysis: By examining the runtime of different jobs, we could see which ones were over-provisioned and which ones needed more resources.
- Parallelism Needs: Assessing the parallelism required for each job helped in understanding the trade-off between machine size and job completion time.

Optimizing Machine Sizes

With a clear understanding of our job requirements, we proceeded to optimize our CircleCI machine sizes. Here’s the step-by-step process we followed:

1. Baseline Resource Allocation: For each job, we established a baseline for the minimum required CPU and memory. This involved selecting the smallest machine size that could handle the job without significant slowdowns.

2. Incremental Adjustments: We incrementally adjusted the machine sizes based on real-time performance metrics. This iterative approach allowed us to fine-tune the resource allocation without compromising job performance.

3. Job Grouping and Workflow Optimization: Jobs with similar resource requirements were grouped together, enabling more efficient use of resources. We also optimized our workflows to reduce unnecessary parallelism, which in turn reduced the number of concurrent machines needed.

4. Utilizing Docker Executors: Wherever possible, we switched to Docker executors, which offered more flexibility in resource allocation and were often more cost-effective than VM-based executors.

Implementing Cost Monitoring

To ensure that our optimizations were sustainable, we implemented a cost monitoring system. This involved:
- Regular Cost Audits: Monthly audits of our CircleCI usage helped in identifying any anomalies or areas for further optimization.
- Automated Alerts: Setting up automated alerts for jobs that exceeded predefined resource thresholds enabled proactive management of our CI/CD pipeline.
- Reporting and Visualization: Using reporting tools to visualize our CI/CD costs and resource utilization provided insights into long-term trends and helped in making informed decisions.

Results and Benefits

The results of our optimization efforts were significant:
- Cost Reduction: We managed to reduce our CircleCI costs by over 15%, freeing up budget for other critical areas of development.
- Improved Efficiency: Jobs were better aligned with their resource needs, leading to faster execution times and more efficient workflows.
- Scalability: The optimized setup made it easier to scale our CI/CD pipeline as our project grew, without incurring unnecessary costs.

Conclusion

Optimizing CircleCI machine sizes to fit actual job requirements proved to be a highly effective strategy for reducing our CI/CD costs. By understanding our job needs, making incremental adjustments, and implementing robust cost monitoring, we achieved substantial savings and improved the efficiency of our CI/CD pipeline. This experience underscored the importance of continuous evaluation and optimization in managing CI/CD environments, ensuring that resources are used wisely and costs are kept in check.

Follow me on Twitter, Medium, and Linkedin to read more!

--

--

No responses yet