cloud run billing - execution time - google-cloud-platform

I have been using cloud run on GCP for several years. I recently moved a service over from AWS Lambda, which costs me like 10 dollars a month, but on cloud run it went to 50 dollars per day. The cloud run service is simply a background worker that should ideally run for 3 minutes max. It loads, schedules, and summarizes jobs. If there are 50 jobs, it should run 50 background workers so it can bursts, which cloud run complains that it cannot allocate quickly enough. Since I use a distributed lock, there should be only 50 workers running regardless.
I tried to figure out the costs breakdown and GCP in my experience does not provide any defaults. I click on the costs breakdown and it just shows me a graph of the monthly costs going from 50 dollars to 800 dollars per month. There is no costs breakdown. I'll try to implement labels, but in general, how do I determine the costs break down for cloud run. AWS lambda is simple because it essentially reduces to execution costs especially within the same VPC.
Besides labels, how do I determine the costs for cloud run? When I drill down further is this CPU allocation that is huge costs, both in tier 2 and standard tier?
Any suggestions or help would be great :)

Related

Suggested way to write a queryset to Parquet in GCP

I have a query that runs against a SQL Server instance that takes anywhere from 5 minutes to 75 minutes to complete. The response size is anywhere from a few rows to 1GB of data. I have a parquet writer that only has to wait until the query completes and results sent back and it will write the results to Google Cloud Storage.
What would be the best product to accomplish this, and is their one that would have roughly zero startup time? The two that came to mind for me were Cloud Functions and Cloud Run, but I've never used either.
Neither service meets your requirement of 75 minutes.
Cloud Functions times out at 540 seconds.
Cloud Functions Time Limits
Cloud Run times out at 60 minutes.
Cloud Run Request Timeout
For that sort of runtime, I would launch a container in Compute Engine Container-Optimized OS.
Container-Optimized OS
There is the possibility of configuring Cloud Run cpu-throttling so that you can run tasks in the background.
Run more workloads on Cloud Run with new CPU allocation controls
Note that you will be paying for the service on a constant basis as it is no longer running services (containers) on demand.

AWS EC2 On-Demand Pricing

I'm new to AWS EC2, and I wanted to deploy a web server in it. However I'm concerned about the price because the app will only be used for a few hours per day and I saw in the AWS Calculator that there's a Utilization per month as part of the billing computation https://calculator.aws/#/createCalculator/EC2.
What does the Utilization mean? Let's say I have a running EC2 instance. How do I reduce the charges?
Does it depend on the amount of times the server APIs are invoked in the app? So for the hours that the APIs are NOT being invoked, I won't get charged?
Or
Will it keep on charging me as long as the EC2 instance is running so I should shut it down during idle hours to save up on costs?
Amazon EC2 is charged at an hourly price. The price varies by the Instance Type and the Operating System. Basically, machines with more memory and more CPUs are more expensive, and Windows is more expensive than Linux. There is also a charge for Data Transfer, which is traffic that goes out to the Internet.
If you have a small application, an alternative would be to use Amazon Lightsail, which offers a simple monthly price for both the computer and the traffic.
I've added my response to each of your questions -
What does the Utilization mean? Let's say I have a running EC2 instance. How do I reduce the charges? - You will be charged for the time you let that EC2 instance running, start with a t2.micro under free tier account, you are allowed to run it for 750 hours a month!
Does it depend on the amount of times the server APIs are invoked in the app? So for the hours that the APIs are NOT being invoked, I won't get charged? - No, for EC2, it's the runtime and not the API queries.
Will it keep on charging me as long as the EC2 instance is running so I should shut it down during idle hours to save up on costs? - Shut it down, I would also to setup billing alarms to get an alert once my bill crosses a certain threshold
As long as the servers are up and running you will be charged for it. So yes, you should shut it down during idle hours if you want to save costs.
If you just want to try it out for a simple Rest API server, you can create a new account for a 12-month free tier that will basically entitle you to the smallest 24/7 running (750 hours/month) server.
I've used this server for one of my smaller projects, and it was enough to serve about 100 users in total, with about maximum 10 people coming in and out time to time per day. Had no problem with it.

How to minimize the GCP cloud SQL billing

