[Total: 1    Average: 5/5]

Introduction

Google Cloud Run charges you for the resources you use when you use them. No long running compute instances, just on-demand services. There are several components to Cloud Run services. In this article, we will look at each one. In the simplest form, the Cloud Run services comprise the container image (Container Registry + Cloud Storage), network transfer to load the container image, the Cloud Run service and network egress bandwidth.

Cloud Run is addictive. Developing containers is easy. Deploying containers to Cloud Run is effortless. With a few shell scripts, you can build and deploy in minutes. In no time at all, I have dozens of Cloud Run services running in the cloud. Managing costs is important. Understanding where these costs come from is the first step.

Container Registry

The Container Registry service is free. Container Registry stores container images and artifacts in Cloud Storage.

At this time, Container Registry is the only location that Cloud Run will pull images from. This is your repository for container images. With Cloud Run, your application is started from scratch with a container image if it has not received traffic for a while. Google has not documented how long this idle time period is. Google Stackdriver Logging shows container shutdowns with the message “Container terminated by the container manager on signal 9”.

Cloud Storage

Cloud Storage is where Google stores your container images. To reduce startup time, costs and security vulnerabilities you want your containers as small as practical. Move items such as static assets to be served from Cloud Storage, optionally fronted by a Cloud CDN. You do not want to pay for CPU time and network bandwidth to serve customers 500 KB of static CSS, Javascript and image files directly from Cloud Run.

Cloud Run is only available in us-central1 as of today. The cheapest option is to create a regional bucket in us-central1. This costs $.02 per GB. A US multi-region bucket costs $.026 per GB. Soon, Cloud Run will be available in Asia and Europe so the best locations will change.

In my Google Cloud Run – Getting Started with Python and Flask article, the container image size is 33 MB. This makes the data transfer cost negligible.

Network – Cloud Storage to Cloud Run

If your bucket is regional us-central1, there are no network transfer charges from Cloud Storage to Cloud Run. If your bucket is US multi-region, the network transfer charge is $0.01 per GB. Note: during the beta period, networking is free for US buckets.

Network – Cloud Run to the Public Internet

Network egress from Cloud Run to the public Internet is charged based upon the source (us-central1) to the destination. In this pricing example, all customers are in the US. The price is $0.12 per GB for the first 10 TB. Note: during the beta period, network egress is free.

CPU

The price is $0.00002400 / vCPU-seconds.

Memory

The price is $0.00000250 / GiB-second

Billable Time

  • The container instance is starting
  • At least one request is being processed by the container instance.
  • You are billed only for the CPU and memory allocated while a request is active on a container instance, rounded up to the nearest 100 milliseconds.

Example

You have a website that receives 1 requests per second, 24 hours per day. 128 MB of memory is allocated to each container instance. 10 concurrent requests per container instance. 100ms execute time per request. Each HTTP request returns 10 KiB of data. 100% of your customers are in the US. This example will ignore Free Quota and Always Free.

A month has 2,592,000 seconds (30-day month).

Region: us-central1

Bucket location: US multi-region

CPU Allocation Time: 259,200 vCPU-second * $0.00002400 = $6.2208

Memory Allocation Time: 32,400 GiB-second * $0.00000250 = $0.081

Requests: 2,592,000 * $0.40 per million requests = $1.036

Network Egress Bandwidth: 2,592,000 * 10240 = 24.7 GiB * $0.12 = $2.964 ($0.00 during beta period).

Total: $10.3018 after the beta ends or $7.3378 during the beta period.

Note: The Free Quota provides for the first 180,000 vCPU-seconds, 360,000 GB-seconds and 2,000,000 requests free.

Cost Improvements

There are several methods to reduce the total cost of your Cloud Run deployments.

  • Reduce the size of your container images. This has the side effect of improving the security footprint and your containers will start faster.
  • Move static assets such as CSS, JavaScript, and images to Cloud Storage. This reduces container size, startup time, CPU time and network egress.
  • Minimize the HTTP Response content. This can reduce your network egress 2x to 5x.

More Information

  • Google Cloud Platform Pricing Calculator link.
  • Google Cloud Run Pricing link.
  • Google Container Registry Pricing link.
  • Google Cloud Storage Pricing link.
  • Google Network Egress Pricing link.

Summary

If your traffic centers on specific times each day, for example, most of your traffic is during normal office hours, then your CPU and Memory prices will drop significantly as your container is not running as often during the 24-hour day. Overlapped requests cost the same as one request.

Now you might think, I can get a Compute Engine instance for those prices. However, you need to look at the CPU + Memory total + Requests and compare that to Compute Engine. For both Cloud Run and Compute Engine, you will pay the same Network Egress cost after the Cloud Run beta ends. In summary, before bandwidth pricing, Cloud Run costs $7.34. Very inexpensive for ease of development and deployment for a service available 24×7.

Credits

I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of Anthony at Pexels.