Best practices for cost-optimized Cloud Run worker pools

This page explains some aspects to consider when configuring your Cloud Run worker pools. There is no one-size-fits-all solution for cost optimization. It is important to monitor your needs, budget, and resources to determine what works best for you.

The best practices outlined in this document are specific to Cloud Run. These are not inclusive of other Google Cloud products.

Resource configurations

Optimizing your worker pools for cost involves consideration of many different configurations. Tailor these configurations to your needs to create worker pools that are reliable and cost efficient.

Select the appropriate region

Your worker pool's deployment location impacts your total cost. Cloud Run uses a two tier regional pricing model. Tier 1 regions offer a lower cost per vCPU and memory compared to Tier 2 regions, so consider deploying to a Tier 1 region.

Optimize CPU and memory utilization

The cost of your Cloud Run worker pool is impacted by its CPU/memory configuration and how long your worker pool is active, among other factors. Overprovisioning your resources can increase your costs. To determine which configuration might be best for your worker pool:

  1. Establish a baseline configuration.
  2. Monitor your metrics while testing the CPU and memory utilization metrics in Cloud Monitoring.
  3. Adjust your configuration as necessary.

If CPU utilization is consistently low under peak load, consider reducing vCPU allocation. If latency is high, consider increasing vCPU allocation.

If memory utilization is consistently low, consider reducing the allocated memory. If latency is high and memory utilization is near 100%, consider increasing the allocated memory. If you are experiencing Out of Memory (OOM) errors, you should increase the allocated memory or modify your application to prevent memory leaks or use less memory. See the Cloud Monitoring dashboard to better understand your memory utilization.

Optimize networking costs

When configuring networking options for your worker pool, consider the following:

  • Co-locate your resources: Try to deploy your Cloud Run worker pools in the same region as your backend databases (like Cloud SQL or Firestore) and Cloud Storage buckets. Data transfer between Google Cloud resources within the same region is free.
  • Switch to Direct VPC egress: If you are securely routing traffic to internal VPC network resources, consider switching to Direct VPC egress from Serverless VPC Access connectors. Direct VPC egress scales to zero, eliminating the baseline compute overhead and idle costs associated with connector instances.
  • Monitor internet egress: Inbound traffic (ingress) is always free, and you receive 1 GiB of free outbound internet data transfer per month within North America. Focus your monitoring efforts on outbound traffic that crosses region boundaries or exceeds the free tier.

Committed use discounts

Committed use discounts (CUDs) provide discounted prices in exchange for committing to continuously using Cloud Run for a specified period of time. CUDs apply at a Cloud Billing-account level. You can purchase Compute flexible CUDs for Cloud Run resources. Compute flexible CUDs don't apply to GPUs or networking. See Compute flexible committed use discount for more details.

Helpful tools

You can use the following tools to better understand your costs and to help avoid cost overruns.

Cloud Run overview: Billing panel

The Cloud Run overview page shows costs per resource name in the Billing panel. The numbers reflect the gross costs for selected time ranges per resource. This tool helps you better understand how much your resources cost.

Budget alerts

Create budget alerts in Cloud Billing to track your actual costs against your planned costs. A budget is an alerting mechanism that triggers notifications when spending thresholds are crossed, not a hard spending cap. There is a billing data delay that might impact when you receive alerts.

Cloud Billing

Cloud Billing is a collection of tools that help you track and understand your Google Cloud spending. These tools help you monitor your usage costs, forecast your spending, and identify opportunities to save on costs.

Cost Explorer

The Cost Explorer lets you understand the cost and utilization of your resources. Use Cost Explorer to:

  • Filter your resources by cost to see which resources are the most costly.
  • Understand what proportion of costs are driven by configurations such as vCPU, GPU, networking, and more.
  • Track impacts of changes to your resource configuration on your monthly bill.

Google Cloud pricing calculator

The Google Cloud pricing overview contains information for better understanding the Google Cloud pricing model. This is also where you can find the Detailed price list. You can estimate your costs by adding and configuring products by using the pricing calculator.

Recommender

Recommender is a tool that provides usage recommendations and insights for Cloud products.

Cloud Hub Optimization

You can view summary cost data, utilization data, and cost optimization recommendations for Google Cloud worker pools on Cloud Hub's Optimization page.