How to estimate Google Cloud Run costs?

Viewed 2252

I have built my machine learning model and now as a next step I wish to make it publicly available. The plan is:

  • To build the UI by using Streamlit.
  • To package the application using Docker image.
  • To deploy the Docker image into the Google Cloud Run environment.
  • To start the Docker container in Google Cloud Run environment.

But the problem is that I cannot estimate what will be the costs when starting and running the container in Google Cloud Run (I'm still a beginner). How to estimate the worst-case scenario, i.e. what could be the maximum cost that it should generate? There are CPU, memory, requests and networking properties in the Google Cloud Run pricing table but:

  • How can I know exactly how much of these resources my application will take?
  • Could it happen that if the application is publicly available and the requests exceed the free limit quota, I could get an astronomical bill.
  • Can I set some limits over which my bill cannot exceed?
1 Answers

The billing is quite simple: you pay the CPU time and the memory time that you allocate (and a little bit the number of requests).

The current worst case is: (NbCpu per instance per seconde + Memory per instance per seondes) * 3600 * 24 * 30 * 1000.

  • 3600 is to transform second in hour
  • 24 to transform hour in day
  • 30 to transform day in month
  • 1000 the default max instances parameter

If you want to limit the cost, limit the max instance parameter. But you will also limit the scalability of the application. But that prevent you to have astronomical bill, it's a matter of tradeoffs.

About the billing, you can also set an alert in the budget of your project

Your last question about the quantity of resource used by the application. It's hard to say! However, you have to know your application. The metrics graph can help you to provide some inputs.

However, Cloud Run is able to process up to 80 concurrent requests. Thus your metric when your process only 1 request at a time can change dramatically with 80 request! Especially in memory consumption!

You can also play with this concurrency param to limit the size of one instance. But is you reduce it, don't set the max instance param too low, else some request won't be served.

Matter of tradeoffs

Related