Check the pricing for Google Cloud Run with the help of a calculator

The pricing for the standard tier is calculated based on the source geolocation of the traffic. It is charged for every GB that is delivered as egress. I went through both the overview and pricing pages on the Google Cloud website, and found out that the cost is determined by the price per GB of egress.

Question:

For some cron-like tasks that require my attention, I am contemplating utilizing
Google Cloud
. These tasks will be activated by an HTTP call, which will most likely return a 202 response, and then run in the background through a golang goroutine.

My worry lies in the fact that Google Cloud Run containers might be terminated while they are not actively processing HTTP requests, which could result in my process being interrupted unexpectedly.

Can I instruct GCR to maintain the container’s state until I am done?


Solution 1:

Cloud Run has the ability to scale down CPU usage to almost nothing when no requests are being handled, which means that payments are only made when requests are being processed. This information is documented here.

As a general rule, it’s not recommended to use applications that start goroutines in the background on Cloud Run. This can cause your goroutines to face a shortage of
CPU time
shares, resulting in your program behaving abnormally, as if it’s running on an extremely slow CPU or not running at all.

The negligible quantity of an idle Cloud Run app is likely only suitable for disposal, a task that will be performed by the Go runtime.

To ensure that your goroutine finishes within the context of the request, it is recommended to prevent the request from returning until the goroutine completes. This can be achieved by implementing a blocking-receive mechanism using either

chan

or

sync.WaitGroup#Done()

.


Solution 2:


Cloud Run’s recently introduced feature, Always On CPU, addresses this issue. For more information, please refer to: https://cloud.google.com/blog/products/serverless/cloud-run-gets-always-on-cpu-allocation.

Frequently Asked Questions

Posted in Uncategorized