I am using Google Cloud Platform (Free Tier) for testing my application. I am using Cloud SQL and my DB size is 1 GB (Images). I am just testing the app so the number of users is only 1. The max time I spent is less than 2 hours per day (120 minutes max). But when I observe the billing, it says that I spent around Rs. 4000 (Indian Rupees-4K) per month.
Details: DB standard Intel N1 1 VCPU running in Mumbai (with 30% promotional discount).
How can I reduce the billing amount?
The Cloud SQL instances basically charged on hourly basis. If you are using it for testing purpose alone, then it is better to stop the instance once you are done with the work and start it whenever you need. By doing this you can avoid getting charged for non-usage period and you pay only for the data storage alone.
Refer this pricing chart for Cloud SQL and refer this one for start-stop-restart instances.

AWS EC2 instance cost far above estimate, why?

I have a script that I run 24/7 that uses 90-100% CPU constantly. I am running this script in multiple virtual machines from Google Cloud Platform. I run one script per VM.
I am trying to reduce cost by using AWS EC2. I looked at the price per hour of t3-micro (2 vCPU) instances and it says the cost is around $0.01/h, which is cheaper than the GCP's equivalent instance with 2 vCPU.
Now, I tried to run the script in one t3-micro instance, just to have a real estimate of how much each t3-instance running my script will cost. I was expecting the monthly cost per instance to be ~$7.20 (720h/month * $0.01/h). The thing is that I have been running the script for 2-3 days, and the cost reports already show a cost of more than $4.
I am trying to understand why the cost is so far from my estimate (and from AWS monthly calculator's estimate). All these extra cost seem to be from "EC2 Other" and "CPU Credit", but I don't understand these costs.
I suspect these come from my 24-7 full CPU usage, but could someone explain what are these costs and if there is a way to reduce them?
The EC2 instance allows a certain baseline CPU usage: 10% for a t3.micro. When the instance is operating below that threshold it accumulates vCPU credits: which are applied to usage above the threshold. A t3.micro can accumulate up to 12 credits an hour (with one credit being equal to 100% CPU ulitilisation for 1 minute). If you are regularly using more CPU credits than the instance allows will be charged at a higher rate: which I understand to be 5c per vCPU hour.
It may be that t3.micro is not your best choice for that type of workload and you may need to select a different instance type or a bigger instance.
The purple in your chart is CPU credits, not instance usage.
Looks like you enabled “T2/T3 Unlimited” when launching your instance and your script is causing it to bursting beyond the provided capacity. When you burst beyond the baseline capacity, you’re charged for that usage at the prevailing rate. You can read more about T2/T3 Unlimited and burstable performance here.
To bring these costs down, disable T2/T3 unlimited by following instructions here.

Is Google Cloud Trial enough for academic project?

We are going to use Kubernetes Engine, Cloud SQL, Storage, and possibly Nosql and cache services for our academic project.
So far we'll have 5 accounts and the project has to be running for 3 months.
Will it be enough for us? Is it possible, for example, to stop project and billing every night or even stop and start at any time?
The Google Cloud Platform (GCP) Free Tier includes $300.00 USD in credits to get started with any GCP product. Since this is an academic project, I recommend using the Google Cloud Platform Pricing Calculator to learn how to price GCP products and services - link. Also review what is included in the "Always Free Products" - link. Then there are discounts for services that run for a majority of the month - "Sustained Usage Discounts" - link.
Google Kubernetes Engine:
Kubernetes Engine is free (the worker nodes are not free).
If you select n1-standard-1 (1 vCPU, 3.75 GB mem) the cost is $24.27 per month per node. Typically you will create a three node cluster: round up to $75.00 per month.
Google Cloud SQL:
Selecting a db-pg-f1-micro (PostgreSQL) with 32 GB of SSD storage: $24.27 per month
Will it be enough for us?
As you can see, you will quickly burn thru $300.00 in credit in only three months.
Take into consideration that Google's goal is not to give away services. The goal is to introduce you to Google Cloud and provide enough services at zero or low cost so that you can complete an evaluation of Google Cloud.
Is it possible, for example, to stop project and billing every night
or even stop and start at any time?
No, you cannot start and stop billing every night. In order to stop billing for a project you must delete the project and everything in it. Some services such as Google Compute Engine (GCE) can be stopped. This stops billing for the VM instance but billing for storage, snapshots, IP addresses, etc. continues unless you delete your instances every night and recreate them each morning.
Services such as Kubernetes or Google Cloud SQL cannot be completely shutdown. Technically you could by deleting everything but then recreating everything takes more time than the savings gained. Very good for practice however.
Google Cloud services would be a great option for your circumstances.
If its budgetary constraint you may want to look into using AWS, AWS will provde you with a years time for free which would be good for your horizontal scaling with k8s
Amazon and Kubernetes