Demystifying Google Cloud Run Pricing: Untangling CPU and Memory Costs for Optimal Savings
Ahmed Zakaria
Sr. Cloud DevOps Engineer | DevOps Solution Architect at _VOIS | 6x GCP | CKA | CKAD | Azure | Multi-Cloud Certified
In today's dynamic cloud computing landscape, serverless platforms like Google Cloud Run offer unparalleled flexibility and scalability to businesses of all sizes. However, one of the most common challenges users face is understanding and estimating the costs associated with these services. Cloud Run's pricing model, based on CPU and memory usage, can be puzzling for newcomers, leading to confusion when attempting to utilize the Google Billing Calculator and encountering unexpected results. In this article, we'll provide a comprehensive breakdown of Cloud Run pricing, shedding light on CPU and memory costs, while demystifying the free tier and offering valuable insights on cost optimization strategies.
Section 1: Understanding Cloud Run Pricing - CPU and Memory Breakdown
Cloud Run operates on a pay-as-you-go model, meaning you only pay for the resources consumed during the execution of your containerized applications. The two primary cost factors are CPU usage, measured in vCPU-seconds, and memory usage, measured in GiB-seconds. While this model provides cost transparency and flexibility, grasping the intricacies of calculating these usage metrics is vital for accurate billing estimations.
Section 2: Unraveling the Free Tier
Fortunately, Google Cloud Run offers a generous free tier, providing developers with a substantial allocation of resources at no cost. However, understanding how to leverage this offering effectively can be challenging. The free tier as per documentation for Tier 1 and for services with?CPU only allocated during request includes 180,000 vCPU-seconds per month for CPU usage and 360,000 GiB-seconds per month for memory usage. Being aware of these complimentary resources is essential to avoid unnecessary confusion when using the billing calculator and discovering a cost of 0 despite adding a significant number of requests.
Section 3: Mastering the Calculation - Examples to Simplify Cost Estimations
Let's demystify the process of calculating vCPU-seconds and GiB-seconds consumed. We'll walk through practical examples to make cost estimations more straightforward and accurate:
As per the documentation?https://cloud.google.com/run/pricing,
?Cloud Run bases its pricing on two factors:
?Cloud Run charges you only for the resources you use, rounded up to the nearest 100 millisecond. Your total Cloud Run bill will be the sum of the resource usage in the pricing table after the free tier is applied.
Let's Suppose ?We fall under Tier 1 billing(europe-west1 region), and our?Services are?with?CPU only allocated during request
?so....
CPU-based pricing :
$0.00002400 / vCPU-second beyond free tier
Free:?The?good news?is Cloud Run offers a generous free tier. The?first 180,000 vCPU-seconds per month are free in each region. (First 180,000 vCPU-seconds free per month)
Memory based-pricing:
$0.00000250 / GiB-second beyond free tier? & Free:?First 360,000 GiB-seconds free per month
Suppose we will use the highest number available: 8 VCPU and 32 GB memory,
In the Cost calculator, I inputted a high number of requests , which is 700,000 requests, and the total estimated cost was only 63.32 USD per month.
Cost breakdown:
as per google cloud calculator, for 8 CPU and 32GiB we have?6250 FREE?request per month.
After performing the equation and testing with 6265 requests, the cost for CPU usage amounts to 0.01 USD per second. ( increments by around 15)
1 Request per 8 CPU = 28.8 vCPU/sec
Pricing For 1 CPU :
Cloud Run pricing is based on vCPU-seconds, which means the number of virtual CPU cores allocated to your service multiplied by the number of seconds those cores are used.
The Free Tier
The good news is Cloud Run offers a generous free tier. The first 180,000 vCPU-seconds per month are free in each region.
Calculating vCPU-Seconds Consumed
To calculate the vCPU-seconds consumed by your Cloud Run services, you need to know:
? The number of vCPUs allocated to the service. You specify this when deploying the service, for example 1 vCPU.
? The runtime of the service - how long it takes to handle a request in seconds. For example, 3.6 seconds.( to follow google cloud calculator as estimation).
? The request rate - the number of requests per second your service receives.
Then for each request, your service will consume:
vCPUs allocated * Runtime = vCPU-seconds consumed per request
For example:
1 vCPU * 3.6 seconds = 3.6 vCPU-seconds per request
So if your service handles 50,000 requests within the free tier and each request takes 3.6 seconds, it will consume:
50,000 requests * 3.6 vCPU-seconds/request = 180,000 vCPU-seconds (free)
Pricing After the Free Tier
After exhausting the free tier, Cloud Run charges $0.00002400 per vCPU-second.
Nearly , every 115 requests (after the free tier) will cost you roughly $0.01, since each request uses 3.6 vCPU-seconds.( by playing around with google cloud calculator)
With this understanding of Cloud Run's CPU-based pricing model, we can estimate costs and optimize resource usage to stay within your budget.
领英推荐
Pricing For 512 MB?:
Here is a breakdown of Cloud Run pricing based on memory usage:
Cloud Run prices memory usage in GiB-seconds, which is the amount of memory allocated to your service in gigabytes multiplied by the number of seconds it is used.
The Free Tier
The free tier for memory is 360,000 GiB-seconds per month in each region.
Calculating GiB-Seconds Consumed
To calculate the GiB-seconds consumed, you need to know:
? The memory allocated to the service. You specify this when deploying the service, for example 512 MB or 0.5 GiB.
? The runtime of the service in seconds.
? The request rate.
Then for each request, your service will consume:
Memory allocated * Runtime = GiB-seconds consumed per request
For example:
0.5 GiB * 0.9 seconds = 0.9 GiB-seconds per request
If your service handles 400,000 requests within the free tier and each request takes 0.9 seconds, it will consume:
400,000 requests * 0.9 GiB-seconds/request = 360,000 GiB-seconds (free)
Pricing After the Free Tier
After exhausting the free tier, Cloud Run charges $0.0000025 per GiB-second.
For example, every 5,000 requests (after the free tier) will cost you around $0.01 since each request uses 0.9 GiB-seconds.
So in summary, to estimate your memory costs for Cloud Run, calculate the GiB-seconds consumed based on the memory allocated, runtime, and request rate of your services.
-------------
Grouping CPU and memory:
The Free Tier
? CPU has 180,000 vCPU-seconds free per month, allowing for ~50,000 free requests.
? Memory has 360,000 GiB-seconds free per month, allowing for ~400,000 free requests.
This means:
? You will only be billed for CPU usage until you exceed ~50,000 requests.
? Once you reach ~400,000 requests, you will start being billed for memory usage as well.
Billing Increments
After the free tier:
? CPU - Every ~115 requests incurs ~$0.01 in additional cost.
? Memory - Every ~5,000 requests incurs ~$0.01 in additional cost.
So once you reach ~405,000 requests in a month:
? You would have exhausted the CPU free tier (~50,000 requests) and used some paid CPU.
? You would have just reached the memory free tier limit (400,000 requests).
This means at ~405,000 requests, you would see:
? Some CPU billing (for requests 51,000 to 405,000)
? Initial memory billing (for requests 400,000 to 405,000)
Totaling roughly $0.01 based on Cloud Run's pricing of $0.000024 per vCPU-second for CPU and $0.0000025 per GiB-second for memory.
Section 5: Summary and Cost Optimization Strategies
Understanding Cloud Run's pricing model empowers you to:
? Calculate estimated costs for your services accurately.
? Optimize resource allocation (CPU/memory) to minimize expenses.
? Monitor usage effectively to stay within your budget and prevent surprises.
Billable instance time (From documentation)
The billable time aggregated from all Cloud Run instances is exposed as a Cloud Monitoring metric. See?container/billable_instance_time?metric?for more details.
Billable instance time is rounded up to the nearest 100 milliseconds and depends on the?CPU allocation?configuration of your Cloud Run service:
Conclusion:
Cloud Run's serverless capabilities bring remarkable efficiency and flexibility to application deployment, but understanding its pricing intricacies is essential for budget-conscious users. By demystifying CPU and memory costs, unraveling the free tier, and embracing cost optimization strategies, businesses can harness the true potential of Google Cloud Run while making well-informed decisions that align with their financial objectives.
Founding Engineer @ Stealth Start-up
1 年Very few resources out there untangling Cloud Run pricing, massive thanks!
Lead Software Engineer | Senior Full-Stack & DevOps | 2x Early Startup Engineer | Building Technical Foundations for Startups
1 年Hi Ahmed Zakaria, Great article! "Totaling roughly $0.01 based on Cloud Run's pricing of $0.000024 per vCPU-second for CPU and $0.0000025 per GiB-second for memory." Is the total ($0.01) sum of both vCPU and memory? Or just memory?
Softwareingenieur bei SCHWABEO GmbH
1 年This is great, thanks
Network Engineer
1 年Hello sir , would you tell me how to learn Google cloud certificate, and how to do inscription in platform and registration exam , and thank you in advence
Data Engineering Lead || Cloud Data Engineer || Data Analytics || Data Warehousing || Digital Transformation || GCP || MS Azure Data Engineering Associate #Azure_Certified #GCP_Certified
1 年Great work Zakariaaaa????